sameer
sameer

Reputation: 220

JSF 2.0 Pass parameters to the same page

i have a page called page1.jsf which contains one parameter. i have a command button which contains the param. On clicking the button, it must return to page1.jsf together with whatever parameter i pass.

<h:commandButton action="#{myBean.DoSthng}" value="Something" >
 <f:param name="p1" value="sthng"></f:param>
 </h:commandButton>

How would i pass this parameter to page1.jsf itself?

In the faces-config.xml - managed Bean, i set it like this

<managed-bean>
  <managed-bean-name>myBean</managed-bean-name>
  <managed-bean-class>com.MyBean</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
  <managed-property>
    <property-name>p1</property-name>
    <value>#{myBean.p1}</value>
  </managed-property>
</managed-bean>

and this is giving me an error.

Can you all help me please.

EDIT

From page1 i have to pass a value from an action to backing bean. The backing bean should redirect me back to page1 but with different contents!

Upvotes: 0

Views: 1453

Answers (3)

Matt Handy
Matt Handy

Reputation: 30025

Although I am not quite sure what you are trying to achieve, you could use an f:setPropertyActionListener:

<h:commandButton action="#{myBean.DoSthng}" value="Something" >
   <f:setPropertyActionListener target="#{myBean.p1}" value="something" />
</h:commandButton>

This will set the backing bean property and if you return null from your action method (or if it is void) the current page should reflect the changes made to your backing bean.

Upvotes: 1

roel
roel

Reputation: 2003

You put your param in hidden field and it will be available

<input type="hidden" id="sl" name="sl" value="#{param.sl}"/>

And then you can use it

${param.sl}

Upvotes: 0

Jigar Joshi
Jigar Joshi

Reputation: 240860

From page you are calling an action so while returning you could do following

return "someView.jsf?param=val&faces-redirect=true"

Upvotes: 0

Related Questions