0

任何人都可以在下面提供帮助。

只有当条件为真时,我才需要使用 jsf 中的命令链接标签打开一个新的浏览器选项卡。

如何在jsf标签中设置条件?

4

2 回答 2

0

You can use managed bean actionListener of the commandMenu and then get the condition tested and redirect to the page in new tab if its true...

enter image description here

import javax.faces.event.ActionEvent;

public class PageBean {

String page;

public PageBean() {
}

public void getMenu(ActionEvent actionEvent) {
    // Add event code here...

/* add your code to get and test condition and based upon the condition true and false conditon get commandMenu Id of the menu clicked by the following way

be sure to give the id of the command menu the same name you want to open in the next tab upon menu click like in my case i have given the command menu id as page1 String id = actionEvent.getComponent().getId(); System.out.println(" Menu ID : "+id); now set the fetched menu id to the page variable with the proper page extension and acccess the pariable in the action from the manged bean to redirect to the page in the next tab upon menu click after testing the validation */

    page = id;
    System.out.println("Value assigned to the page from the menu Id is :"+page);
}

public String getPage() {
    return page;
}

public void setPage(String page) {
    this.page = page;
}

public void dashContentEntryCheck(){
    System.out.println("entered inside dashboard content task flow");
}

}

于 2013-03-22T07:47:52.563 回答
0

您可以使用该rendered属性,并使用 EL 表达式完成它们。使用该rendered属性,仅当条件为 时才会显示链接true

如果要根据条件在新的浏览器选项卡中打开命令链接,可以使用rendered属性轻松实现:

<h:commandLink action="my_navigation_rule"
               rendered="#{!MyBean.booleanValue}" />

<h:commandLink action="my_navigation_rule"
               rendered="#{MyBean.booleanValue}" target="_blank"/>

由于rendered条件是排他性的,因此只会打印其中一个 commandLinks。

有关 JSF 表达式语言 (EL) 的更多信息(在 jsf 标签中设置条件非常有用)-->此处

注意:我知道解决方案可以改进,因为您可以使用 EL 表达式来确定target值,但我认为这个解决方案更容易。

于 2013-03-20T15:22:47.690 回答