繁体   English   中英

h:commandLink条件目标

[英]h:commandLink conditional target

我有一个h:commandLink

<h:commandLink value="" 
    actionListener="#{controller.authenticateAccount}" 
    style="text-decoration: none;" 
    target="#{controller.userNameGiven ? '_parent' : '' }">
        <img src="../images/Profile/authenticateCPButton.gif" border="0" style="padding-left: 2px;"/>
</h:commandLink>

现在controller.userNameGiven是一个布尔字段,如果提供了用户名,则设置为true,否则设置为false。 h:commandLink存在于iframe中,在此之前, target已设置为_parent ,然后如果存在用户名,则它将重定向到同一父窗口中的页面,但在其他情况下,iframe在父页面中呈现这显然是一个错误。 现在,在目标验证之后,重定向页面正在该iframe中打开,这是不可取的。 我做错了什么?

谢谢并恭祝安康。


编辑1:

我已将target更改为:

target="#{controller.target}"

哪里:

    public String getTarget() {
        return target;
    }

    public void setTarget(String target) {
        this.target = target;
    }    

if(this.userName != null && this.userName.trim().length()>0) {
            target = "_parent";
            FacesContext.getCurrentInstance().getExternalContext().redirect("./somepage");
} else {
            target = "";
}

但它仍然无法正常工作,并且在iframe中打开了网址网址页面。

将逻辑移到bean方法中:

public class Controller
{
    // ...

    public boolean isUserNameGiven () { /* snip */ }

    public String getFooTarget()
    {
        return this.isUserNameGiven() ? "_parent" : "";
    }

    // ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM