4 Replies Latest reply on Oct 12, 2009 12:03 PM by phantasmo

    DataModel vs a regular list in rich:dataTable

    phantasmo

      Both @DataModel and a regular list can be used as a value for a rich:dataTable, but if a regular list is used, the iterating variable can not be used as a parameter in a method binding expression. On the other hand, using @DataModel allows this, but appends parameters to output links that I would rather avoid.


      To clarify:


      <rich:dataTable id="items" var="item" value="#{items}">
      ...
      <s:link id="selectItem" value="Select" action="#{itemList.select(item)}" />
      



      will fail if items is declared like this


      @Out private List<Item> items;



      but will work as expected if items is declared like this


      @DataModel private List<Item> items;


      but this will also append dataModel and some other parameters to the s:link, even if it's used without an action (meaning it doesn't really need data model selection), like this:


      <s:link id="selectItem" value="Select Item" view="/item.xhtml" propagation="none">
              <f:param name="itemId" value="#{item.id}"/>
      </s:link>



      Am I right when I say this? If I am, is there a way to maintain clean URLs like appname.com/item/itemId without sacrificing the ability to use the iterating variable (item) in a parametrized method binding expression?


      Hopefully this makes sense... Anyway, thanks for any advice you decide to share.

        • 1. Re: DataModel vs a regular list in rich:dataTable
          swd847

          You can still use the parameter if you submit the form (i.e. h:commandLink instead of s:link).


          • 2. Re: DataModel vs a regular list in rich:dataTable
            asookazian

            The main purpose of the ListDataModel outjection/injection pattern implemented via @DataModel, @DataModelSelection, and @DataModelSelectionIndex is to allow you to have access to the rowId or entity selected when the user submits a form via a button/link in the dataTable (typically there are multiple links/buttons in the table in one column, one per row).


            I've never had any problems with it other than when the user sorts a dataTable by clicking a column header (Richfaces), then the row/entity gets screwed up in the backing bean.


            IIRC, s:link is for GET requests and h:commandLink is for POST requests.  You typically don't use s:link with dataTable form submissions...


            • 3. Re: DataModel vs a regular list in rich:dataTable
              clerum

              You can also wrap the List right on the page.


              value="#{dataModels.getDataModel(summaryBillingAccountNumber.invoices)}" or in your case value="#{dataModels.getDataModel(items)}"


              This does break JBoss Tooling suggestions. I opened a JIRA on it JBIDE-4870 but no clue if it's even possible for them to make it work.


              I've found this really useful in areas where I'm trying to expose a clickable list on a association deep in my model and not wanting to @DataModel it.


              • 4. Re: DataModel vs a regular list in rich:dataTable
                phantasmo

                I understand now.
                Thank you guys for such detailed answers! You were very helpful!



                #{dataModels.getDataModel(items)}

                Nice trick! I agree that this approach can be very useful in certain cases. Thanks!