Complex Bean -tree Processing 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 {
    ....
}

      

Thus, it basically Abean

contains everything. Now I want to make a JSP for all these beans, where for example the user can specify how much Cbean

he wants in Bbean

. So my problem is that I want to show the form for all "child" instances automatically, eg: on d.jsp. I want to show a shape for everyone Dbean

inside Cbeans

.

I have tried inserting <h:dataTable>

-s without any success. Any help or thought would be appreciated. I hope my explanation was clear.

Thanks in advance Daniel

0


a source to share


3 answers


I am assuming that since you are using JSP you are not using Facelets?

If you were, you could use and manually create 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>

      

Alternatively, Richfaces has a4j : repeat that does the same thing and can certainly be used with JSPs. In addition, Richfaces has a rich: subTable that can be used to split tables.

+1


a source


Nested data Tables are usually not a good idea. With data structures like this, you might end up iterating over O (n ^ 4) child controls, which can have performance implications. The standard dataTable control is pretty primitive. Better approach would be to use some master / detail form or write your own tree control. Since writing a custom control requires a detailed understanding of the JSF architecture, you might want to look at third party JSF libraries first to see if you can find one that works for you.



+1


a source


I'm not sure if this answers your problem, but for example, in your CBean, if you have a getter for a 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>

      

0


a source







All Articles