[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Struts html:select problem

Posted on 2013-01-30
2
Medium Priority
?
351 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 1500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

650 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