Solved

Struts html:select problem

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 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