The html-el:checkbox No Longer Works If Preceded by html-el:form

My <html-el:checkbox worked fine. But if the ><html-el:form ....> ... </html-el:form> come before the <html-el:checkbox ... >, I got the runtime JSP error: "cannot find bean: "org.apache.struts.taglib.html.BEAN" in any scope".

The complaint points specifically to the <html-el:checkbox property="selectedUsers[${idx.index}].selected" />. The getter method for selectedUsers[0].selected can no longer be recognized.

I need help because I really do not understand why it happens this way.

.....

<%@ page import="......common.pojo.user.User" %>

......

......

<!-- Create a variable in scope called userRows from the Users object -->

<c:set var="userRows" value="${requestScope.Users}" />

<c:choose>

<html-el:form action="/admin/findUsers.do">

// many textfields and a submit button

</html-el:form>

<c:when test="${not empty userRows}">

......

......

<!-- create a"user" objectfor each element in the userRows -->

<c:forEach var="user" items="${userRows}" varStatus="idx">

<tr>

<td align="center">

<html-el:checkbox property="selectedUsers[${idx.index}].selected" />

<html-el:hidden property="selectedUsers[${idx.index}].id" value="${user.id}"/>

</td>

</tr>

......

......

</c:forEach>

<tr>

<td colspan="6" align="left">

<html-el:link action="/admin/selectUsers.do">Edit Selected Users</html-el:link>

</td>

</tr>

</table>

</c:when>

......

</c:choose>

......

......

[2240 byte] By [Natalie999a] at [2007-10-2 23:34:50]
# 1

When you only specify the "property" attribute on a struts tag, it goes looking for the property on the owning action form - ie the action form belonging to the <html:form> it is nested in.

If it is not nested within an <html:form> it won't work.

Well the solution would be to include the checkbox inside the form right?

Alternatively, use the name attribute as well as the property attribute, and it should render correctly.

Is there a reason you don't want the checkbox inside the form tags?

It won't be submitted if it is not enclosed in them.

evnafetsa at 2007-7-14 16:16:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

The checkbox does "not" belong to the form that invokes the "findUsers.do" action. I put some search criteria in that form to search for users in the database.

The checkbox "is" supposed to be outside the form and gets submitted to another action called "selectUsers.do".

Question: How do I use the name attribute as well as the property attribute for the <html-el:checkbox property="selectedUsers[${idx.index}].selected" />?

The checkbox is associated with SelectUsersForm.java:

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];

}

}

and SelectedUserField.java is like:

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;

}

}

Natalie999a at 2007-7-14 16:16:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Would anyboby help with the problem? I would really appreciate your help.
Natalie999a at 2007-7-14 16:16:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...