Daniel Szalay
Daniel Szalay

Reputation: 4101

Handling a complex Bean-tree in JSF

Let's take a look at this bean structure for example:

public class Abean {
   private Bbean b;
}

public class Bbean {
   private ArrayList<Cbean> c;
}

public class Cbean {
   private ArrayList<Dbean> d;
}

public class Dbean {
    ....
}

So basically Abean containts everything. Now I want to make JSPs for all of these beans, where for example, the user can tell how many Cbean he/she wants in Bbean. So my problem is that I want to show a form for all the "child" instances automatically, for example: on d.jsp I want to show a form for every Dbean inside the Cbeans.

I've tried to embed <h:dataTable>-s, without any success. Any help or thought will be appreciated. I hope my explanation was clear.

Thanks in advance, Daniel

Upvotes: 0

Views: 756

Answers (3)

McDowell
McDowell

Reputation: 108859

Nesting dataTables is generally not a good idea. With data structures this deep you may end up with an O(n^4) iteration over the child controls, which may have consequences for performance. The standard dataTable control is quite primitive. A better approach would be to use some form of master/detail design or write a custom tree control. Since writing a custom control requires a detailed understanding of the JSF architecture, you might first want to look at 3rd party JSF libraries to see if you can find one that suits your needs.

Upvotes: 1

Damo
Damo

Reputation: 11540

I assume that since you're using JSP that you're not using Facelets?

If you were, then you could take advantage of the and manually build up a table with nested tables.

eg.

<table> 
<ui:repeat value="#{myCBEan.d}" var="myDBean">
   <tr>
      <td><h:outputText value="#{myDBean.someText}"/></td>
   </tr>
</ui:repeat>
</table>

Alternately, Richfaces has a a4j:repeat that does the same thing and can undoubtedly be used with JSPs. Also Richfaces has a rich:subTable that can be used to nest tables.

Upvotes: 1

Cyrille Ka
Cyrille Ka

Reputation: 15538

I'm not sure this answers your problem, but for example in your CBean, if you have the getter for the list "d", you can use JSTL to iterate through the DBean in your CBean.

<c:forEach items="#{myCBean.d}" var="myDBean">
    <h:form>
        <!-- example form content -->
        <h:outputText value="#{myDBean.someText}"/>
        <h:inputText value="#{myDBean.exampleInput}"/>
        <h:commandButton value="#{myDBean.anAction}"/>
    </h:form>
</c:forEach>

Upvotes: 0

Related Questions