You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Johnson <ch...@gmail.com> on 2005/03/07 17:33:24 UTC

Displaying a HashMap as a

Posted by David Johnson <ch...@gmail.com>.
Thanks Wendy!

My problem was the following. In order to get this <select> to
display, I of course needed to set up all the crap asociated with
doing such a thing... This is a list partially to get it into the
archives so I can search on it later.

So, I did the following
1. Loaded an ArrayList of CodeBean objects onto the application
context at application startup (inder the name "codes". (a CodeBean
has a codeID and codeName attribure with getters and setters)

I actualyl rethought the way I was saving data in the application
context, and an ArrayList of code beans seemed nicer than a hashMap..
so I changed it.

2. create the HTML for it all to work

<html:form action="codeAction.do" method="post">
    <html:select name="codeForm" property="codeName">
          <html:options collection="codes" property="codeID"
labelProperty="codeName"/>
    </html:select>
</html:form>

WELL, in order for th above to work, you need a form-bean entry, and
an action mapping, and for that to work, you need a Form Bean and an
Action Class

>From Struts-Config.xml....
<form-beans>
    <form-bean name="codeForm" type="com.company.struts.form.CodeForm"/>
</form-beans>

...and...

<action path="/CodeAction"
      name="sicForm"
      scope="request"
      input="page.input"
      type="com.company.struts.CodeAction">		
        <forward name="success" path="page.result" redirect="true" /> 	
</action>

My apologies, but I thought it might help reinforce it in my mind if I
wrote it all down.

Thanks for the help Wendy!

On Mon, 07 Mar 2005 09:48:35 -0700, Wendy Smoak <ja...@wendysmoak.com> wrote:
> From: "David Johnson" <ch...@gmail.com>
> > I simply want to create a select box containing all the items in my
> > HashMap (displaying the codeName but passing the codeID)
> > What's the easiest way to do this? Can I do this wil just a vanilla
> > HashMap? The examples are slightly confusing.
> 
> I agree... I can never figure out what combination of tag attributes will do
> what I want just from reading the docs.  Here's an example from a working
> webapp:
> 
> <html-el:select property="type">
>            <html-el:options collection="contactTypes"
>                                        property="key"
>                                        labelProperty="value"/>
> </html-el:select>
> 
> --
> Wendy Smoak
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


-- 
-Dave
ChaChaNY@Gmail.com

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


Re: Displaying a HashMap as a

Posted by Jeff Beal <jb...@gmail.com>.
Even if the results coming out of the database are sorted, throwing
them into a non-sorted Collection, like a basic HashMap, will un-sort
them.  If you use a List, you just preserve the database sort order. 
If you use a TreeMap, you can get the same sort order, but the TreeMap
object will go through the work of sorting them all over again.


On Tue, 8 Mar 2005 09:17:49 -0500, David Johnson <ch...@gmail.com> wrote:
> my thought was just to let the DB do the work on the sorting. Is that bad?
> 
> 
> On Mon, 7 Mar 2005 21:29:08 -0700, Wendy Smoak <ja...@wendysmoak.com> wrote:
> > From: "James Mitchell" <jm...@apache.org>
> > > I wouldn't use a Map, I would go with a List.  Primarily for ordering.
> >
> > I use java.util.TreeMap-- automatic alphabetical order for my lists of
> > (String) codes and descriptions.
> >
> > --
> > Wendy Smoak
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 
> --
> -Dave
> ChaChaNY@Gmail.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


-- 
Jeff Beal
Webmedx, Inc.
Pittsburgh, PA USA

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


Re: Displaying a HashMap as a

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "James Mitchell" <jm...@apache.org>
> I wouldn't use a Map, I would go with a List.  Primarily for ordering.

I use java.util.TreeMap-- automatic alphabetical order for my lists of 
(String) codes and descriptions.

-- 
Wendy Smoak 



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


Re: Displaying a HashMap as a