Re: Getting an object from a Hashtable

2002-05-27 Thread Ted Husted

The Struts 1.0 ActionServlet and custom tags were written to rely on the
pre-Commons BeanUtils, which did not support maps. I don't believe
anything along these lines is going to be available to a Struts 1.0
application. You'd have to replace the ActionServlet too, at which point
it really wouldn't be a Struts 1.0 application anymore, and you could
just as well go up to 1.1b. 

In 1.1, when bare Maps are being used in an application, an Action can
be used to wrap it in a bean. It does not need to be a DynaBean, it just
needs to have a public accessor and mutator, per the JavaBean
conventions. The Commons BeanUtil's package will handle the rest. 

-- 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


Adolfo Miguelez wrote:
 
 Hhhmmm,
 
 yes, in that way, we can get a value in a map which in turn is wrapped as a
 bean property, but what about if my bean is a map itself.
 
 (NOTE: We know about the different concept among a JavaBean spec class and a
 java.util.Map).
 
 Is there any way for that situation?
 
 I have been inspecting BeanUtils package from Jakarta Commons, and it seens
 to inspect any kind of property within a bean, mapped, indexed, simple,
 nested, composed, but I can not find a way to inspect a map directly.
 
 The reason to use a map rather than a bean is that, in that way, we can have
 a general value object and not a specific bean for each JSP.
 
 AFAIK we can solve the problem by replacing the map by a dynabean as value
 object, but we have some application already working in production made with
 Struts 1.0, when not dynabeans were available, and we needed to work out our
 own tags to patch this situation.
 
 I have suspicions that experts rejects using maps as value objects. However
 I think that more for a traditional reason that for another one. I have seen
 at EJB design patterns by Floyd Marinescu, page 59, a pattern using hashmaps
 as data transfer objects. Could this transfer by understood as transfer
 to JSP? I would grateful any light.
 
 Any solution to this issue? Thanks in advance.
 
 Adolfo.
 
 From: Ted Husted [EMAIL PROTECTED]
 Reply-To: [EMAIL PROTECTED]
 To: Struts Users Mailing List [EMAIL PROTECTED]
 Subject: Re: Getting an object from a Hashtable
 Date: Fri, 24 May 2002 08:45:51 -0400
 
 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 [EMAIL PROTECTED]
===
   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:
 mailto:[EMAIL PROTECTED]
   For additional commands, e-mail:
 mailto:[EMAIL PROTECTED]
 
 -- 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:
 mailto:[EMAIL PROTECTED

Re: Getting an object from a Hashtable

2002-05-25 Thread Adolfo Miguelez


Hhhmmm,

yes, in that way, we can get a value in a map which in turn is wrapped as a 
bean property, but what about if my bean is a map itself.

(NOTE: We know about the different concept among a JavaBean spec class and a 
java.util.Map).

Is there any way for that situation?

I have been inspecting BeanUtils package from Jakarta Commons, and it seens 
to inspect any kind of property within a bean, mapped, indexed, simple, 
nested, composed, but I can not find a way to inspect a map directly.

The reason to use a map rather than a bean is that, in that way, we can have 
a general value object and not a specific bean for each JSP.

AFAIK we can solve the problem by replacing the map by a dynabean as value 
object, but we have some application already working in production made with 
Struts 1.0, when not dynabeans were available, and we needed to work out our 
own tags to patch this situation.

I have suspicions that experts rejects using maps as value objects. However 
I think that more for a traditional reason that for another one. I have seen 
at EJB design patterns by Floyd Marinescu, page 59, a pattern using hashmaps 
as data transfer objects. Could this transfer by understood as transfer 
to JSP? I would grateful any light.

Any solution to this issue? Thanks in advance.

Adolfo.

From: Ted Husted [EMAIL PROTECTED]
Reply-To: [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: Re: Getting an object from a Hashtable
Date: Fri, 24 May 2002 08:45:51 -0400

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 [EMAIL PROTECTED]
   ===
  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:   
mailto:[EMAIL PROTECTED]
  For additional commands, e-mail: 
mailto:[EMAIL PROTECTED]

-- 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:   
mailto:[EMAIL PROTECTED]
For additional commands, e-mail: 
mailto:[EMAIL PROTECTED]



_
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.


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




Getting an object from a Hashtable

2002-05-24 Thread @Basebeans.com

Subject: Getting an object from a Hashtable
From: Scott Curtis [EMAIL PROTECTED]
 ===
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:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: Getting an object from a Hashtable

2002-05-24 Thread Ted Husted

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 [EMAIL PROTECTED]
  ===
 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:   mailto:[EMAIL PROTECTED]
 For additional commands, e-mail: mailto:[EMAIL PROTECTED]

-- 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:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]