我做了一个输入页面,这个页面可以通过点击butoon来增加输入框,大致代码如下:
...
<af:forEach items="#{bean1.collection1}" var="item1">
<af:panelForm>
<af:inputText value="#{item1.propertity1}" label="Label1">
</af:inputText>
</af:panelForm>
</af:forEach>
...
<af:forEach items="#{bean1.collection2}" var="item2">
<af:panelForm>
<af:inputText value="#{item2.propertity2}" label="Label2">
</af:inputText>
</af:panelForm>
</af:forEach>
...
上述代码中,bean1是一个managed bean,在adf-faces-config.xml中配置,另外在PannelPage的facet actions中放了两个CommandButton,大致代码如下:
...
<f:facet name="actions">
<af:panelButtonBar binding="..." id="panelButtonBar1">
<af:commandButton text="More Item1" binding="..."
id="moreItem1Button"
action="#{backing1.moreItem1Button_action}"/>
<af:commandButton text="More Item2" binding="..."
id="moreItem2Button"
action="#{backing1.moreItem2Button_action}"/>
</af:panelButtonBar>
</f:facet>
...在页面的backing Bean中,方法moreItem1Button_action()构造新的item1对象,并将其加入到managed bean bean1的collection1中,方法moreItem2Button_action()构造新的item2对象,并将其加入到managed bean bean1的collection2中.问题是,后面一个button可以正常工作,即点击moreItem2Button后,页面上会增加一个输入框。前一个button不能正常工作,点击moreItem1Button后,页面显示会变得很混乱,明显是页面绘制有问题,感觉问题在于PPR。
但是两个按钮的PartialSubmit都设的是false。我试着交换了两个forEach的位置,即将collection1放在后面,那么就会变成moreItem1Button按钮正常工作,而moreItem2Button出问题。需要说明的是,在backing bean中对bean1的更新是没有问题的,如果将显示有问题的页面的地址粘贴到一个firefox的一个新tab页中回车,页面会被正确的绘制。还请高人指点。Thanks. :-)

解决方案 »

  1.   

    To make the problem more clear, I removed two panelForms and the second Button, so the code will be as follows:
    ...
    <af:forEach items="#{bean1.collection1}" var="item1">
    <af:inputText label="Label 1" value="#{item1.property1}"/>
    </af:forEach>
    <af:forEach items="#{bean1.collection2}" var="item2">
    <af:inputText label="Label 2" value="#{item2.property2}"/>
    </af:forEach>
    <f:facet name="actions">
    <af:commandButton text="commandButton 1"
    binding="#{backing_untitled1.commandButton1}"
    id="commandButton1"
    action="#{backing_untitled1.commandButton1_action}"/>
    </f:facet>
    ...
    The code in backing Bean will be as follows:
    public String commandButton1_action() {
    // Add event code here...
    Item1 item1 = new Item1();
    item1.setProperty1("new Added!");
    FacesContext ctx = FacesContext.getCurrentInstance();
    Bean1 bean1 = (Bean1)JSFUtil.getManagedBeanValue(ctx, "bean1");
    bean1.getCollection1().add(item1);
    return null;
    }
    ...
    After some clicks of the button, the generated Html is as follows (it's copied from firefox):
    ...
    <table><tr>
    <td>... Label 1 ...</td>
    <td><input id="form1:_id0" name="form1:_id0" type="text"></td>
    </tr></table>
    <table><tr>
    <td>... Label 2 ...</td>
    <td><input id="form1:_id1" name="form1:_id1" type="text"></td>
    </tr></table>
    <table><tr>
    <td... Label 2 ...></td>
    <td><input id="form1:_id2" name="form1:_id2" type="text"></td>
    </tr></table>
    <table><tr>
    <td... Label 2 ...></td>
    <td><input id="form1:_id3" name="form1:_id3" type="text"></td>
    </tr></table>
    <table><tr>
    <td... Label 2 ...></td>
    <td><input id="form1:_id4" name="form1:_id4" type="text"></td>
    </tr></table>
    ...This output is obviously wrong. What I added is Item1, so the added inputText should be labeled "Label 1", and the new added inputText should have "new Added!" value.If I visit the page in a new tab of firefox, the output will be fine like this:
    ...<table><tr>
    <td>... Label 1 ...</td>
    <td><input id="form1:_id0" name="form1:_id0" type="text"></td>
    </tr></table>
    <table><tr>
    <td>... Label 1 ...</td>
    <td><input id="form1:_id1" name="form1:_id1" type="text" value="new Added!"></td>
    </tr></table>
    <table><tr>
    <td... Label 1 ...></td>
    <td><input id="form1:_id2" name="form1:_id2" type="text" value="new Added!"></td>
    </tr></table>
    <table><tr>
    <td... Label 1 ...></td>
    <td><input id="form1:_id3" name="form1:_id3" type="text" value="new Added!"></td>
    </tr></table>
    <table><tr>
    <td... Label 2 ...></td>
    <td><input id="form1:_id4" name="form1:_id4" type="text"></td>
    </tr></table>
    ...This output is what I need!Thanks. :-)