javaserverfaces
  1. javaserverfaces
  2. JAVASERVERFACES-159

Nested Datatable expressions resolve wrong (patch included)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2
    • Fix Version/s: 1.0
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      159

      Description

      This bug is probably a duplicate of issue 62 but for some reasons I couldn't
      comment on that bug. Anyway, here is a new testcase and a patch that I hope gets
      accepted since I spent most of the day on this bug.

      The problem is that UIData doesn't correctly reset its DataModel when
      broadcasting events because in a nested data table there could theoretically be
      several DataModels associated with the one UIData. One DataModel and state for
      each nested DataTable instance. Here is another testcase:

      NestedBean.java
      package test;

      import javax.faces.event.ActionEvent;

      public class NestedBean {
      private String id;

      public String getId()

      { return id; }

      public void setId(String id)

      { this.id = id; }

      public void executeLink(ActionEvent event)

      { System.out.println("You clicked on link: "+id); }

      }

      faces-config.xml
      <managed-bean>
      <managed-bean-name>nestedBean1</managed-bean-name>
      <managed-bean-class>test.NestedBean</managed-bean-class>
      <managed-bean-scope>none</managed-bean-scope>
      <managed-property>
      <property-name>id</property-name>
      <value>1</value>
      </managed-property>
      </managed-bean>

      <managed-bean>
      <managed-bean-name>nestedBean2</managed-bean-name>
      <managed-bean-class>test.NestedBean</managed-bean-class>
      <managed-bean-scope>none</managed-bean-scope>
      <managed-property>
      <property-name>id</property-name>
      <value>2</value>
      </managed-property>
      </managed-bean>

      <managed-bean>
      <managed-bean-name>nestedBean3</managed-bean-name>
      <managed-bean-class>test.NestedBean</managed-bean-class>
      <managed-bean-scope>none</managed-bean-scope>
      <managed-property>
      <property-name>id</property-name>
      <value>3</value>
      </managed-property>
      </managed-bean>

      <managed-bean>
      <managed-bean-name>nestedBean4</managed-bean-name>
      <managed-bean-class>test.NestedBean</managed-bean-class>
      <managed-bean-scope>none</managed-bean-scope>
      <managed-property>
      <property-name>id</property-name>
      <value>4</value>
      </managed-property>
      </managed-bean>

      <managed-bean>
      <managed-bean-name>nestedTestList1</managed-bean-name>
      <managed-bean-class>java.util.ArrayList</managed-bean-class>
      <managed-bean-scope>request</managed-bean-scope>
      <list-entries>
      <value>#

      {nestedBean1}

      </value>
      <value>#

      {nestedBean2}

      </value>
      </list-entries>
      </managed-bean>

      <managed-bean>
      <managed-bean-name>nestedTestList2</managed-bean-name>
      <managed-bean-class>java.util.ArrayList</managed-bean-class>
      <managed-bean-scope>request</managed-bean-scope>
      <list-entries>
      <value>#

      {nestedBean3}

      </value>
      <value>#

      {nestedBean4}

      </value>
      </list-entries>
      </managed-bean>
      <managed-bean>
      <managed-bean-name>nestedTestList</managed-bean-name>
      <managed-bean-class>java.util.ArrayList</managed-bean-class>
      <managed-bean-scope>request</managed-bean-scope>
      <list-entries>
      <value>#

      {nestedTestList1}

      </value>
      <value>#

      {nestedTestList2}

      </value>
      </list-entries>
      </managed-bean>

      nestedTest.jsp
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
      <f:view>
      <h:form>
      <h:dataTable value="#

      {nestedTestList}

      " var="nestedList">
      <h:column>
      <h:dataTable value="#

      {nestedList}

      " var="nestedBean">
      <h:column>
      <h:commandLink actionListener="#

      {nestedBean.executeLink}

      "><h:outputText
      value="test bean: #

      {nestedBean.id}

      "/></h:commandLink>
      </h:column>
      </h:dataTable>
      </h:column>
      </h:dataTable>
      </h:form>
      </f:view>

      When nestedTest is loaded you are presented with 4 links. If you click on "test
      bean: 4" then "You clicked on link: 4" is correctly printed to the console.
      However, if you click on "test bean: 1" then "You clicked on link: 3" is
      INCORRECTLY displayed.

      The problem is there are actually 2 DataModels associated with the datatable
      with var="nestedBean". But when the Action Event is fired there is no way for
      the UIData to switch to the correct DataModel.

      The patch is fairly simple, store and persist the nested savestates in the
      parent UIData and temporarily store all of the available DataModels in the
      parent UIData. Then when saving and resotring DescendantState provide the
      correct DataModel to the nested UIData.

      One other note. The "workaround" specified in issue 62 is only valid if the
      value of the param is not value bound. If it is value bound to an item in the
      nested DataModel then the incorrect value will be returned by the
      UIParameter.getValue().

      Patch coming in a few minutes.

      Mike

        Activity

        Hide
        youngm added a comment -

        Unfortunately I don't believe that patch is going to cut it because only the
        last row of the nested Tables saved state is going to be persisted between
        requests. I'll see if you can come up with another test case for the problem.
        If I cannot then great.

        Mike

        Show
        youngm added a comment - Unfortunately I don't believe that patch is going to cut it because only the last row of the nested Tables saved state is going to be persisted between requests. I'll see if you can come up with another test case for the problem. If I cannot then great. Mike
        Hide
        youngm added a comment -

        >I'll see if you can come up with another test case for the problem.

        I meant to say "I'll see if I can come up..."

        Show
        youngm added a comment - >I'll see if you can come up with another test case for the problem. I meant to say "I'll see if I can come up..."
        Hide
        youngm added a comment -

        Well, I cannot make you're patch break. I didn't notice before that the
        entire clientId was being used as the key in saved, so it works great. Thanks
        for fixing this.

        Mike

        Show
        youngm added a comment - Well, I cannot make you're patch break. I didn't notice before that the entire clientId was being used as the key in saved, so it works great. Thanks for fixing this. Mike
        Hide
        youngm added a comment -

        Is this going to be added to JSF_1_1_ROLLING?

        Show
        youngm added a comment - Is this going to be added to JSF_1_1_ROLLING?
        Hide
        Manfred Riem added a comment -

        Closing out issue

        Show
        Manfred Riem added a comment - Closing out issue

          People

          • Assignee:
            Ed Burns
            Reporter:
            youngm
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: