3 Replies Latest reply on Aug 26, 2010 9:38 PM by cmathrusse

    Complex object and dynamic rendering from Java

    cmathrusse

      I have a top level complex object that has a collection of Child objects, which each can have a List of Child objects as well. I'm attempting to dynamically build the UIComponents from within Java as the object structure is unpredictable, based upon data residing within the database. Normally I would retrieve a List from the database and render it within a data table, but because each object within the first list can be represented in a different fashion (textInput, Radio buttons, DropDown list, multi-select checkboxes, etc) I can't use a table to represent the data.

       

      Because the first child list can have any number of objects within it, I wondering what is the best way to represent this in the backing bean. I can't use a UIData object to acquire the currently selected row as I would do if I were to use a data table. I don't think it would be very flexible either if I were to try to access the list based upon an index. So the only solution that I was able to think of was to dynamically register a new managed bean that would contain a reference to one object from the list and binding that managed bean to the UIComponent.

       

      Does this sound reasonable or is there an easier way to accomplish this task?

       

      Thanks for the help...

        • 1. Re: Complex object and dynamic rendering from Java
          ilya_shaikovsky

          I believe that you still should be able to use just table and not use bindings for that case. In similar case - I created set of facelts with different inputs which could be used and added them to columns using ui:include. The facelet to include was returned from backend according to type of the control required. And passing value binding and other parameters to facelet was done through ui:param.

          • 2. Re: Complex object and dynamic rendering from Java
            cmathrusse

            Thanks so much for the response. I seem to be asking for a lot of help these days.

            So the backing bean contained a UData object that represented the table. When rendering the table and iterating over the list of objects, you would perform a ui:include using a value that was contained in the current object? And the current object was passed to the included page via a UI:param?

             

            I think I'm following the idea. When the page was submitted did the values get updated or did you update the values with ajax calls?

             

            Is there any chance that you could provide a sample?

             

            Thanks again for all the help. It's really great of you to give me all this assistance.

            • 3. Re: Complex object and dynamic rendering from Java
              cmathrusse

              Hi Ilya,

               

              I started thinking about what you had suggested, using different pages to include based upon the data and I began implementing this solution. Everything seemed to work well until I tried to dynamically include the pages. It seems that the <ui:include> tag does not behave as I expected when including the pages dynamically in a loop. I played around with it a bit and it seems that the <ui:include> is processed prior to looping through my records. I don't know if this is the case but is there a solution that will accomplish what I am attempting? Or am I simply doing it incorrectly?

               

              Thanks again for the help..

               

              Screen shot 2010-08-26 at 6.37.19 PM.PNG