Passing a parameter to <p: commandLink>

Hi, I have a code like:

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

How to pass the test.xhtml parameter to get the value on the specified page? I tried with the <f:param> . But you can get the value on the test.xhtml page. Please suggest.

+4
source share
2 answers

Replace it with <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 the bean property associated with the landing page

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

See also:

+7
source

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 BalusC JSF Communications

+5
source

Source: https://habr.com/ru/post/1488026/


All Articles