JSF ui:repeat in ui:repeat with dynamically assigned var-value

限于喜欢 提交于 2020-01-06 01:33:08

问题


We created a JSF table component for our projects which uses <ui:repeat> to create the table. A new requirement to add a table inside a table (the second table resides in a row and is collapsable) has gotten us into trouble as the <ui:repeat var="row" ...> is set statically inside the table componenten and the inner table uses the row variable of the outer table when iterating through the list. Now what i want to create is something like this:

<div>
   <myfw:mytable dataModel="#{bean.user}" varName="user" ...>
      <myfw:mycolumn value="#{user.name}"/>
      <myfw:myexpendablecolumn>
         <myfw:mytable dataModel="#{bean.acl}" varName="acl" ...>
            <myfw:mycolumn value="#{acl.name}"/>    
         </myfw:mytable>
      </myfw:myexpendablecolumn>
   </myfw:mytable>
</div>

In the table component the var attribute should be set ...

<composite:interface>
...
    <composite:attribute name="varName" required="false"
        type="java.lang.String" default="row" />
</composite:interface>

<composite:implementation>
...

        <ui:repeat var="#{varName}" value="#{cc.attrs.dataModel.wrappedData}"
            varStatus="loop">
            <div class="floating_table_row">
                              <composite:insertChildren />  
            </div>
        </ui:repeat>
</composite:implementation>

... but sadly, this does not work. I've tried it with <c:forEach> but the result is the same, the values of the columns are empty and no data is shown. Is there a way to dynamically set the var attribut of the <ui:repeat>?


回答1:


After further research I stumbled over this page https://java.net/jira/browse/FACELETS-372 where the UIRepeat class, specifically the getVar method is modified to access the ValueExpression so instead of

public String getVar() {
    return this.var;
}

... the method looks like this:

public String getVar() {
    if (this.var != null) {
        return this.var;
    }
    ValueExpression ve = this.getValueExpression("var");
    if (ve != null) {
        return (String) ve.getValue(getFacesContext().getELContext());
    }
    return null;
}

There are further modifications in the attached file from https://java.net/jira/browse/FACELETS-372. Sadly, the UIRepeatclass cannot be simply extended because of the usage of the var attribute in private methods so I now have a <myfw:repeat> which utilises the patched UIRepeat class from the page.



来源:https://stackoverflow.com/questions/26337016/jsf-uirepeat-in-uirepeat-with-dynamically-assigned-var-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!