I asked a similar question yesterday.

see:
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg39132.html
I ended up wrapping the Hashmap

Test class:
--------------
public class HashWrapper implements java.io.Serializable {
    java.util.HashMap map = new java.util.HashMap();

    public HashWrapper() {
         map.put("item1", "H");
         map.put("item2", "E");
         map.put("item3", "I");
    }

     public String getItem(String item){
      return (String)map.get(item);
     }
}
----------------
request setAttribute("hashWrapper",new HashWrapper());

------------------
Then I used the syntax for the tags:
<logic:equal name="hashWrapper" property="item(item2)" value="H"></logic:equal>

item(item2) will become getItem("item1")....

This should work the same for the jsp getProperty  tags, though have not
tried it.


Hope this helps.




"Morycz, Felicia V" <[EMAIL PROTECTED]> on 08/28/2002 10:51:02 AM

Please respond to "Struts Users Mailing List"
       <[EMAIL PROTECTED]>

To:    "'Struts Users Mailing List'" <[EMAIL PROTECTED]>
cc:

Subject:    RE: Want to Access Key/Value Pairs in Hashtable within jsp


I see in the struts examples where LabelValueBeans are placed in a Vector
or
List and used with select option tags.
So what I would define in my form bean is a collection of LabelValueBeans
that looks like this:
("label1","value1")
("label2","value2")
("label3","value3")

I will have a getLabelValueCollection() method that would return the
collection of these LabelValueBeans

then in my jsp I want to do a bean write or getProperty passing in the
label
and getting back the value.  Something like this:
<jsp:getProperty name="responseBean"
property="labelValueCollection("label3")"/>

I do not understand the jsp syntax to pass in the label and get the value
out of the collection.

-----Original Message-----
From: Joe Latty [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 28, 2002 10:55 AM
To: Struts Users Mailing List
Subject: RE: Want to Access Key/Value Pairs in Hashtable within jsp


If your using Struts 1.1-b2 check out org.apache.struts.util.LabelValueBean

Joe

-----Original Message-----
From: John Raley [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 29 August 2002 12:28 AM
To: Struts Users Mailing List
Subject: Re: Want to Access Key/Value Pairs in Hashtable within jsp


Morycz, Felicia V wrote:

>I have done some archive searching and cannot seem to hit this topic.
>
>My business tier is going to be sending me a chunk of data that is
delimited
>into key/value pairs.  I want to parse this data and put it into a
>Hashtable.  I want to be able to access this data from a jsp.
>
>1.  Is Hashtable the correct storage object?
>
>
Hashtable might be convenient for you but JSP tag libs (especially in
Struts) are very bean-centric.

>2.  How should the Hashtable be stored on the request, wrapped inside a
>bean?
>
>

You could represent the Hashtable as a bean with this API:
dynclass.sourceforge.net

>3.  What is the syntax in the jsp to retrieve the values given a key?
>
>
<jsp:getProperty/> is the "built-in" way, although the Struts
<bean:write> and <bean:define> tags are preferred.

--
Check it out: Map -> JavaBean
http://dynclass.sourceforge.net/




--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <
mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <
mailto:[EMAIL PROTECTED]>








--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to