当前位置: 动力学知识库 > 问答 > 编程问答 >

jsf - Passing a parameter in <p:commandLink>

问题描述:

Hi I have a code like:

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

How can I pass a parameter to test.xhtml to get the value in the said page?

I tried with <f:param> tag.But can get the value in the test.xhtml page.

Please suggest.

网友答案:

Replace it by <h:link>

<h:link value="#{user.strUserid}" outcome="test.xhtml">
    <f:param name="foo" value="bar" />
</h:link>

and use <f:viewParam> to set it as a property of the bean associated with target page

<f:metadata>
    <f:viewParam name="foo" value="#{bean.foo}" />
</f:metadata>

See also:

  • When should I use h:outputLink instead of h:commandLink?
  • What can <f:metadata> and <f:viewParam> be used for?
网友答案:

Then I think you need to try <f:setPropertyActionListener ..

<h:commandButton action="#{testBean.takeParam}" >
    <f:setPropertyActionListener target="#{testBean.myStringVal}" value="something" />
</h:commandButton>

And then You can get this value in your bean class

    @SessionScoped
    public class TestBean{

        public String myStringVal;

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

    }

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

Also see Communication in JSF by BalusC

分享给朋友:
您可能感兴趣的文章:
随机阅读: