我正在尝试从已包含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>
受管Bean
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。
答案 0 :(得分:0)
将bean放在视图范围内。这样,@PostConstruct
在视图的初始请求中只运行一次,只要您通过ajax与同一视图进行交互并返回null
或void
,bean就会生效关于行动方法。