2012-10-20 24 views
0

我发送值到我的视图从我的bean和我的视图到我的bean,一切都很好,如果我使用“acitonListener”等事件,但现在我想发送用户到其他页面(使用导航规则,它完美)当我点击一个按钮,但在此之前,我想在我的bean中设置一个值,我该怎么做?如何使用primefaces将视图中的值发送到我的bean?

我做这样的

<p:commandButton value="Send" id="sendButton" action="#{myBean.myMethod}" 
    update=":form:growTop" > 
    </p:commandButton> 

东西在此之前,只有与<h:outputText/>一个表,从我的豆值,没有办法做到这一点?

感谢

回答

1
action="#{myBean.myMethod(myParameter)} 

上述方法表达将派myParametermyMethod功能支持bean:返回一个有效的导航

public void myMethod(String myParameter) { 
    // ... 
} 

您还可以发送用户到下一页来自您行动方法的结果:

public String myMethod(String myParameter) { 
    // ... 
    return "myPage?faces-redirect=true"; 
} 

在你的具体情况下,如果存在其上打印了一个辅助bean值:

<h:outputText value=#{myBean.myParameter}/> 

以下动作

<p:commandButton value="Send" id="sendButton" action="#{myBean.myMethod(myParameter)} 
    update=":form:growTop" > 
</p:commandButton> 

将传递到myParameter动作方法。

为了获得Primefaces数据表的预期行为,至少在表值后面使用@ViewScoped支持bean。

+0

谢谢,就是这样! – jpganz18

+0

欢迎您! –

相关问题