Solved

Struts html:select problem

Posted on 2013-01-30
2
330 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now