0 Replies Latest reply on Mar 2, 2011 12:48 AM by sizafuvubo mulatesefu

    Problem with setting a DataModelSelection context variable manually

    sizafuvubo mulatesefu Newbie
      Hi,

      I have a problem with setting a DataModelSelection context variable manually. Let’s assume I have 3 pages: A kind of homepage, a page with a list (dataTable) of objects and a page which shows one object from that list in detail.

      Usually a user clicks on a link like “Show objects” on the homepage. He then get to the page with a list of all objects. Then he can click on one object to get this object displayed in detail. The Code could look like the following:

      We have a BackingBeanA with this two attributes:
      @DataModel
      Private List<Obj> objects;
      @DataModelSelection
      @Out(required=false)
      Private Obj object;

      And the page which shows the details of one object could look like the following:

      <h:outputText value=”#{object.id}” />
      <h:outputText value=”#{object.name}” />
      <h:outputText value=”#{object.description}” />

      As long as the user takes the normal way (Homepage  SelectionPage  DetailPage) everything is fine. But now we want to provide a link on the homepage, which links directly to the DetailPage to show a particular object. The method is implemented in BackingBean2 could look like the following:

      @Out
      Private Obj object;
      Public String showObj() {
      this.object = verySpecialObject;
      return “DetailPage.xhtml”;
      }

      But now, the DetailsPage does not show the id, name and description of our verySpecialObject, but of the first row of the DataModel. So we assign our verySpecialObject to the context variable “object”, but before displaying the DetailPage, Seam just override the context var again with the first rom of the DataModel. It seems, that the connection between the both context variables objects and object exisits even in the context itself.

      So what can I do to solve the problem? I could create two DetailPages, one looking like the one above and one looking like the following:

      <h:outputText value=”#{object2.id}” />
      <h:outputText value=”#{object2.name}” />
      <h:outputText value=”#{object2.description}” />

      And then adjust the BackingBean2, so that it uses this new context variable object2:
      @Out
      Private Obj object2;
      Public String showObj() {
      this.object2 = verySpecialObject;
      return “DetailPage.xhtml”;
      }

      But that’s very uncool, because I would have two almost identical XHTML-Files.
      Any other suggestions?
      Thanks in advance!