Solved

Struts html:select problem

Posted on 2013-01-30
2
336 Views
Last Modified: 2013-11-19
I'm stuck and could use a little guidance.

I'm trying to add a survey page to an existing site.  I'm attempting to drive the entire page from the database.  I have tables for questions and for valid choices (all questions are multiple choice and the choices will be presented in drop-downs next to the associated questions).

I have DTOs for the tables.  In addition, I've defined a QuestionAndAnswerBean that contains the following:

questionDTO
validChoiceList (an ArrayList of ValidChoiceDTOs)
selectedAnswer (an int)

The QuestionDTO exposes, among other things, a propererty called question which contains the question text.

The ValidChoiceDTO exposes, among other things,  properties validValueText and validValueID.

So there will be one QuestionAndAnswerBean for each question on the page that contains one question and a list of the choice DTOs ; I load these beans into an ArrayList and expose this List in the FormBean.

On the page, I have the following:

<h1>Customer Survey</h1>
<table>
	<logic:iterate name="surveyForm" property="qsAndAs" id="surveyQuestions" indexId="qaIdx">
		<tr>
			<td>
				<bean:write name="surveyQuestions" property="questionDTO.question" ignore="true"/>
			</td>
			<td>
				<html:select name="surveyQuestions" property="selectedAnswer">
					<html:options name="surveyQuestions" collection="validChoiceList" labelProperty="validValueText" property="validValueID" />
				</html:select>
			</td>
		</tr>
	</logic:iterate>
</table>

Open in new window


If I get rid of the table row with the drop-downs, the page renders and all the questions are there.  If I include that table row, the page does not render.  Furthermore, the Tomcat logs contain multiple error messages to the effect of:


Cannot find bean under name validValueID

Obviously I am misunderstanding something here, but nothing I've tried has worked.  I've logged the data in the objects in the Action just before I expose it to the form bean; it's populated correctly.

Any help would be very much appreciated.
0
Comment
Question by:toolsmythe
2 Comments
 
LVL 20

Accepted Solution

by:
Sathish David  Kumar N earned 500 total points
ID: 38834629
<html:select property="selectedValue" >   
   <html:optionsCollection property="myList" label="propertyUsedForLabel" value="propertyUsedForValue" />   
</html:select>

Open in new window


The above assumes that myList is a list of JavaBeans, each having a propertyUsedForLabel and a propertyUsedForValue property.
0
 

Author Closing Comment

by:toolsmythe
ID: 38838824
Your answer was not 100% correct, but it did drag me across the solution.

The correct solution was:

<logic:iterate name="surveyForm" id="surveyQuestion" property="qsAndAs">
      <tr>
            <td style="text-align: right;">
                  <bean:write name="surveyQuestion" property="questionDTO.question" ignore="true"/>

            </td>
            <td width="500px">
                  <html:select name="surveyQuestion" property="selectedAnswer" indexed="true">
                        <html:optionsCollection name="surveyQuestion" property="validChoiceList" label="validValueText" value="validValueID" />
                  </html:select>
            </td>
      </tr>
</logic:iterate>

The "name" attribute was needed in the select because I was working from a bean (created in the logic:iterate tag).

Your answer would also have been better had it used the names from my example code.

None the less, you got me to the solution, for which I am most grateful.  Thank you!!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question