[英]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.