1

我无法将一个简单的参数从一个 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)上获得了 URL 参数,但该setLogout方法从未被调用。

我什至尝试将logout类型更改为 String,正确更改 getter 和 setter,看看会发生什么,但从未调用过 setter...

任何想法?

提前致谢!!

4

0 回答 0