JSF Datatables : How to handle columns with subtype specific content [duplicate] - jsf

This question already has answers here:
Conditionally displaying JSF components
(3 answers)
JSTL c:if doesn't work inside a JSF h:dataTable
(1 answer)
Closed 5 years ago.
I have a scenario where I have a list of objects that extend a common supertype.
This list of objects is supplied to the h:datatable as it's value.
The last column in the table has inputs that are subtype-specific whereas all the other columns apply to fields found in the common superclass.
What is the most elegant way of rendering the subtype-specific fields ?
At the moment I am doing this:
<h:column>
<c:if test="#{cover.cd eq 2}">
//Markup specific to this subtype
</c:if>
<c:if test="#{cover.cd eq 3}">
//Markup specific to this subtype
</c:if>
</h:column>

Related

JSF not null condition [duplicate]

This question already has answers here:
Specify conditional rendering of element inside <ui:repeat>? The <c:if> does not seem to work
(1 answer)
JSTL c:if doesn't work inside a JSF h:dataTable
(1 answer)
JSTL in JSF2 Facelets... makes sense?
(3 answers)
Closed 5 years ago.
Using JSF & EL, I'm basically trying to check if a variable is null (or not).
Here is a code snippet:
<p:dataGrid value="#{bean.graphiques}"
var="graphique"
rows="1" columns="3">
<c:if test="#{not empty graphique}">
<p:chart type="line" model="#{graphique}"/>
</c:if>
<c:if test="#{empty graphique}">
<p:outputLabel>
Add a new chart.
</p:outputLabel>
</c:if>
</p:dataGrid>
First check, #{not empty graphique} is always false, even if graphique is not null. I tried with #{graphique ne null} and #{graphique != null}, but it's false, too.
When I remove the c:if statement, the chart is displayed. Thus, graphique is not null.
I looked for a solution on a lot of websites - including SO - but didn't manage to find a solution.
Do you know what's going on and how to solve my problem?
Thanks!
Did you try...
<p:chart type="line" model="#{graphique}" rendered="#{graphique != null}"/>
Sometimes I had issues with primefaces tags in <c:if>

PrimeFaces dataTable method called many times [duplicate]

This question already has answers here:
Defining and reusing an EL variable in JSF page
(2 answers)
Closed 6 years ago.
I have a datatable with a column:
<p:dataTable value="#{cc.attrs.bean.model}"
...
<p:column style="width:#{bean.getWidth('colDate', 55)}px;"
It seems that the bean.getWidth method is called for every row in the table. Thus, when having 100 rows, the method is called a hundred times. I expected the method to be called only once.
Am I wrong?
No, it's right.
You can cache the value into your bean or use JSTL
<c:set var="width" value="#{bean.getWidth('colDate', 55)}" />
<p:dataTable value="#{cc.attrs.bean.model}"
...
<p:column style="width:#{width}px;"
You can find more infos here https://stackoverflow.com/tags/jstl/info.
Don't forget the namespace .
you can save result of getWidth in managed bean attribute then use this in column style

How can I add JSF code to xhtml in the attribute id? [duplicate]

This question already has answers here:
How to dynamically generate id in dataTable using ui:repeat tag
(4 answers)
How to use EL with <ui:repeat var> in id attribute of a JSF component
(1 answer)
Closed 6 years ago.
I am working with JSF 2.2 and I would like use JSF variables in the id attribute for to send individuals petitions for each list's element.
For example:
<ui:repeat value="#{bean.numbers}" var="number">
<h:inputText id="text#{number}"/>
</ui:repeat>
Thank you

How to pre-select data in h:selectManyListbox [duplicate]

This question already has an answer here:
How do UISelectOne and UISelectMany components preselect defaults in f:selectItems
(1 answer)
Closed 7 years ago.
This is a common problem and I already saw the basic solution (populate the selectManyListBox). Here is the code of my JSF 1.2 page:
<h:selectManyListbox id="statusMenu" converter="statusConverter" value="#{aprvAction.ap.statuses}" >
<f:selectItems id="statusItem" value="#{action.ap.statusItens}"/>
<a:support event="onclick" ajaxSingle="true" immediate="true" eventsQueue="queueGeral" />
<a:support event="onchange" ajaxSingle="true" eventsQueue="queueGeral" process="statusMenu"/>
</h:selectManyListbox>
The thing is that #{aprvAction.ap.statuses} is an instance of List<Status> class. However, in tag <f:selectItems> the value: #{action.ap.statusItens} is an Instance of List<SelectItem>.
I populate the the #{aprvAction.ap.statuses} with the values that I want to pre-select the ListBox, but did not work. I think it's because they are different objects in <selectManyListBox> and <selectItems>.
How can I solve this, and show the pre-selected values in <selectManyListBox>?
JSF will use equals() method to compare available items with (pre)selected items.
In case of standard objects, such as String, this is already implemented.
In case of custom objects, such as your Status entity, it's your responsibility to make sure that you've properly implemented the equals() (and hashCode()) method in the class.
See also:
How to populate options of h:selectOneMenu from database?
Right way to implement equals contract
value in h:selectManyListbox should be subset of itemValue's in f:selectItems.
Create a method which return the List or Array of selected statuses. Use this method in value attribute of h:selectManyListbox. Any value from list/array returned in this method should match itemValue in set of {itemValue, itemLabel} pairs used in f:selectItems.

How to pass parameters panelgroup - binding, JSF [duplicate]

This question already has answers here:
How does the 'binding' attribute work in JSF? When and how should it be used?
(2 answers)
Closed 8 years ago.
I have a datatable that reads registers from a database.
In the datatable I have a panelgroup that is populated by binding
My problem is that I can not pass a parameter. I want to pass a value from the datatable variable, in that case preg, on each row I want to know the value of the register read to populate the panelgroup.
If I display the value it works fine for each row: #{preg.idpreg}
<h:dataTable var="preg" value="#{Pregbacking.list(Pregbacking.idenq)}">
<h:column>
#{preg.idpreg}
<h:panelGroup binding="#{Pregbacking.dynamicDataTableGroup(preg.idpreg)}"/>
</h:column>
</h:dataTable>
Does anybody know how can I solve this?
That should work just find but I believe that you need to make sure you are using a modern servlet spec (v3 I think). Use the latest Glassfish or Tomcat app server.

Resources