我正在尝试从已经包含GET参数的页面发送POST请求。没有引发任何错误,但是控制流似乎跳过了调用应用程序阶段。如果我在没有GET参数的页面上尝试相同的POST请求,则一切正常。

模板实现此实现根据名为action的GET参数实现所需的组件

<ui:define name = "front">

    <cd:accountSettings rendered = "${accountController.action == 'details'}"/>

    <cd:accountTabShortcut rendered = "${accountController.action == 'loginfo'}"/>

</ui:define>


组件

<cc:implementation>

    <h:form id = "auth-fm">

        <div class = "fm-input">
            <h:outputLabel for="firstName">#{appMessage['form.label.name.first']}</h:outputLabel>
            <div class = "fm-input-elem">
                <h:inputText styleClass="input-auth" id="firstName" label="firstName" value="#{accountController.firstName}">
                    <f:validator validatorId="nameValidator" />
                    <f:ajax event = "blur" render = "firstNameMessage" />
                </h:inputText>
                <div class = "fm-err">
                    <h:message id = "firstNameMessage" for = "firstName" />
                </div>
            </div>
        </div>

        <div class = "fm-input">
            <h:outputLabel for="lastName">#{appMessage['form.label.name.last']}</h:outputLabel>
            <div class = "fm-input-elem">
                <h:inputText styleClass="input-auth" id="lastName" label="lastName" value="#{accountController.lastName}">
                    <f:validator validatorId="nameValidator" />
                    <f:ajax event = "blur" render = "lastNameMessage" />
                </h:inputText>
                <div class = "fm-err">
                    <h:message id = "lastNameMessage" for = "lastName" />
                </div>
            </div>
        </div>

        <div class = "fm-submit">
            <h:commandButton styleClass="bn-auth lk-bn-rng" id = "authButton" value="#{appMessage['form.text.register']}" action="#{accountController.changeDetails}" />
        </div>

    </h:form>


托管豆

public class AccountController extends BaseController{

    private String firstName;
    private String lastName;
    @PostConstruct
    public void init(){
        System.out.println("=> Account Controller - init() - enter");

        action = getParam("action");

        firstName = sessionController.getAuthUser().getFirstName();
                lastName = sessionController.getAuthUser().getLastName();

        System.out.println("=< Account Controller - init() - exit");
    }

     public String changeDetails(){
        System.out.println("=> Account Controller - Change Details - start");
        System.out.println("First Name: " + firstName);
        System.out.println("Last Name: " + lastName);
        System.out.println("=< Account Controller - Change Details - start");
        return "account";
    }
    }


当我跟踪阶段侦听器时,永远不会调用changeDetails()方法。
该帖子的调用是通过如下页面进行的:mySite.com/account.xhtml?action=details。我认为这可能是问题所在,但我不能确定,除了将内容分为两页之外,我不知道任何解决方法:accountDetails和accountLoginfo。

LE:
我正在使用带有Glassfish3容器的JSF 2.0和用于GUI的XHTML facelets。

最佳答案

将bean放入视图范围。这样,@PostConstruct将仅在视图的初始请求上运行一次,并且只要您通过ajax并通过在操作方法上返回nullvoid与同一个视图进行交互,该Bean就会存在。

也可以看看:


Communication in JSF2 - Managed bean scopes

10-07 20:53