JSF2.0: variable list of custom component
        Posted  
        
            by rattaman
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by rattaman
        
        
        
        Published on 2010-06-03T17:22:54Z
        Indexed on 
            2010/06/03
            17:24 UTC
        
        
        Read the original article
        Hit count: 300
        
customcomponents
|jsf2
Hello
Is there any way of using JSF2.0 in connection with variable lists of components? For example, lets say I have list o people that I would like to edit. They are presented on the page as list of components PersonEditor, which allow changing person data. Each editor is associated with single Person element. In order for this to work I need to perform following steps:
On initial request:
- Get list of people
 - For each person create PersonEditor and associate it with Person object.
 - Fill editor's data.
 
On user action:
- When user changes values and presses Save, data is processed by backing bean.
 
I can either fill editor with data from list of people or bind it to the backing bean, but not at the same time, so I am stuck.
I tried
people.xhtml
<ui:render value="#{bean.people}" var="person">
  <example:personEditor person="#{person}"/>
</ui:render>
where personEditor.xhtml:
a) proper association with person object, but no connection to backing bean
<h:form>
  <h:outputText value="#{cc.attr.person.name}"/>
  <h:commandButton name="Save" actionListener="editorBean.save">
    <f:ajax execute="@form" render="@form"/>
  </h:commandButton>
</h:form>
b) no association with person object, but there is connection to backing bean - there is no way to pass that person to the backing bean
<h:form>
  <h:outputText value="#{editorBean.name}"/>
  <h:commandButton name="Save" actionListener="editorBean.save">
    <f:ajax execute="@form" render="@form"/>
  </h:commandButton>
</h:form>
If I had each editor on separate page, I could pass the person id as url parameter (either using f:param or f:attribute) and initialize it accordingly. Is there any solution to this problem?
© Stack Overflow or respective owner