You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Michael Mok <mi...@madart.com.au> on 2004/07/10 15:55:57 UTC

Dynamic lookup tag lib (drop down list reverse)

Hi all

I have created a jsp tag that will look up a collection (of  
LabelValueBeans) and return the label of the value. For example we store 
position description in a code table such as
Code  Description
1        Director
2        Manager
3        Assistant Manager
4        Staff

In the User table, we store
Logon      Position
Jack         1
Jill             2
Charlie      2

In a UserList.jsp

<logic:iterate ...>
Logon : <bean:write  name="user" property="logon"/>
Position: <bean:write name="user" property="position"/>
</logic:iterate>

This will produce the following list
Logon : Jack     Position:  1
Logon : Jill         Position: 2
Logon : Charlie  Position: 2

To display the position description instead of the position number, I 
added a list of LabelValueBeans to the session (ie 
session.setAttribute("session.positionlevel"); ) and changed the JSP to 
the following.

<logic:iterate ...>
Logon : <bean:write  name="user" property="logon"/>
Position: <ma:droplist name="user" property="position" 
labelValueList="session.positionlevel"/>
</logic:iterate>

The droplist tag will produce the following with
Logon : Jack     Position:  Director
Logon : Jill         Position: Manager
Logon : Charlie  Position: Manager

I am happy to contribute this back the STRUTS tag lib or if anyone is 
interested, let me know and I will send you the code. This functionality 
consists of

ma-droplist.tld
com.ma.struts.taglib.droplisttag.java
com.ma.struts.taglib.droplisttag.class

To add the functionality to your JSP you will need to

1) Add the tld to your web.xml.
2) Add the tld to your JSP.

This tag also works with indexed beans as droplisttag.java is extended 
from writetag.java.

Regards

Michael Mok

MAD ART | Lead Technical Architect
e| michael@madart.com.au
m| 0417 968 581


This e-mail is the property of MadArt Services and/or its relevant affiliate and may contain confidential and privileged material for the sole use of the intended recipient(s). Any review, use, distribution or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive for the recipient), please contact the sender and delete all copies of the message. This e-mail (and any attachments hereto) are not intended to be an offer (or an acceptance) and do not create or evidence a binding and enforceable contract between MadArt Services (or any of its affiliates) and the intended recipient or any other party, and may not be relied on by anyone as the basis of a contract by estoppel or otherwise. Thank you.



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