Show boolean values as icons - jsf

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

Related

Set width for JSF column header in fixed-size table

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%; }

Represent a boolean value in Primefaces DataTable

So I am attempting to pass object values from a bean into a primefaces datatable (using primefaces 3.4 currently), howevever I'm facing two problems with this.
1. I cannot seem to find any way to display (or represent) a boolean value within a column in a datatable. Every time I attempt this, the table returns back totally empty (even though without the boolean column the other columns are populated with data from the bean).
2. The other bigger problem (more to do with java I think than primefaces) is that I have currently 26 different Objects I get from Siebels CRM ONDemand cloud solution, each containing their own datatypes and attribute values. I cannot for the life of me figure out how to, based on a drop down selection of a specific object display that objects fields dynamically within a primefaces datatable. So far I have just managed to display some of the fields for 1 of these objects as a sort of prototype but I am having the problem with the boolean value being display also its a nightmare.
Anybody have any sort of similar experiences ? or suggestions? I've been puzzled by this for over 2 weeks now and I am going absolutely crazy!
I can provide code examples or other details if needed :)
Thanks a lot I really appreciate any help !
Reggie
Html code:
<p:panel header ="Source Environment" style="margin-bottom:5px;">
<p:dataTable draggableColumns="true" id="tableFieldSet1" value="#{ODComBean.fields}" var="tableFieldSet1" rowKey="#{ODComBean.fields}" selectionMode ="multiple" style="font-family:sans-serif; width:max-content;">
<p:panel header="OD Object Selection" style="margin-bottom:5px;">
<h:panelGrid columns="2" cellpadding="5">
<p:selectOneMenu immediate ="true" id="pickList" value="#{ODComBean.fieldSetData}" effect="fade" style="font-size: 12px; font-family:sans-serif;" >
<f:selectItems value="#{ODComBean.fieldSet}" itemLabel="#{fieldSet.objectName}" var="fieldSet"/>
<p:ajax event="change" update="#form" />
</p:selectOneMenu>
</h:panelGrid>
</p:panel>
<p:panel header ="Source Environment" style="margin-bottom:5px;">
<p:dataTable draggableColumns="true" id="tableFieldSet1" value="#{ODComBean.fields}" var="tableFieldSet1" rowKey="#{ODComBean.fields}" selectionMode ="multiple" style="font-family:sans-serif; width:max-content;">
<p:column headerText="Type" styleClass="singleLine" style="height: 10px; font-size: 8pt;">
<h:outputText value="#{tableFieldSet1.fieldType}"/>
</p:column>
<p:column headerText="Required">
<p:graphicImage value="/resources/images/tick.png" rendered="#{tableFieldSet1.readOnly}"/>
<p:graphicImage value="/resources/images/red-cross.png" rendered="#{not tableFieldSet1.readOnly}"/>
</p:column>
<p:column headerText="Name" styleClass="singleLine" style="height: 10px; font-size: 8pt;">
<h:outputText value="#{tableFieldSet1.name}"/>
</p:column>
<p:column headerText ="Display Name" styleClass="singleLine" style="height: 10px; font-size: 8pt;">
<h:outputText value="#{tableFieldSet1.displayName}"/>
</p:column>
<p:column headerText="Default Value" styleClass="singleLine" style="height: 10px; font-size: 8pt;">
<h:outputText value="#{tableFieldSet1.defaultValue}"/>
</p:column>
<p:column headerText="Generic Integration Tag" styleClass="singleLine" style="height: 10px; font-size: 8pt;">
<h:outputText value="#{tableFieldSet1.genericIntegrationTag}"/>
</p:column>
<p:column headerText ="Integration Tag" styleClass="singleLine" style="height: 10px; font-size: 8pt;">
<h:outputText value="#{tableFieldSet1.integrationTag}"/>
</p:column>
<p:column headerText ="Translations" styleClass="singleLine" style="height: 10px; font-size: 8pt;">
<h:outputText value="#{tableFieldSet1.listOfFieldTranslations}"/>
</p:column>
<p:column headerText ="Validation Error" styleClass="singleLine" style="height: 10px; font-size: 8pt;">
<h:outputText value="#{tableFieldSet1.validationErrorMsg}"/>
</p:column>
<!-- When I add the next Column it will only show data for the first line, and display a <div half tag in the last column... strange... !-->
</p:dataTable>
</p:panel>
if you want to use a h:outputText, you can set its converter to something that you implemented and inside that converter, decide about the display value.
Otherwise, if you like to view an icon according to the value,
you can do like this :
<p:column headerText="My Boolean Value">
<p:graphicImage value="/resources/images/tick.png" rendered="#{MODEL.boolean}"/>
<p:graphicImage value="/resources/images/red-cross.png" rendered="#{not MODEL.boolean}"/>
</p:column>
I hope this is helpful :)
Output panel with layout set to inline produce a <span> tag with the style class you provide.
You can for example use the jquery-ui icons provided by the framework. Like this:
<p:outputPanel layout="inline" styleClass="ui-icon ui-icon-circle-check" rendered="#{project.inBudget}" />
<p:outputPanel layout="inline" styleClass="ui-icon ui-icon-circle-close" rendered="#{!project.inBudget}" />
You could simply use a check mark symbol for true and empty String, or x symbol for false.
<p:column headerText="Required" style="text-align: center">
<h:outputText value="#{tableFieldSet1.readOnly ? '✓' : ''}"/>
</p:column>

JSF snippet to center an image in a data table Primefaces

How can I align a graphicImage which will come as an element as a column in the middle .Now It is left aligned. I tried a lot but it will not work.
<p:column>
<f:facet name="header">
<h:outputText value="Status" />
</f:facet>
<h:graphicImage value="../resources/images/Yellow_button.png"
style="float:center;height: 18px; width: 20px"
rendered="#{categorey.status == 1}" title="READY TO ZIP"/>
<p:column>
You can align the table cell content for the whole column:
<p:column style="text-align: center">
<f:facet name="header">
<h:outputText value="Status" />
</f:facet>
<h:graphicImage value="../resources/images/Yellow_button.png" />
</p:column>
In order to separate the layout you can use the styleClass attribute referencing a class from a css resource as well.

JSF - Scrollable DataTable

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 :)

JSF: make f:facet header as commandLink

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>

Resources