3

Is that possible to define dynamic value of tag "var" in richfaces datatable?

I have a component that contains rich datatable inside and I want to use custom "var" name.

I do so

Component:

<rich:extendedDataTable id="#{id}_list" cellspacing="0" rows="#{rows}" var="#{itemName}"
                            value="#{data}">

Page:

<wh:list id="f" data="#{deviceListBean.data}" rows="20" itemName="item">

But I get such exception:

javax.servlet.ServletException: var cannot be EL-expression
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)

I want to be able use custom "var" name. May be there is some another way to do that?

2 Answers 2

2

Here is a trick (name attribute of ui:param can be EL-expression):

<ui:param name="#{itemName}" value="#{item}"/>
<rich:extendedDataTable var="item" value="#{data}">
2
  • Nice one. Noted should be that this trick works in Mojarra only.
    – BalusC
    Nov 8, 2012 at 23:18
  • Could you please post an example for that?
    – Diego D
    Dec 4, 2012 at 16:58
0

var is the name that you use to reference each item that is being looped in the datatable.

You would do something like

<rich:extendedDataTable id="#{id}_list" cellspacing="0" rows="#{rows}" var="_dataItem"
                        value="#{data}">

And inside the data table, you can use _dataItem to referent the current value

<rich:column>
  <h:outputLabel value="#{_itemData.myValue}"/>
</rich:column>

Think of it as if defining the following for

for(Item _dataItem : data) {
   System.out.println(_dataItem.myValue);
}
6
  • Yes, I know that. The problem is that I do not want to use the same name (_itemData) for current value in all tables. I want to user different names. F.e. _deviceItem for device list and _userItem for user list.
    – Ananda
    Nov 5, 2012 at 8:45
  • If you have different datatables you can use a different name for each one. If you are somewhat reusing one (I do not advice it) you cannot.
    – SJuan76
    Nov 5, 2012 at 8:47
  • How to define different names if I cannot use EL-expression and the table is "hidden" within a component? How to pass that name to the datatable?
    – Ananda
    Nov 5, 2012 at 8:52
  • Ok, missed the component part. But why do you wnat that? Are you using that name outside of the component?
    – SJuan76
    Nov 5, 2012 at 9:04
  • I have a list component with different additional functionality and want to use it on many of my pages. But I dont like to use same var name on all pages. Especially taking to account that I may have nested lists.
    – Ananda
    Nov 5, 2012 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.