简体   繁体   English

h:commandLink条件目标

[英]h:commandLink conditional target

I have a h:commandLink : 我有一个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>

Now controller.userNameGiven is a boolean field and is set to true if username given and otherwise set to false. 现在controller.userNameGiven是一个布尔字段,如果提供了用户名,则设置为true,否则设置为false。 The h:commandLink is present in a iframe and prior to this the target was set to _parent and then if the username is present then it was redirecting to a page in the same parent window but in other case the iframe was rendered in the parent page which is clearly a bug. h:commandLink存在于iframe中,在此之前, target已设置为_parent ,然后如果存在用户名,则它将重定向到同一父窗口中的页面,但在其他情况下,iframe在父页面中呈现这显然是一个错误。 Now after the target validation the redirected page is opening in that iframe, which is undesirable. 现在,在目标验证之后,重定向页面正在该iframe中打开,这是不可取的。 What I am doing wrong? 我做错了什么?

Thanks and regards. 谢谢并恭祝安康。


Edit 1: 编辑1:

I have changed the target to: 我已将target更改为:

target="#{controller.target}"

where: 哪里:

    public String getTarget() {
        return target;
    }

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

and

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

But its still not working and the url somepage is opening in the iframe. 但它仍然无法正常工作,并且在iframe中打开了网址网址页面。

Move the logic into a bean method: 将逻辑移到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