JSF创建动态命令链接

时间:2017-12-08 12:29:04

标签: primefaces jsf-2.2

我正在使用Eclipse Mars.2,64位Java 1.8更新102,JSF Mojarra 2.2.2,Primefaces 6.1,Spring 3.2.3,Hibernate 4.3(MySQL 5.1.39)和Tomcat 7.0开发Maven项目。 53。

我有2个xhtml页面及其各自的@ViewScoped支持bean。在第A页中,我有以下代码:

<p:dataGrid var="theReg" value="#{pageA_BB.listOfReg}" columns="1" rows="5" paginator="true" paginatorPosition="bottom">
    <p:commandLink value="#{theReg.title}" action="pageB?faces-redirect=true&amp;idvalue=#{theReg.paramValue}" />
</p:dataGrid>

上面的代码应该呈现一些具有不同param值的URL。 theReg.title 是一个字符串, theReg.paramValue 是一个整数

第B页支持bean中,我有以下代码来营救并使用“idvalue”参数:

@PostConstruct
public void init() {
    if (FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("idvalue")!=null){
        idvalue = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("idvalue"));
    }else{
        idvalue = 0;
    }
}

上述代码不起作用,因为在commandLink操作中不允许使用EL。

我曾尝试使用af:param,如here所述,但使用f:params需要支持bean为@Requestscope(其他方式是范围错误触发),我需要一个@Viewscoped,因为有些Primefaces组件需要它。

我曾考虑在像onClick这样的onClick事件中使用EL:

<p:commandButton onclick="window.open('pageB.xhtml?faces-redirect=true&amp;idvalue=#{theReg.paramValue}', '_blank')" value="#{theReg.title}"/> 

但是我想使用params,因为我觉得这将是“最干净”的方法。

有什么建议吗?

提前多多感谢!

0 个答案:

没有答案
相关问题