You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Struts Newsgroup (@Basebeans.com)" <st...@basebeans.com> on 2002/05/24 12:10:02 UTC
Getting an object from a Hashtable
Subject: Getting an object from a Hashtable
From: "Scott Curtis" <sc...@smart421.com>
===
Hi,
I want to be able to check the value of a property held within a hashtable
using a Struts tag such as <logic:equal />. For example I have a Hashtable
which contains a collection of JavaBeans. In the JSP I know the key for each
object in the Hashtable. I want to be able to select an object from the
Hashtable according to a specified key and then compare a property value in
the returned object using it's getter.
Something along these lines:
MyBean contains a Hashtable called myHash full of JavaBean conformant
objects. MyBean has a getter to return the Hashtable getMyHash(). Each of
the objects in the Hashtable is of type AnotherBean and they all have
getters and setters. I want to get an object from the Hashtable using the
key "obj1". The bean returned using "obj1" has a 'valid' property with a
getter isValid().
This is what I want to do but it doesn't work obviously because Hashtable
isn't a bean that can be queried from property getters and setters:
<logic:equal name="MyBean" property="myHash.obj1.valid" value="false">
Do something here.
</logic:equal>
Is there another tag I can use to first get the AnotherBean from myHash in
order for it to be used in the tag above? So basically me question is really
simply how can I get an object from a Hashtable using Struts tags or any
other tags out there? I don't want to iterate the Hashtable by the way.
Thanks, if anyone understands that and can help. :-)
- scott
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Getting an object from a Hashtable
Posted by Ted Husted <hu...@apache.org>.
Under Struts 1.1b, you could probably use the same approach that is used
to store ActionForm properties in a map.
private Map values = null;
public void setValues(Map values) {
this.values = values;
}
public Map getValues() {
return this.values;
}
public void setValue(String key, Object value) {
getValues().put(key,value);
}
public Object getValue(String key) {
return getValues().get(key);
}
> <logic:equal name="myBean" property="value(valid)" value="false">
> Do something here.
> </logic:equal>
"Struts Newsgroup (@Basebeans.com)" wrote:
>
> Subject: Getting an object from a Hashtable
> From: "Scott Curtis" <sc...@smart421.com>
> ===
> Hi,
>
> I want to be able to check the value of a property held within a hashtable
> using a Struts tag such as <logic:equal />. For example I have a Hashtable
> which contains a collection of JavaBeans. In the JSP I know the key for each
> object in the Hashtable. I want to be able to select an object from the
> Hashtable according to a specified key and then compare a property value in
> the returned object using it's getter.
>
> Something along these lines:
>
> MyBean contains a Hashtable called myHash full of JavaBean conformant
> objects. MyBean has a getter to return the Hashtable getMyHash(). Each of
> the objects in the Hashtable is of type AnotherBean and they all have
> getters and setters. I want to get an object from the Hashtable using the
> key "obj1". The bean returned using "obj1" has a 'valid' property with a
> getter isValid().
>
> This is what I want to do but it doesn't work obviously because Hashtable
> isn't a bean that can be queried from property getters and setters:
>
> <logic:equal name="MyBean" property="myHash.obj1.valid" value="false">
> Do something here.
> </logic:equal>
>
> Is there another tag I can use to first get the AnotherBean from myHash in
> order for it to be used in the tag above? So basically me question is really
> simply how can I get an object from a Hashtable using Struts tags or any
> other tags out there? I don't want to iterate the Hashtable by the way.
>
> Thanks, if anyone understands that and can help. :-)
> - scott
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
-- Ted Husted, Husted dot Com, Fairport NY US
-- Developing Java Web Applications with Struts
-- Tel: +1 585 737-3463
-- Web: http://husted.com/about/services
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>