This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Retrieving radio selection & checkbox selection from a DynaForm

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
I need to retrieve the info from the AnswerQuestionnaire.jsp into the ProcessQuestionnaire.java
 
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!