You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jerry Jalenak <Je...@LABONE.com> on 2003/04/29 17:36:32 UTC

[repost] need help with defining nested form-bean

<still-needing-help!>

I have the following nested structure:

public class InitializeAction extends Action
{
	public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
	{
		UserSessionBean usb = new UserSessionBean();
		usb.setUserName("User Name");

		for (int i = 0; i < 3; i++)
		{
			DomainSessionBean dsb = new DomainSessionBean();
			dsb.setDomainName("Domain" + i);
			dsb.setDomainDescription("DomainDescription" + i);

			usb.addDomain(dsb);

			for (int j = 0; j < 3; j++)
			{
				ApplicationSessionBean asb = new
ApplicationSessionBean();
				asb.setApplicationName("Application" + j);
	
asb.setApplicationDescription("ApplicationDescription" + j);
				asb.setApplicationURL("ApplicationURL" + j);

				dsb.addApplication(asb);

			}
		}
		HttpSession session = request.getSession();
		session.setAttribute("UserSessionBean", usb);

		return(mapping.findForward("success"));
	}
}

What I end up with is a UserSessionBean that contains 1 or more
DomainSessionBeans; each DomainSessionBean then contains 1 or more
ApplicationSessionBeans.  The source JSP and the rendered HTML look like
this:

<%@ taglib uri="/struts-html"		prefix="html"%>
<%@ taglib uri="/struts-nested"		prefix="nested"%>
<%@ page language="java"%>
<%@ page contentType="text/html; charset=UTF-8" %>

<html:html locale="true">
	<body>
		<nested:form action="TestAction" method="POST">
			This is test page 2. and then some.<br>
				<nested:write name="UserSessionBean"
property="userName" /><br>
				<nested:iterate name="UserSessionBean"
property="domainList">
					<nested:checkbox
property="domainName" /><nested:write property="domainName" /><br>
					<nested:iterate
property="applicationList">
						<nested:checkbox
property="applicationName" /><nested:write property="applicationName" /><br>
					</nested:iterate>
				</nested:iterate>
			<nested:submit />
		</nested:form>
	</body>
</html:html>

<html lang="en">
	<body>
		<form name="TestFormBean" method="POST"
action="/membersolutions_v3/TestAction.action">
			This is test page 2. and then some.<br>
				User Name<br>
					<input type="checkbox"
name="domainList[0].domainName" value="on">Domain0<br>
						<input type="checkbox"
name="domainList[0].applicationList[0].applicationName"
value="on">Application0<br>
						<input type="checkbox"
name="domainList[0].applicationList[1].applicationName"
value="on">Application1<br>
						<input type="checkbox"
name="domainList[0].applicationList[2].applicationName"
value="on">Application2<br>
					<input type="checkbox"
name="domainList[1].domainName" value="on">Domain1<br>
						<input type="checkbox"
name="domainList[1].applicationList[0].applicationName"
value="on">Application0<br>
						<input type="checkbox"
name="domainList[1].applicationList[1].applicationName"
value="on">Application1<br>
						<input type="checkbox"
name="domainList[1].applicationList[2].applicationName"
value="on">Application2<br>
					<input type="checkbox"
name="domainList[2].domainName" value="on">Domain2<br>
						<input type="checkbox"
name="domainList[2].applicationList[0].applicationName"
value="on">Application0<br>
						<input type="checkbox"
name="domainList[2].applicationList[1].applicationName"
value="on">Application1<br>
						<input type="checkbox"
name="domainList[2].applicationList[2].applicationName"
value="on">Application2<br>
			<input type="submit" name="" value="Submit">
		</form>
	</body>
</html>

What I am struggling with is how do define in struts-config my form-bean
(TestFormBean) so that the user can 'select' the domain / applications and
struts will populate the form-bean correctly.  I've started out trying to
define domainList as a String[], but BeanUtils.populate keeps throwing an
ArrayIndexOutOfBoundsException.  How do I need to go about doing this?

Thanks in advance for your help.  


Jerry Jalenak
Team Lead, Web Publishing
LabOne, Inc.
10101 Renner Blvd.
Lenexa, KS  66219
(913) 577-1496

jerry.jalenak@labone.com

This transmission (and any information attached to it) may be confidential and is intended solely for the use of the individual or entity to which it is addressed. If you are not the intended recipient or the person responsible for delivering the transmission to the intended recipient, be advised that you have received this transmission in error and that any use, dissemination, forwarding, printing, or copying of this information is strictly prohibited. If you have received this transmission in error, please immediately notify LabOne at the following email address: securityincidentreporting@labone.com



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