Solved

Struts html:select problem

Posted on 2013-01-30
2
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

730 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