• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing f:param with h:commandLink  RSS feed

 
Jeremy Stoneburner
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have a question about using <h:commandButton>. In my application, I am trying to use a commandButton to delete a record from the database. I was using a commandLink and using a <f:param> to pass in the id of the record to be deleted. The requirements changed and a pop-up window for deletion confirmation is now requested. From what I understand, commandLink (in JSF 1.1) does not support the use of onclick to call a javascrip confirmation function. However, I cannot figure out how to pass the parameter by using a commandButton. Any advice would be nice.

This is the code snipet I was using before the change:


This is what I had been attempting to do with no avail:


Thank you in advance.
 
Narendran Nair
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




copy the getParameter to the desired type
use this code in the backing bean ... thats all .........
 
Alex Skor
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had similar problem, and your advice helped.
but it is strange that the parameter is not passed to my backing bean and I have to use the code you've provided.

I have a list of objects with IDs:


ViewTests class has suiteId:
private Long suiteId; (with getters and setters),

and performSearch() method always sees NULL suiteId.

why doesn't a Long parameter work? I tried to change it to Sting, but it did not help: it is still not passed to the backing bean.
[ August 16, 2006: Message edited by: Alex Skor ]
 
Daniel Rhoades
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I personally get them from the requestMap:

FacesContext context = FacesContext.getCurrentInstance();
Object value = context.getExternalContext().getRequestMap().get("paramName");
 
Sudeep Agrawal
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to view the parameter <f:param> that I pass in the the <h:commandLink>.
The backing bean was tried in both "Session" scope and "Request" Scope.
The Map Attribute I got were something like this :

"I am using actionListener and not action method", would this make a difference?



Please advice how can I pass parameters via. commandLink.

Thanks,
[ January 28, 2008: Message edited by: Sudeep Agrawal ]
 
Sudeep Agrawal
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darn I was getting the application Map instead of the request MAp.
Problem Solved.
 
Bob Good
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://forum.java.sun.com/thread.jspa?threadID=581604&messageID=2956929

f:param not supported for commandButton.

One thing you can do is put a inputHidden field on your page.
The code a javascript on mouse down to set the field:

document.getElementById("yourForm:hiddenTextField").value="someValue";

Now you can get the value using the request map.

There are other ways....
 
Bob Good
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another thing you can do in the JSF action for the commandButton is grab the target bean you are going to from the faces context and set the parm value directly. Here is sample code the the action, userInfobean is the backing bean for the target JSP:

 
Bill Lyons
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Daniel Rhoades:
I personally get them from the requestMap:

FacesContext context = FacesContext.getCurrentInstance();
Object value = context.getExternalContext().getRequestMap().get("paramName");


Hi folks,

This post is almost correct. The 2nd to last get needs to be on getRequestParameterMap() instead of .getRequestMap

The corrected code should read:
FacesContext context = FacesContext.getCurrentInstance();
Object value = context.getExternalContext().getRequestParameterMap().get("paramName");

For readability I broke it up into 3 lines:

[ April 03, 2008: Message edited by: Bill Lyons ]
 
Seamus Minogue
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am passing a paramter from a commandLink in the same way that was discussed.
In my backing bean I am also getting the value in this way:




Its working great in FireFox >2.0.2 but when I try and use the site in IE6 the parameter is not being passed through. (String)requestMap.get("paramName") is returning null.

Is there something specific I need to do for parameters to work for commandLinks in IE?

Thanks,
S
 
Seamus Minogue
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind. I found my answer.

Wasnt even a JSF issue.

It seemed that for some reason FF had no problem with <input name="id"/> and IE simply dropped it.

I changed the name to be somethingId and it works fine.

Oh I love these little differences between browsers...
 
Chris Lewis
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Seamus Minogue:

It seemed that for some reason FF had no problem with <input name="id"/> and IE simply dropped it.


Thanks for sharing your solution - that was exactly my problem.
[ July 17, 2008: Message edited by: Chris Lewis ]
 
Shishir Choudhary
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but in all the cases we need to update config.xml

please help me for the same............


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!