所以我有这个示例代码:
hello.xhtml
<h:form>
<h:inputText id="username" value="#{blahBlah.username}" />
<br />
<h:commandButton action="#{blahBlah.verifyUser()}" value="Go to goodbye!"/>
</h:form>
BlahBlah.java
@ManagedBean
@SessionScoped
public class BlahBlah {
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String verifyUser(){
if (!username.equals("koray")) {
return "hello?faces-redirect=true&msg=" + username;
}
return "goodbye?faces-redirect=true&msg=" + username;
}
}
最后 goodbye.xhtml
<f:view>
<h:body>
#{param.msg}
</h:body>
</f:view>
所以这可以按预期工作。提交表格后,我会发现自己在
/goodbye.xhtml?msg=koray
等。
但我想使用导航规则,所以这就是我修改代码的方式:
面-config.xml中
<navigation-rule>
<from-view-id>/hello.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/goodbye.xhtml</to-view-id>
<redirect>
<redirect-param>
<name>msg</name>
<value>#{blahBlah.username}</value>
</redirect-param>
</redirect>
</navigation-case>
<navigation-case>
<from-outcome>fail</from-outcome>
<to-view-id>/hello.xhtml</to-view-id>
<redirect>
<redirect-param>
<name>msg</name>
<value>#{blahBlah.username}</value>
</redirect-param>
</redirect>
</navigation-case>
</navigation-rule>
和
BlahBlah.java
@ManagedBean
@SessionScoped
public class BlahBlah {
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String verifyUser(){
if (!username.equals("koray")) {
return "fail";
}
return "success";
}
}
在这种情况下,我将再次被重定向到 goodbye.xhtml ,但没有?msg =
那么
的目的是什么?<redirect-param>
<name>msg</name>
<value>#{blahBlah.username}</value>
</redirect-param>
为什么它不起作用?