• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to pass parameter to the next page with a html:link attribute

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hiiii everyone ..i have a screen which has list of users shown with their
firstname lastname username edit delete ...this all information is list of users from database.....edit and delete are with <html:link> tags
Problem is each user is associated with userid...so if somebody clicks edit link on some user i have to pass that user's id with <html:link>

for example...
<html:link forward="edit"> edit</edit>

in congif file..
<global-forwards>
<forward name="edit" path="/userEdit.jsp?userid=1>....in this line i have assumed userid =1..but how to specify what userid will be...bcaz it will be dynamic accprding to what edit link client hits....I am new at struts ...Thanks in advance
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hiiii

From Struts Developer Guide :
"There are two ways you can append one or more dynamically defined query parameters to the hyperlink -- specify a single parameter with the paramId attribute (and its associated attributes to select the value), or specify the name (and optional property) attributes to select a java.util.Map bean that contains one or more parameter ids and corresponding values.

To specify a single parameter, use the paramId attribute to define the name of the request parameter to be submitted. To specify the corresponding value, use one of the following approaches:
- Specify only the paramName attribute - The named JSP bean (optionally scoped by the value of the paramScope attribute) must identify a value that can be converted to a String.
- Specify both the paramName and paramProperty attributes - The specified property getter method will be called on the JSP bean identified by the paramName (and optional paramScope) attributes, in order to select a value that can be converted to a String.

If you prefer to specify a java.util.Map that contains all of the request parameters to be added to the hyperlink, use one of the following techniques:
- Specify only the name attribute - The named JSP bean (optionally scoped by the value of the scope attribute) must identify a java.util.Map containing the parameters.
- Specify both name and property attributes - The specified property getter method will be called on the bean identified by the name (and optional scope) attributes, in order to return the java.util.Map containing the parameters.

As the Map is processed, the keys are assumed to be the names of query parameters to be appended to the hyperlink. The value associated with each key must be either a String or a String array representing the parameter value(s), or an object whose toString() method will be called. If a String array is specified, more than one value for the same query parameter name will be created."

Here is a basic example. Of course, in the real world, values added to the HashMap should be dynamic, and probably handled into an Action instead of the JSP :

Resulting HTML will be :
 
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've just hit this challenge too, and following the Struts instructions here and copied above, I added the following to the relevant Struts form:



Then, in the JSP:



Not too ugly after all...though it would be nice to generate the map within the JSP using an appropriate set of tags.


-Tim
 
reply
    Bookmark Topic Watch Topic
  • New Topic