Struts form nesting and iteration problems
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Adam_Seymour
Posted On:   Thursday, June 5, 2003 10:42 AM

I am currently developing a questionnaire jsp. The layout of the page is simply a list of questions with their input fields (mostly checkboxes and radio buttons) below each question. There are 3 methods on the EJB: The first (getQuestions) returns a map with questionID as its key, and the String question itself as the value. The second (getQuestionType) returns a String (either checkbox, radio, text, etc) when the questionID is passed in as the argument. (This questionType is stored in a hidden field on the jsp, and a simple java 'if/else' to do the correct HTML) The third (getOptions) return a String[] of the options for the particular questionID passed in as the argument.    More>>

I am currently developing a questionnaire jsp. The layout of the page is simply a list of questions with their input fields (mostly checkboxes and radio buttons) below each question.

There are 3 methods on the EJB:

The first (getQuestions) returns a map with questionID as its key, and the String question itself as the value.

The second (getQuestionType) returns a String (either checkbox, radio, text, etc) when the questionID is passed in as the argument.

(This questionType is stored in a hidden field on the jsp, and a simple java 'if/else' to do the correct HTML)

The third (getOptions) return a String[] of the options for the particular questionID passed in as the argument.

Unfortunately the number of questions returned by the EJB are totally variable - there is currently no set limit to questions, nor the number of options they have.



I've tried a number of combinations of logic, bean and nested tags to get the questions displayed with their relevant options, but the problem seems to be that struts requires a specific getter/setter for each individual string to be displayed on the page (be it question or question option). As the size of the map and array brought back from the ejb are undefined, I see no way of doing this.

Does anyone have a similar problem/know of a way around this?

All I can think of is to limit the number of questions returned by the ejb so I can write individual getter/setter method for each string.

   <<Less

Re: Struts form nesting and iteration problems

Posted By:   sahil_k  
Posted On:   Monday, June 9, 2003 10:33 AM

I have never done EJBs and so probably should not be speaking. However, in a regular jsp - struts application my approach would be something like this.


I will create a bean for each question. The bean will contain two properties. One for the question string and another a collection (Vector/Arraylist) ("optionsVec") of all the options. Each of these beans will be put in a Vector ("beansVec") which will then be passed to the jsp.

Within the jsp, I will first iterate the "beansVec", display the question. I will have another iterate loop inside the outer iterate to get the options.



My pseudocode therefore would be



Display the question

Display each option






Hope I made some sense.
About | Sitemap | Contact