You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Simon MARTIN <si...@gmx.at> on 2005/03/27 18:48:24 UTC

with multiple="true" - creating an appropriate Model

Hi,

I'm using a form which is defined like this:

<form-bean name="diplomarbeitForm" 
type="org.apache.struts.validator.DynaValidatorForm">
   <form-property name="diplomarbeit" type="org.mmo.model.Diplomarbeiten"/>
</form-bean>

The part with the html:select tag in my JSP looks like this:

<html:select property="diplomarbeit.schuelerDiplomarbeiten" multiple="true" 
size="6">
   <c:forEach var="sm" items="${schuelerMatura}" varStatus="varStatus">
     <html:option value="${sm.schuelerMaturaId}">
       <c:out value="${sm.schueler.vorname}" /> <c:out 
value="${sm.schueler.nachname}" />
     </html:option>
   </c:forEach>
</html:select>

(the schuelerMatura array is put into the model manually in the Action)

Showing the page works pretty fine, put selecting on ore more of the items in 
the list and submitting
the form produces an servlet-exception regarding the 'BeanUtils.populate' method.

The getter and the setter for the schuelerDiplomarbeiten array are wrapped 
around an internal Set,
which is required as Hibernate can't map to an array in my case.

public SchuelerDiplomarbeiten[] getSchuelerDiplomarbeiten() {
		SchuelerDiplomarbeiten[] schuelerDiplomarbeiten =
				new SchuelerDiplomarbeiten[schuelerDiplomarbeitenInternal.size()];

		int i = 0;
		for (Iterator it = schuelerDiplomarbeitenInternal.iterator(); it.hasNext(); ) {
			schuelerDiplomarbeiten[i] = (SchuelerDiplomarbeiten) it.next();
			i++;
		}

		return schuelerDiplomarbeiten;
	}

public void setSchuelerDiplomarbeiten(SchuelerDiplomarbeiten[] 
schuelerDiplomarbeiten) {
		schuelerDiplomarbeitenInternal = new HashSet();

		for (int i=0; i < schuelerDiplomarbeiten.length; i++) {
			schuelerDiplomarbeitenInternal.add(schuelerDiplomarbeiten[i]);
		}
	}

So, I assume something's wrong with my setter, but I can't see any mistake.

Any suggestions?

Thanks in advance.

Kind regards,
   Simon

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