You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Guillermo Meyer <gm...@sib.interbanking.com.ar> on 2004/01/05 14:01:02 UTC

Filling select with options and getting description from ids: Providers

Using Struts tags, you do this for creating a select filled with options
tags:

<html:select property="idDocument">
	<html:options collection="documents" property="id"
labelProperty="descrip"/>
</html:select>


In this case, you should create a collection with beans for each
document type (Passport, Cedule, Document, SSN, etc) and set it in the
request to be collected by "options" tag.

My questions are: Are you creating and filling this collection in the
action previous the JSP? If you have this combo in multiples JSPs, Do
you "copy&paste" the collection creation in each action previous the JSP
rendering?

In my case, we created a new tag that uses a tinny framework we made for
managing these collections, called "Providers".
Providers let you define collections from diferent datasources and you
use this like this:

<html:select property="idDocument">
	<providers:options provider="DOCUMENTS" property="id"
labelProperty="descrip"/>
</html:select>

Here, DOCUMENTS is the name of the provider, defined like this:

	<provider	name="DOCUMENTS"
className="ar.com.koalas.providers.FixedProvider">
		<set-property	property="keyName"
value="key"/>
		<set-property	property="description"	value="value"/>
		<value key="1" value="Passport"/>
		<value key="2"	value="Cedule"/>
		<value key="3" value="SSN"/>
	</provider>

You can use JDBCProvider to query from a database, or RefProvider to
filter other Provider. And you could add new providers types

Another problem is having an id, get a description. If you have an id
(for instance, idDocument) you can get the description, in a bean:write
fashion:

<providers:write provider="DOCUMENTS" property="idDocument"/>

This displays Document description acording to idDocument property
value, so you don't need to query it before JSP display.
You can create providers to display, for example, boolean values in
diferent ways: (Yes/No, True/False, a checked or unchecked html:checkbox
tag, 2 different gifs images, etc).

<providers:write provider="TRUEFALSE" property="isValid"/>
<providers:write provider="YESNO" property="isValid"/>
<providers:write provider="IMAGESBOOLEAN" property="isValid"/>

IMAGESBOOLEAN could be:
	<provider	name="IMAGESBOOLEAN"
className="ar.com.koalas.providers.FixedProvider">
		<set-property	property="keyName"
value="key"/>
		<set-property	property="description"	value="value"/>
		<value key="true">
		<![CDATA[
		<img src="/images/true.gif">
		]]>
		</value>
		<value key="false">
		<![CDATA[
		<img src="/images/false.gif">
		]]>
		</value>
	</provider> 

This solution helps us a lot in filling selects, displaying ids
descriptions and increases reusability.

What do you think of these solution? Does it goes against MVC? 
We are planing to upload this tiny framework to sourceforge.net in next
week. Is there anything like this anywhere? Are we reinventing the
wheel?

Cheers.
Guillermo.


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