JSF中的多个页面没有调用backing bean mutators

时间:2010-10-29 06:54:16

标签: java jsf jboss seam

我目前正在为现有网站开发一个额外的页面。实际上那部分并不是那么重要 - 页面执行它自己独立的功能。

无论如何,最初,这个“页面”由一个jpdl页面流控制的两个页面组成。一切正常,除了引用第二页时。用户可以在字段中输入他们喜欢的内容,然后单击“提交”。一切都按预期运行,除了从未调用过set方法。尽管从Backing Bean中读取现有值,但从未调用过setter。我写了一些Seam测试并发现我可以创建自己的FacesRequest,它会在同一个EL表达式上调用setValue()并且它工作正常,这指出了JSF方面失败的东西。我仍然没有想到它并继续前进。当然,现在我必须回到它。

有问题的代码看起来像......(不相关的部分已删除。由于这些非常普遍并且在很多地方都在使用,因此有很多不妥之处):

@Name("user")
@Install(precedence = Install.DEPLOYMENT)
@Scope(ScopeType.CONVERSATION)
@AutoCreate
public class UserBean{
    private String username;
    public void setUsername(String username){this.username = username;}
    public String getUsername(){return username;}
}

页面的基本片段“users.xhtml”......

<h:form id="modifyUsersForm">
    <rich:panel>
        <rich:dataTable id="userTable" value="#{users}" var="myUser">
            <rich:column style="text-align:center">
                <h:commandButton id="modifyButton" type="submit" value="Modify" action="modify">
                    <f:setPropertyActionListener target="#{user.id}" value="#{myUser.id}"/>
                </h:commandButton>
            </rich:column>
        </rich:dataTable>
    </rich:panel>
    <s:button id="modifyUserCancelButton" value="Cancel" action="cancel"/>
    </s:fragment>
</h:form>

用户是一个扩展LinkedList<UserBean>的bean。所有这些基本上都是创建一个按钮表,说“修改”

页面“user.xhtml”的基本摘要......

<h:form id="modifyUserForm">
    <rich:panel>
        <h:inputText id="username" value="#{user.username}"/>
        <div style="clear: both"/>
    </rich:panel>
    <s:button id="modifyUserCancelButton" value="Cancel" action="cancel"/>
    <s:button id="modifyUserModifyButton" value="Modify" action="doModify"/>
</h:form>

的“users.pageflow.jpdl.xml”
<pageflow-definition xmlns="http://jboss.com/products/seam/pageflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="users">

    <start-page name="start" view-id="/users.xhtml" no-conversation-view-id="/users.xhtml">
        <transition name="cancel" to="cancelled"/>
        <transition name="retrieve" to="retrieve"/>
    </start-page>

    <decision name="retrieve_agent" expression="#{action.retrieve}">
        <transition name="success" to="retrieved"/>
        <transition name="failure" to="start"/>
    </decision>

    <page name="retrieved" view-id="/users.xhtml" no-conversation-view-id="/users.xhtml">
        <transition name="modify" to="retrieve_user"/>
        <transition name="cancel" to="cancelled"/>
    </page>

    <decision name="retrieve_user" expression="#{action.retrieveUser}">
        <transition name="success" to="modify"/>
        <transition name="failure" to="start"/>
    </decision>

    <page name="modify" view-id="/user.xhtml" no-conversation-view-id="/user.xhtml">
        <transition name="cancel" to="cancelled"/>
        <transition name="doModify" to="doModify"/>
    </page>

    <decision name="doModify" expression="#{action.modifyUser}">
        <transition name="success" to="start"/>
        <transition name="failure" to="modify"/>
    </decision>

    <page name="cancelled" view-id="/users.xhtml">
        <end-conversation before-redirect="true"/>
        <redirect/>
    </page>
</pageflow-definition>

那我错过了什么?为什么在JSF生命周期中,当它在同一页面上成功调用getUsername时,不会在user.xhtml上调用setUsername?我们使用的是Java 1.6.0_07,Seam 2.2.1,JSF 1.1(我相信。很可能是1.2),并部署到JBoss 4.2.3。

1 个答案:

答案 0 :(得分:1)

你试过h:commandButton吗? s:button执行GET,而不执行POST。也许这会有所帮助。