You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Richard Raquepo <rr...@primeorion.com> on 2003/07/14 05:37:26 UTC

getting hash map values

Hi.

Assuming i have this king of bean:

public class MyJavaBean implements Serializable{
 public HashMap values = new HashMap();
  
 public String get(String name){
  String value = (String) values.get(name);
        if (value == null) {
            throw new NullPointerException
                    ("No mapped value for '" + name);
            }
        return value;
 }
 
 public void set(String name,String value){
  if(name == null){
            throw new NullPointerException
                    ("No name given");  
  }
  if(value == null){
   value="";
  }
  values.put(name,value);
 }
}

--->
during my action for example i did:
MyJavaBean obj = new MyJavaBean();
obj.set("test","Hope this work");
HttpSession session = request.getSession()
session.setAttribute("obj",obj);

now, my question is how will i be able to get the value i set
for test? is that possible?

is there other way i can get to the hashmap values directly from struts?

thanks a lot...


Re: getting hash map values

Posted by Rick Reumann <r...@reumann.net>.
On Mon, 2003-07-14 at 08:23, Kris Schneider wrote:
> The way the class is defined, I don't think either JSTL or Struts tags will be
> of much use. There really aren't any properties exposed.  

True, I forgot that there wasn't a getMapName() method listed. If he
included that the tags should work.

-- 
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: getting hash map values

Posted by Kris Schneider <kr...@dotech.com>.
The way the class is defined, I don't think either JSTL or Struts tags will be
of much use. There really aren't any properties exposed. Take a look at:

http://jakarta.apache.org/struts/faqs/indexedprops.html

Specifically the section titled "Mapped Properties".

Quoting Rick Reumann <r...@reumann.net>:

> On Mon, Jul 14,'03 (11:37 AM GMT+0800), Richard wrote: 
>  
> > 
> > now, my question is how will i be able to get the value i set
> > for test? is that possible?
> > 
> > is there other way i can get to the hashmap values directly from
> > struts?
> 
> You should be able to do it with  
> beanName.nameOfMapInBean.value.nameOfKey
> 
> ie.. <c:out value="${yourBean.mapName.value.nameOfKey}"/>
> or i think with html-bean...something like...
> <bean:write property="yourBean.mapName.value.nameOfKey"/>
> 
> 
> 
> 
> 
> -- 
> Rick

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: getting hash map values

Posted by Rick Reumann <r...@reumann.net>.
On Mon, Jul 14,'03 (11:37 AM GMT+0800), Richard wrote: 
 
> 
> now, my question is how will i be able to get the value i set
> for test? is that possible?
> 
> is there other way i can get to the hashmap values directly from
> struts?

You should be able to do it with  
beanName.nameOfMapInBean.value.nameOfKey

ie.. <c:out value="${yourBean.mapName.value.nameOfKey}"/>
or i think with html-bean...something like...
<bean:write property="yourBean.mapName.value.nameOfKey"/>





-- 
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org