I display a List of objects.
Because the List can be very long, I use a pagination
tag library to display my long list 10 at a time.
This taglib is not a front-end one. The taglib makes
a trip to the back end to retrieve the next 10 records
from the database when the next pagination link is
clicked.
Each object is with a checkbox attached. and this is
the way I code it:
[code]
<html-el:checkbox property="selectedUserIds"
value="${user.userIDCode}" />
<html-el:checkbox
property="selectedUsers[${idx.index}].selected" />
[/code]
Clients may navigate page by page to mark certain
checkboxes in each page. And I have to make sure that
all marked checkboxes are kept in memory when clients
finally click on the 'Submit' button.
The way that I code my form may not be right:
[code]
.....
.....
public class SelectUsersForm extends ActionForm
{
private Map selectedUserFieldMap = new HashMap();
private String[] selectedUsers = new String[0];
private String[] selectedUserIDs;
public SelectedUserField getSelectedUsers( int
index )
{
SelectedUserField selectedUserField = (
SelectedUserField )selectedUserFieldMap.get( new
Integer( index ) );
if ( selectedUserField == null )
{
selectedUserField = new SelectedUserField();
selectedUserFieldMap.put( new Integer( index
), selectedUserField );
}
return selectedUserField;
}
// Convenience method to get a list of selected
user IDs.
public String[] getSelectedUserIDs()
{
List theUserIDList = new ArrayList();
Iterator i =
selectedUserFieldMap.values().iterator();
while( i.hasNext() )
{
SelectedUserField selectedUserField = (
SelectedUserField ) i.next();
if ( selectedUserField.isSelected() )
{
theUserIDList.add(
selectedUserField.getId() );
}
}
return ( String[] )theUserIDList.toArray( new
String[theUserIDList.size()] );
}
public void reset( ActionMapping mapping,
HttpServletRequest request)
{
selectedUsers = new String[0];
selectedUserIDs = new String[0];
}
}
[/code]
and the SelectedUserField.java is like:
[code]
package gov.cbp.ace.st.tf.web.admin.form;
import java.sql.Timestamp;
public class SelectedUserField
{
private boolean selected = false;
private Long id;
public Long getId()
{
return id;
}
public void setId( Long newValue )
{
id = newValue;
}
public boolean isSelected()
{
return selected;
}
public void setSelected( boolean newValue )
{
selected = newValue;
}
}
[/code]
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]