You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dan Allen <da...@mojavelinux.com> on 2003/03/13 05:25:07 UTC

state and country taglib

I have seen some taglibs around the web for making a state and
country list, but they all seem to make the <select> element.  I
would rather use the struts <html:select> tag but have the custom
taglib just make the options part, so as to replace <html:option>
tag with <html:stateOption> and <html:countryOption>

Does anyone know of a taglib that has this?  It seems to me that the
list should be part of the view and not something that the model has
to prepare, so it would be perfect as a taglib out of convenience
for the jsp developer.

Unfortunately I don't really have experience making taglibs.  Anyone
have any ideas.

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Windows: where do you want your data to disappear to today?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

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


Re: state and country taglib

Posted by Mark <st...@webpit.com>.
I have a table in my database that stores a bunch of redundant data which I call "Pick lists"  each of the lists have a list name, item name, and item value

I have pick lists for Countries and States and use the country code/state code as the item name, and and their display as the item value.

I then load this list into a cache Hashtable and Vectors at startup in my startup servlet.  The hashtable has keys for list name, and their stored objects are the vectors.
The vectors actually store series of LabelValueBeans which is in the struts util package.

>From all this, I am going to tell you that you do not need a custom taglib for this.  You could store the lists in text files, load them at startup time.

In your JSP page you can refer to these such as:


<html:select property="ccstate" size="1">
	<html:options collection="states" property="value" labelProperty="label"/>
</html:select>

However, I do infact use a custom tag to set these in my request environment on the page rather than inside the action.

<eos:formcollections use="states"/>
<eos:formcollections use="countries"/>

those two lines do what im showing you below essentially

So inside your action class, before you forward to your JSP, you need to setup this "collection" of ValueLableBeans and store it in the request

Vector states=new Vector();
states.add(new LabelValueBean("US","United States"));

request.setAttribute("states",states);

// do your forward to your jsp page

you should see "United States" as a drop down item

like i said, prepopulate the list in some class that gets executed at startup time.  Its much more efficient after that.

Regards,
Mark Williamson

private email me for more help or consulting
struts@webpit.com


you wrote:

I have seen some taglibs around the web for making a state and
country list, but they all seem to make the <select> element.  I
would rather use the struts <html:select> tag but have the custom
taglib just make the options part, so as to replace <html:option>
tag with <html:stateOption> and <html:countryOption>

Does anyone know of a taglib that has this?  It seems to me that the
list should be part of the view and not something that the model has
to prepare, so it would be perfect as a taglib out of convenience
for the jsp developer.

Unfortunately I don't really have experience making taglibs.  Anyone
have any ideas.

Dan





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