jsf:
<rich:dataTable>
...
<h:column>
<f:facet name="header">
<h:commandLink action="fileSearchSort" styleClass="theader">
Name
</h:commandLink>
</f:facet>
#{f.name}
</h:column>
...
</rich:dataTable>
if do this:
...
<h:column>
<h:commandLink action="fileSearchSort" styleClass="theader">
<f:facet name="header">
Name
</f:facet>
</h:commandLink>
#{f.name}
</h:column>
...
that label "Name" in header is dissappeared.
Is it possible to do whole f:facet header as commandLink?
thanks.
As to the behaviour you're seeing, the <f:facet> is to be nested as direct child of the JSF component which is supposed to own the facet, which is in this case thus the <h:column>. Placing it inside a <h:commandLink> instead will make it to be the facet of the <h:commandLink>, but that component doesn't support a facet with name header, so you'll see nothing.
As to the concrete functional requirement, the JSF <h:commandLink> component renders a HTML <a> element which is by default an inline element. If you want to let it occupy the entire space of the parent HTML <th> element, then you need to make the <a> a block element instead. Just adding display: block to its style class should do.
.theader {
display: block;
...
}
The elements of the facet will be rendered into some kind of container, so if you place within the <h:commandLink> a <span> or <div> tag that consumes the entire area then your commandLink should work.
<h:column>
<f:facet name="header">
<h:commandLink action="fileSearchSort" styleClass="theader">
<span style="width: 100%; height: 100%;">
Name
</h:commandLink>
</f:facet>
#{f.name}
</h:column>
Related
I've added OmniFaces to my Primefaces application primarily for being able to update a single row of a dataTable. I'm calling Ajax.updateColumn(dataTable, 1) on push event, but nothing gets updated. Eg. one of my cells is like this
<p:column style="width:40px;text-align: center;"
toggleable="false" styleClass="smallPadding unmarkable">
<f:facet name="header">
<p:commandLink styleClass="ui-icon ui-icon-car"
style="display: inline-flex;" id="carIcon" />
</f:facet>
<p:tooltip for="carIcon" value="Anzahl freie Fahrzeuge" />
<h:outputText
value="#{editLoad.getAmountOfUnusedOrderPositions(order)}" />
<h:outputText value="/#{order.orderPositions.size()}" />
</p:column>
I've debugged and #{editLoad.getAmountOfUnusedOrderPositions(order))} returns 0, but the wrong value (8) is displayed after the update.
From the Ajax#updateColumn() javadoc:
public static void updateColumn(UIData table, int index)
...
Note that the to-be-updated direct child of UIColumn must be a fullworthy JSF UI component which renders a concrete HTML element to the output, so that JS/ajax can update it. So if you have due to design restrictions for example a <h:panelGroup rendered="..."> without an ID, then you should give it an ID. This way it will render a <span id="..."> which is updateable by JS/ajax.
Your <h:outputText> of interest doesn't have a id. Give it one.
<h:outputText id="amountOfUnusedOrderPositions"
value="#{editLoad.getAmountOfUnusedOrderPositions(order)}" />
I have DataTable with 5 columns. In one column are boolean values – true or false. I would like to show icons instead “true” or “false” literals. How can I show Boolean values as icons?
this is quiet simple.You just use the rendered attribute. Try this code:
<h:column>
<f:facet name="header">Col Name</f:facet>
<h:graphicImage value="../image1.jpg" rendered="#{yourBoolean}" />
<h:graphicImage value="../image2.jpg" rendered="#{!yourBoolean}" />
</h:column>
This can be achieved by using rendered's attribute of the graphic image's tag :
<h:dataTable value="#{managedBean.yourList}" var="list" rules="all" >
<h:column>
...
</h:column>
<h:column>
<f:facet name="header">Your column name</f:facet>
<h:graphicImage rendered="#{list.yourBoolean eq true}" library="images/SomeFolder" name="someTrueImage.png" />
<h:graphicImage rendered="#{list.yourBoolean eq false}" library="images/SomeFolder" name="someFalseImage.png" />
</h:column>
<h:column>
...
</h:column>
</h:dataTable>
You can use rendered attribute (as you can see in other answers), or incorporate condition inside value tag using ternary operator:
<h:graphicImage value="#{yourBoolean ? image1.png : image2.png}" />
The best (IMO) would be :
<h:dataTable value="#{myBean.myList}" var="myVarName">
.
..
...
<h:panelGroup styleClass="#{myVarName.myBoolean?'myTrueClass':'myFalseClass'}"/>
where in css
.myTrueClass {
width: 16px;
height: 16px;
background-image:url('../resources/images/myTrue.png');
}
.myFalseClass {
width: 16px;
height: 16px;
background-image:url('../resources/images/myFalse.png');
}
By using the css you will make you life much easier... easier to maintain
I have a JSF datatable with table-layout:fixed, where I'm trying to set percentage based width for each column. I figured that if i add a width attribute to the header in IE, then it works as expected. However, I cant figure out how to add this width attribute in the code.
I have added an attribute inside the facet header, but that didnt work. It didnt work setting it inside the column tag either.
If anyone could help me out it would be appreciated.
<h:column>
<f:facet name="header">
<h:outputText
value="#{messageSource['tasks.headline.task']}" />
<f:attribute name="width" value="20%"/>
</f:facet>
<t:commandLink id="lookAtTask" action="lookAtTask">
<t:updateActionListener property="#{flowScope.localTask}"
value="#{data.task}" />
<h:graphicImage url="/images/icon_properties_16x16.gif"
alt="#{messageSource['tasks.headline.task']}" />
</t:commandLink>
</h:column>
You can use the headerClass attribute of the <h:column> to specify a style class of the header.
<h:dataTable ...>
<h:column headerClass="col1">
<f:facet name="header">...</f:facet>
...
</h:column>
<h:column headerClass="col2">
<f:facet name="header">...</f:facet>
...
</h:column>
<h:column headerClass="col3">
<f:facet name="header">...</f:facet>
...
</h:column>
</h:dataTable>
with e.g. this CSS
.col1 { width: 20%; }
.col2 { width: 30%; }
.col3 { width: 50%; }
I want to submit a data table on a button click, but that action is not called on the first click. Here is my code:
<h:panelGrid id="addToThisDepartmentPanel">
<h:outputText value="#{messageDataBean.message}" rendered="#{messageDataBean.isSuccess eq false}" style="color:red" id="addToThisDepartmentMessage"/>
<h:form>
<h:dataTable value="#{systemResultViewUtil.systemUserDetailDataBeansList}" var="departmentdetail" id="addToThisDepartmentDataTable" rendered="#{systemResultViewUtil.systemUserDetailDataBeansList.size() gt 0}">
<h:column>
<f:facet name="header">
Name
</f:facet>
<h:outputText value="#{departmentdetail.name}" style="text-align: left;padding-right: 120px" />
</h:column>
<h:column>
<f:facet name="header">
Current Department
</f:facet>
<h:outputText value="#{departmentdetail.depName}" style="text-align: left;padding-right: 120px" />
</h:column>
<h:column>
<f:facet name="header">
Add To This
</f:facet>
<h:selectBooleanCheckbox value="#{departmentdetail.cheked}" style="text-align: left;padding-right: 120px"/>
</h:column>
</h:dataTable>
<a4j:commandButton oncomplete="if(#{messageDataBean.isSuccess eq true}){ closeAddToThisDepartmentDialog()}" value="Add TO This Department" action="#{departmentServiceBean.addEmployeeToThisDepartment}" id="addToThisDepartmentButton"
render=":addToThisDepartmentMessage :message" execute=":addToThisDepartmentDataTable" />
</h:form>
</h:panelGrid>
The problem is that on the second click my <a4j:commandButton> action is called. But it is not called on the first click.
Any ideas?
This problem is known as JSF spec issue 790. If you ajax-render some content which in turn contains a <h:form>, then its view state will get lost, which causes that the 1st action inside that form won't invoke anything. On the ajax response of the first action, the form will get new view state and thus any subsequent actions will succeed.
This is scheduled to be fixed for the upcoming JSF 2.2. But right now with JSF 2.0/2.1 you have to introduce a workaround. You first need to give the <h:form> a fixed ID which is yourFormId in the below example:
<h:panelGrid id="addToThisDepartmentPanel">
...
<h:form id="yourFormId">
...
Then you need to reference it in the render attribute as well:
<f:ajax ... render=":addToThisDepartmentPanel :yourFormId" />
The same story applies to <a4j:xxx> components.
<a4j:commandButton ... render=":addToThisDepartmentPanel :yourFormId" />
See also:
h:commandButton/h:commandLink does not work on first click, works only on second click
Communication in JSF 2.0 - Ajax rendering of content which contains another form
Is there any way to implement a scrollable datatable without using Rich Faces ? If there is can anyone point me to some code samples or example pages ? Thanks.
Use div component for scrollable datatable in jsf and mention
properties height: 200px; overflow: auto; in style attribute.
<div style="height: 200px; overflow: auto;">
<h:dataTable value="#{facesBean.files}" var="file">
<h:column>
<f:facet name="header">
<h:outputText value="Image"></h:outputText>
</f:facet>
<h:graphicImage value="#{files.image}" style="width:100px; height:100px;"></h:graphicImage>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Description"></h:outputText>
</f:facet>
<h:outputText style="font-weight:bold;" value="File Name:"></h:outputText>
<h:outputText value="#{file.alt}"></h:outputText>
</h:column>
</h:dataTable>
</div>
This can be achieved via CSS. You must use the css property overflow:scroll or overflow-x and overflow-y. But take note that different browsers treat this property differently so you it may result to different behavior.
You make a h:dataTable wrap inside a div.
Change the property of the div using css and add overflow property to scroll.
Make sure that your table has a fixed sized.
You may want to look at this
http://anaturb.net/csstips/sheader.htm
-cheers :)