Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a parameter in <p:commandLink>

Tags:

jsf

primefaces

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.

like image 580
NDeveloper Avatar asked Jun 25 '13 08:06

NDeveloper


2 Answers

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>, <f:viewParam> and <f:viewAction> be used for?
like image 127
BalusC Avatar answered Jan 03 '23 00:01

BalusC


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

like image 43
Freak Avatar answered Jan 03 '23 01:01

Freak