Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting the f:param from commandButton

 
arona kosari
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
arona kosari
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 557
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arnav Jain,

You saved my day !!!

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic