• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retrieving radio selection & checkbox selection from a DynaForm

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a DynaForm that creates a questionnaire from a template stored on the Server.

It now shows fine, but how do I retrieve the selections I have made?

The questions are in a forEach and based on the questionType I show radio button, checkboxes or a text field.

I have attempted storing them in String arrays on the DynaForm, but without luck.


The JSP file looks like this:

<html:form action="/processQuestionnaire" >
<table border="0" width="80%">

<c:forEach var="question" items="${QuestionnaireActionForm.map.questions}">
<tr><td><c ut value="${question.text}"/></td>

<c:forEach var="radio" items="${question.radios}">
<c:if test="${radio != null}">
<tr>
<td><html:radio name="question" indexed="true" property="selectedRadios" value="${radio.id}"/><c ut value="${radio.text}"/></td>
</tr>
</c:if>
</c:forEach>

<c:forEach var="box" items="${question.boxes}">
<c:if test="${box != null}">
<tr>
<td><html:checkbox name="question" indexed="true" property="selectedBoxes" value="${box.id}"/><c ut value="${box.text}"/></td>
</tr>
</c:if>
</c:forEach>

<c:forEach var="text" items="${question.texts}">
<c:if test="${text != null}">
<tr>
<td><html:text name="question" indexed="true" property="selectedTexts" value="${text.text}" maxlength="10" size="10" style="margin-top: 2px; margin-bottom: 5px; border: 1px solid #ffcc99;" /></td>
</tr>
</c:if>
</c:forEach>


</tr>
</c:forEach>
</table>
<P/>
<html:submit value="Update Comments"/>
</html:form>

The struts file looks like this:

<form-bean name="QuestionnaireActionForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="questions" type="dk.procard.eclub.web.model.Question[]"/>
<form-property name="selectedRadios" type="dk.procard.eclub.web.model.Radio[]"/>
<form-property name="selectedBoxes" type="dk.procard.eclub.web.model.Checkbox[]"/>
<form-property name="selectedTexts" type="dk.procard.eclub.web.model.Text[]"/>
</form-bean>

<action path="/setupQuestionnaire"
type="dk.procard.eclub.web.controller.GenerateQuestionnaire"
name="QuestionnaireActionForm"
scope="session"
validate="false">
<forward name="success" path="/AnswerQuestionnaire.jsp"/>
</action>

<action path="/processQuestionnaire"
type="dk.procard.eclub.web.controller.ProcessQuestionnaire"
name="QuestionnaireActionForm"
scope="session"
validate="false">
<forward name="success" path="/questionnaireUpdated.jsp"/>
</action>


The ProcessQuestionnaire file looks like this:

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

login = (LoginInformationDTO)request.getSession().getAttribute("userinfo");
DynaValidatorForm df = (DynaValidatorForm) form;
Question[] q = (Question[]) df.get("questions");


Radio[] radios = (Radio[])df.get("selectedRadios");
for (int i = 0; i < radios.length; i++) {
log.fatal("radio: " + radios[i].getQuestionId() + ", " + radios[i].getId());
}
Checkbox[] boxes = (Checkbox[])df.get("selectedBoxes");
for (int i = 0; i < boxes.length; i++) {
log.fatal("box: " + boxes[i].getQuestionId() + ", " + boxes[i].getId());
}
Text[] texts = (Text[])df.get("selectedTexts");
for (int i = 0; i < texts.length; i++) {
log.fatal("text: " + texts[i].getQuestionId() + " text: " + texts[i].getText());
}



Thanks for any help.

Mark.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It now shows fine, but how do I retrieve the selections I have made?



From where? ProcessQuestionnaire???
 
Markooo Thomasooo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to retrieve the info from the AnswerQuestionnaire.jsp into the ProcessQuestionnaire.java
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic