• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Hashmap in Struts

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I need some direction on how to proceed on using hashmap. I am new to this. Please advise.

I have a form with Struts validation enabled. In my form I have a drop down.Based on value from drop down. I need to load one particular value.


My form has a default value assigned to a particular field. But when something is selected from dropdown I need to overwrite that default value with the value mentioned in the Hashmap for that selected dropdown value(key).


I am using Hashmap to store the key value pairs. Now my question is where should this functionality be. Will it be in the ActionForm or in the Action class.

Thanks.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the process:
  • Create a property in your ActionForm for the value you want to set (example: selectedValue)
  • override the reset method of your ActionForm and in that method set the default value (example: selectedValue="x")
  • Use the <html:select> and <html:optionsCollection> tags to render the select box. Struts will then display the default value in the select box and change it when the user changes the value.

  • Example:

    The above assumes your hashmap is stored in either session or request scope under the name of "theHashMap".
    [ January 25, 2007: Message edited by: Merrill Higginson ]
     
    Ravi Kumar
    Greenhorn
    Posts: 24
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Merrill. I will try that.
     
    Sheriff
    Posts: 67645
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    "Kris10",

    There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

    In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

    Thanks!
    bear
    JavaRanch Sheriff
     
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Originally posted by Merrill Higginson:
    Here is the process:

  • Create a property in your ActionForm for the value you want to set (example: selectedValue)
  • override the reset method of your ActionForm and in that method set the default value (example: selectedValue="x")
  • Use the <html:select> and <html ptionsCollection> tags to render the select box. Struts will then display the default value in the select box and change it when the user changes the value.

  • Example:
    <blockquote>code:
    <pre name="code" class="core"><html:select property="selectedValue" >
    <html ptionsCollection name="theHashMap" label="value" value="key" />
    </html:select>
    </pre>

    The above assumes your hashmap is stored in either session or request scope under the name of "theHashMap".

    [ January 25, 2007: Message edited by: Merrill Higginson ]
    </blockquote>

    Tried what you suggest and still get an error about property value not set for optionsCollection. any idea?
     
    Merrill Higginson
    Ranch Hand
    Posts: 4864
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    If you want help debugging this, you will need to post revlevant portions of your code including the JSP, the ActionForm, the Action class, and the struts-config.xml file. Also post the exact error message you get along with the firt 10 lines or so of the stack trace.
     
    pie. tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    reply
      Bookmark Topic Watch Topic
    • New Topic