Using Struts tag libs

Hi,

I am relatively new to Struts [using 1.3].

I need to create a form using Struts tag libs with 2 HTML select's [lists],

connected to 2 DB tables, say allUsers and Admins, which would allow

to select Administrators from the list of AllUsers.

So I will have 3 buttons: Add, Remove and Update.

Add - to add selected item(s) from AllUsers list to Admins list [if it is

not there already];

Remove- to delete selected item(s) from Admins list;

Update - to save changes to Admins list to the Admins DB table.

So roughly my JSP will looks something like that:

<%@ page import="java.util.Collection" %>

<html:form property="manageAdmins" action="/manageAdmins">

<table>

<tr>

<td> </td>

<td>All Users:</td>

<td> </td>

<td> </td>

<td> </td>

<td>Administrators:</td>

</tr>

<tr>

<td> </td>

<td>

<html:select size="8" property="allUsers" multiple="true"

styleId="allUsersID">

<html:options collection="AllUsersList" property="AllUsersId"

labelProperty="allUsers"/>

</html:select>

</td>

<td> </td>

<td>

<table>

<tr><img src="/images/btn_add.gif" alt="Add" name="add" border="0"

id="add" onClick="?">

</tr>

<tr><img src="/images/btn_remove.gif" alt="Remove" name="remove"

id="remove" onClick="?">

</tr>

<tr><img src="/images/btn_update.gif" alt="Update" name="update"

id="update" onClick="?">

</tr>

</table>

</td>

<td> </td>

<td>

<html:select size="8" property="admins" multiple="true"

styleId="adminsID" onchange="getAdmins();">

<html:options collection="AdminsList" property="AdminID"

labelProperty="admins"/>

</html:select>

</td>

</tr>

<tr>

</tr>

</table>

</html:form>

So how do I manipulate these <html:options collection=AdminList...> Struts

tags

in order to implement Add, Remove, Update ?In onClick="..." ?

Is it in JavaScript or in Java ?

Any other useful Struts tags for that [especially to do DB synchronization]?

Code snippets ?

Sorry for the newbie question.

Thank you in advance,

Oleg.

[2466 byte] By [olegkona] at [2007-11-27 11:18:06]
# 1

creaet Struts ActionForm class and declare all the properties (html elements) and generate getters/setters.

for select box like this:

private Collection allUsersList = null;

private String allUsers = null;

.....

......

Create Action class initially to run the jsp (.do action, create action mappings in your struts-config.xml)

If you want to pre-populate any values, you can do it here.

Then, for you add/update/delete create one more action class. (based on what you clicked have

seperate methods here.). When you click a button in the jsp, call javascript fn, and submit the form.

Here, call this action.

<html:form property="manageAdmins" action="/manageAdmins">

Using get and set you can assign and fetch the values from the jsp.

for good example, refer here:

www.ibm.com/developerworks/websphere/techjournal/0302_fung/fung.html

skp71a at 2007-7-29 14:28:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...