在<p:commandLink>中传递参数

5

你好,我有一段代码:

<p:commandLink value="#{user.strUserid}" action="test.xhtml?faces-redirect=true"/>

如何传递参数到test.xhtml页面并获取该页面的值?我尝试使用标签,但无法在test.xhtml页面中获取该值。请给出建议。


http://www.mkyong.com/jsf2/4-ways-to-pass-parameter-from-jsf-page-to-backing-bean/ - Simon
你能补充更多细节吗? - Sazzadur Rahaman
但可以在test.xhtml页面中获取该值。这是什么意思? - Freak
2个回答

8

5
那么我认为你需要尝试使用<f:setPropertyActionListener ..
<h:commandButton action="#{testBean.takeParam}" >
    <f:setPropertyActionListener target="#{testBean.myStringVal}" value="something" />
</h:commandButton>

然后,您可以在bean类中获取此值。
    @SessionScoped
    public class TestBean{

        public String myStringVal;

        public void setMyStringVal(String myStringVal) {
            this.myStringVal = myStringVal;
        }

    }

    public void takeParam{
         System.out.println("String Value: "+myStringVal);
    }

还可以参见BalusC的JSF通信文章


1
OP正在使用JSF2。那篇文章的目标是JSF1。有一个JSF2变种:http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html - BalusC

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接