This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSF and the fly likes getting the f:param from commandButton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "getting the f:param from commandButton" Watch "getting the f:param from commandButton" New topic
Author

getting the f:param from commandButton

arona kosari
Greenhorn

Joined: Oct 28, 2006
Posts: 19
hi every body
I have this tags in my jsp:
<h:commandLink action="#{book.edit}">
<f:param name="title" value="#{param.title}" />
</h:commandLink>

how can I get this param in edit method in class Book?

I try to use request.getParameter("title") and request.getRequestMap().get("title") but they work wrong!please help me!
regards
Arona
Josh Juneau
Ranch Hand

Joined: Jun 16, 2004
Posts: 86
You may want to try using the FacesContext. Look at some of the examples at the following link...they may help you out.

http://www.jsffaq.com/Wiki.jsp?page=HowToAccessOneManagedBeanFromAnotherManagedBean


Database Administrator/Application Developer
arona kosari
Greenhorn

Joined: Oct 28, 2006
Posts: 19
hi
I use this code:
ExternalContex contex = FacesContex.getCurrentInstance().getExternalContext();
HttpServletRequest request = (HttpServletRequest)context.getRequest();

and then :
String title = request.getParameter("title");

but title is null.

Maybe I must use another method of getCurrentInstance().
please help me!
Josh Juneau
Ranch Hand

Joined: Jun 16, 2004
Posts: 86
Try to request the parameter map instead of references to the HTTP session. Look at this topic below. It pertains to a commandLink, but it should also work for a commandButton. I hope this solves your issue...good luck!

http://wiki.apache.org/myfaces/ExecutingMethodsFromLinkButtonParameters

code:
FacesContext context = FacesContext.getCurrentInstance();
Map map = context.getExternalContext().getRequestParameterMap();
String localVariable = (String) map.get("your value");
arona kosari
Greenhorn

Joined: Oct 28, 2006
Posts: 19
hi
At first thanks for the useful linkes.
I use the exact code you wrote, but still title is null.

FacesContext context = FacesContext.getCurrentInstance();
Map map = context.getExternalContext().getRequestParameterMap();
String title= (String) map.get("title");

Please help me.
Regards
Ryan Lubke
Ranch Hand

Joined: Jun 20, 2007
Posts: 36
f:param is only handled by h:commandLink. Per the spec, the commandButton doesn't perform any actions with respect to h:param.
Arnav Jain
Greenhorn

Joined: Oct 26, 2010
Posts: 1
Just another way of doing this using a4j:
----------xhtml code------------------------
<a4j:form>
<a4j:commandButton action="#{TestPage.testMethod}" value="Submit">
<f:param name="title" value="TestValue" />
</a4j:commandButton>
</a4j:form>

---------backing bean code---------------------
public void testMethod(){
FacesContext context = FacesContext.getCurrentInstance();
Map map = context.getExternalContext().getRequestParameterMap();
String title1= (String) map.get("title");
}

Though its an old post, just adding my comments if it could help someone looking for same stuff.
Srinivasan thoyyeti
Ranch Hand

Joined: Feb 15, 2007
Posts: 557
Arnav Jain,

You saved my day !!!



Thanks & Regards, T.Srinivasan
SCWCD 1.4(89%), SCJP 5.0(75%)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting the f:param from commandButton