You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Olve Sæther Hansen <ol...@uib.no> on 2004/08/25 00:36:31 UTC

submitting map-backed action forms

Ok, trying once more, hopeing for more help this time..

I have a jsp, getting values from an action. These values represent 
questions, and alternatives for each question rendered as radio-buttons.

The radiobuttons is preset to a choice if the user has visited and 
answered this question before, but he/she is free to revise the answer. 
So far I got it to work (by hardcoding the values sent from the action 
-  just for testing).

I am using the general approach from:
http://struts.apache.org/userGuide/building_controller.html#map_action_form_classes 


My problem comes when submitting the form, I get a:

javax.servlet.ServletException: BeanUtils.populate
	at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:844)
	at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:823)
	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:243)
	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1176)
	at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:472)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:68)

[snip]

The two actions involved is defined as:
* @struts.action name="mapValueForm" path="/answerQuestionGroup"
* parameter="action" scope="request"
*
* @struts.action name="mapValueForm" path="/openQuestionGroup"
* parameter="action" scope="request"

The form is defined as:
private Map values = new HashMap();
Object getValue(String key)
{return values.getKey(); }
void setValue(String key, Object value)
{ values.put(key, value); }

The form is specified as:
<html:form action="answerQuestionGroup" method="post" 
styleId="mapValueForm" >
<c:forEach var="question" items="${requestScope.questionList}">

<h4><c:out value="${question.title}"/> </h4>
<i><c:out value="${question.question}"/></i>
<div>
   <%--    Todo: legg til innrykk--%>

<c:forEach var="alternative" items="${question.alternatives}">

<html-el:radio  value="${alternative.id}" 
property="value(${question.id})"/>
<%-- Here I am retrtieving the value from mapValueForm, and it works --%>

<c:out value="${alternative.text}" />  <br>
</c:forEach>

</div>
<div class="separator"></div>
</c:forEach>

<html:submit styleClass="button" property="action" onclick="bCancel=false">
   <bean:message key="button.answerQuestionnaire"/>
</html:submit>
</html:form>

As far as I understand, struts should use 
mapValueForm.setValue("someVal") when submitting this form. The 
generated html looks sane, in that it generates the following for a 
question with three alternatives, and one is checked (the hardcoded val 
from the action):

<input type="radio" name="value(1)" value="1" />ja  <br>
<input type="radio" name="value(1)" value="2" />nei  <br>
<input type="radio" name="value(1)" value="3" checked="checked" /> kanskje <br>
			

I have struggled with this problem for some time now, please anyone who 
can help me with a pointer to what can be wrong, or how I can do this in 
another way?

Thanks,
Olve S. Hansen

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