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
Related
This question already has answers here:
How to use <h:selectBooleanCheckbox> in <h:dataTable> or <ui:repeat> to select multiple items?
(3 answers)
Closed 5 years ago.
I have an <ui:repeat> in which I has a list of object , next to each of those object I need to have a checkbox ( to check this element).
I want to know how could I integrate those checkboxes inside the <ui:repeat> in order to have many rows and each rows needs to has the object.getName() and next to it I need to have the checkbox ?
If this is feasible, Please how could I obtain those checked objects in the backing bean ?
<ui:repeat var="myObject" varStatus="status"
value="#{Bean.getListObjects}">
<b>#{status.index+1} .</b>
<h:outputLabel value="#{myObject.name}" />
//need the checkbox here for example
</ui:repeat>
Just create a map with the object UID as the key and a boolean as the value. Then value-bind each checkbox to a map entry.
Assuming your names are unique, you could use them. So, in you bean create a Map<String,Boolean>, and initialize the map with each object.
You can use the map to in the checkbox value like value="#{bean.map[object.name]}".
See also:
Dynamic value binding of JSF component
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>
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.
This question already has answers here:
Differences between action and actionListener
(4 answers)
Closed 3 years ago.
what is the difference between
<h:commandLink actionListener="#{serviceProviderBean.method}" value="Save" />
and
<h:commandLink actionListener="#{serviceProviderBean.method()}" value="Save" />
is both invoke same method or any error in above code
Second will not work under tomcat6, it will work with tomcat7/jSF2
Both are fine. The second one is being used for passing params like
<h:commandLink actionListener="#{serviceProviderBean.save(someBean.someOption)}"
value="Save" />
I think you also have to use the method with braces, when you want to use a method returning a boolean value, but don't have a matching property defined in the bean.
I had that situation today.
My xhtml page has a <h:panelGroup ...> with the rendered="#{bean.isLoggedIn}" attribute. The isLoggedIn method, calls the method of the boundary, so the bean does not have the matching property private boolean isLoggedIn.
I got a exception because of the missing property.
After adding the braces to the rendered attribute making it to rendered="#{bean.isLoggedIn()}" it's working correctly.
Anyway. The method got removed by now, because my bean should not do business logic stuff :D
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.