我无法将一个简单参数从一个Facelet传递到另一个Facelet,并设置一个bean属性...这里是我的代码:
主叫页面 main.xhtml (仅限相关代码):
<h:link outcome="index" value="disconnect" >
<f:param name="logout" value="true" />
</h:link>
最后一页 index.xhtml :
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:metadata>
<f:viewParam name="logout" value="#{indexBean.logout}"/>
<f:event type="preRenderView" listener="#{indexBean.redirect}" />
</f:metadata>
</html>
IndexBean (仅限相关代码):
@Named
@RequestScoped
public class IndexBean {
@Inject
private Logger logger;
private boolean logout;
public IndexBean() {this.logout = false;}
public void setLogout(boolean logout) {
logger.log(Level.DEBUG, "logout changed");
this.logout = logout;
}
public boolean isLogout() {return logout;}
public void redirect() throws IOException {
if(logout) {
//Never get in here
} else {
//Always here
}
}
}
我正在链接(http://localhost/index.xhtml?logout=true)上获取网址参数,但永远不会调用setLogout
方法。
我甚至试图将logout
类型更改为String,正确更改getter和setter,看看会发生什么,但是setter永远不会被调用...
有什么想法吗?
提前致谢!!