You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "mreisz@4sxs.de" <mr...@4sxs.de> on 2011/01/17 11:59:44 UTC

Dynamic dropDown List

Hello,

This is my first request in this mailing list, I hope I am doing it right !

I am currently developing a Portlet for Liferay using Struts 2, it is working good and I am often surprised with all the possibilities from Struts2.
Unfortunately I have a blocker !
I would like to design a form with a survey thanks to dropDown List and would like to get all the content from a database.
In the database, there are a table question (questionId, questionName) and a table answer (answerId, answerName, questionId) and I would like to generate all the dropdown from these table...

While (question)
{
	While {answer from this question)
	{
}


I tried many solutions, but I didn't achieved it!

Thank you for your help,
Mat

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


AW: Dynamic dropDown List

Posted by "mreisz@4sxs.de" <mr...@4sxs.de>.
Hello,

I tried with a map, a set... and for the quest.questionId with [], $, #...
But nothing is working.
I think it is not possible to do this!?

My requirement:
A form with 4 pages and it is possible to navigate through the 4 pages without loose field data. Example, a user fill the page 1 and 2, than goes to page 3 and begins to fill the fields. He remember that he did a mistake on the page 2, go back (all the field are recovered with his answer), correct it and goes again to page 3: here the field he answered before have to be recovered too.
All is working well with the <s:textfield> tag, the <s:select> , <s:checkbox>.... but the page 3 with dynamic dropDown List is not working:

<s:iterator value="questions" id="quest">
	<s:property value="questionName"/>
	<s:select name=" answers[quest.questionId]" list="answer" listKey="answerId" listValue="answerName" headerKey="0" headerValue="Bitte wählen"/>
</s:iterator>

Somebody know if it is possible to do that??

Thanks and regards,
Matthieu


-----Ursprüngliche Nachricht-----
Von: Dave Newton [mailto:davelnewton@gmail.com] 
Gesendet: Donnerstag, 20. Januar 2011 19:39
An: Struts Users Mailing List
Betreff: Re: Dynamic dropDown List

On Thu, Jan 20, 2011 at 12:10 PM, mreisz@4sxs.de wrote:

> And in my bean I have the variable " private String[] answers;" with 
> getter and setters...
>

You'd probably want a map, no?


> But it is not working.... and the variable " quest.questionId" is not 
> replaced by the value.
>

Try with a # maybe.

Dave


From: Reisz Matthieu

Thank you for your answer. Do you mean something like this:

<s:iterator value="questions" id="quest">
	<s:property value="questionId"/><br/>
	<s:property value="questionName"/><br/>
	<s:select name="answers[quest.questionId]" list="answers"/><br/><br/>
</s:iterator>

And in my bean I have the variable " private String[] answers;" with getter and setters...

But it is not working.... and the variable " quest.questionId" is not replaced by the value.

Other ideas?

Thanks and regards,
Mat

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Dynamic dropDown List

Posted by Dave Newton <da...@gmail.com>.
On Thu, Jan 20, 2011 at 12:10 PM, mreisz@4sxs.de wrote:

> And in my bean I have the variable " private String[] answers;" with getter
> and setters...
>

You'd probably want a map, no?


> But it is not working.... and the variable " quest.questionId" is not
> replaced by the value.
>

Try with a # maybe.

Dave

AW: Dynamic dropDown List

Posted by "mreisz@4sxs.de" <mr...@4sxs.de>.
Thank you for your answer. Do you mean something like this:

<s:iterator value="questions" id="quest">
	<s:property value="questionId"/><br/>
	<s:property value="questionName"/><br/>
	<s:select name="answers[quest.questionId]" list="answers"/><br/><br/>
</s:iterator>

And in my bean I have the variable " private String[] answers;" with getter and setters...

But it is not working.... and the variable " quest.questionId" is not replaced by the value.

Other ideas?

Thanks and regards,
Mat


-----Ursprüngliche Nachricht-----
Von: Dave Newton [mailto:davelnewton@gmail.com] 
Gesendet: Donnerstag, 20. Januar 2011 17:49
An: Struts Users Mailing List
Betreff: Re: Dynamic dropDown List

On Thu, Jan 20, 2011 at 11:08 AM, mreisz@4sxs.de wrote:

>        <s:select key="??????????????" list="answers"/><br/><br/>
>

<s:select name="answers[question.id]" .../>?

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Dynamic dropDown List

Posted by Dave Newton <da...@gmail.com>.
On Thu, Jan 20, 2011 at 11:08 AM, mreisz@4sxs.de wrote:

>        <s:select key="??????????????" list="answers"/><br/><br/>
>

<s:select name="answers[question.id]" .../>?

Dave

AW: Dynamic dropDown List

Posted by "mreisz@4sxs.de" <mr...@4sxs.de>.
Hello,

I used the normal <select> and <option> tag and built the form by hand. But on this way, I lost all the save mechanisms from struts (if the page is reloaded all the dropdown value are lost).
I didn't find a working solution...

So I tried again with the struts tag, and I did:

<s:iterator value="questions">
	<s:property value="questionId"/><br/>
	<s:property value="questionName"/><br/>
	<s:select key="??????????????" list="answers"/><br/><br/>
</s:iterator>

- I iterate on the list "questions" (return by the function: List<QuestionObject> getQuestions() in the action class) with the iterator.
- I display the id and the questionName
- Then I would like to generate for each question a drop down list with the answers (return by the function: List<String> getAnswers() in the action class)

The form is properly generated, all the questions with dropdown are displayed...
But how can I save all the values of the dropdowns in my bean? 

I thought maybe with a list or a table attribute in the bean, with getter and setter...

Any Idea?

Thanks and regards,
Matthieu


-----Ursprüngliche Nachricht-----
Von: Chris Pratt [mailto:thechrispratt@gmail.com] 
Gesendet: Dienstag, 18. Januar 2011 17:18
An: Struts Users Mailing List
Betreff: Re: Dynamic dropDown List

Unfortunately the <s:select> tag doesn't work like the <select> HTML element.  If that's what you are trying to do you could either set up the list to be displayed in the action and reference it in the <s:select> "list"
attribute, or you could just use <select> and <option> and build it yourself.
  (*Chris*)

On Tue, Jan 18, 2011 at 12:37 AM, mreisz@4sxs.de <mr...@4sxs.de> wrote:

> Hi Chris,
>
> Thank you for your reply, I had already try with the iterator but I 
> had two
> problem:
>        - I would like to put the <:property value="name"> in a 
> dropdown List (<s:select>)
>        - the answerList from the second iterator, depends from the 
> current item from the first list
>
> Something like:
>
> <s:iterator value="questionList" status="qStatus">
>         <s:select label="<s:property value='description' />"
>                <s:iterator value="answerList(<s:property 
> value=questionId/>)" status="aStatus">
>                        <option value="<s:property 
> value='AnswerDescription'/>" name="<s:property value='answerId'/>" />
>             </s:iterator>
> </s:iterator>
>
> Thank you for your help,
> Mat
>
> -----Ursprüngliche Nachricht-----
> Von: Chris Pratt [mailto:thechrispratt@gmail.com]
> Gesendet: Montag, 17. Januar 2011 19:22
> An: Struts Users Mailing List
> Betreff: Re: Dynamic dropDown List
>
> The Struts documentation can be pretty helpful here.  Here's an 
> excerpt from http://struts.apache.org/2.1.8.1/docs/iterator.html (I 
> changed the variable names to match yours):
>
>  <s:iterator value="questionList" status="qStatus">
>     <tr class="<s:if test="#qStatus.odd == true 
> ">odd</s:if><s:else>even</s:else>">
>         <td><s:property value="name"/></td>
>         <td><s:property value="description"/></td>
>         <td>
>             <s:iterator value="answerList" status="aStatus">
>                 <s:property value="description"/><s:if 
> test="!#aStatus.last">,</s:if>
>             </s:iterator>
>         </td>
>     </tr>
>  </s:iterator>
>
> If you need to access the current question while inside the answer 
> loop, look at the var attribute.
>  (*Chris*)
>
> On Mon, Jan 17, 2011 at 2:59 AM, mreisz@4sxs.de <mr...@4sxs.de> wrote:
>
> > Hello,
> >
> > This is my first request in this mailing list, I hope I am doing it 
> > right
> !
> >
> > I am currently developing a Portlet for Liferay using Struts 2, it 
> > is working good and I am often surprised with all the possibilities 
> > from Struts2.
> > Unfortunately I have a blocker !
> > I would like to design a form with a survey thanks to dropDown List 
> > and would like to get all the content from a database.
> > In the database, there are a table question (questionId, 
> > questionName) and a table answer (answerId, answerName, questionId) 
> > and I would like to generate all the dropdown from these table...
> >
> > While (question)
> > {
> >        While {answer from this question)
> >        {
> > }
> >
> >
> > I tried many solutions, but I didn't achieved it!
> >
> > Thank you for your help,
> > Mat
> >
> > --------------------------------------------------------------------
> > - To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Dynamic dropDown List

Posted by Chris Pratt <th...@gmail.com>.
Unfortunately the <s:select> tag doesn't work like the <select> HTML
element.  If that's what you are trying to do you could either set up the
list to be displayed in the action and reference it in the <s:select> "list"
attribute, or you could just use <select> and <option> and build it
yourself.
  (*Chris*)

On Tue, Jan 18, 2011 at 12:37 AM, mreisz@4sxs.de <mr...@4sxs.de> wrote:

> Hi Chris,
>
> Thank you for your reply, I had already try with the iterator but I had two
> problem:
>        - I would like to put the <:property value="name"> in a dropdown
> List (<s:select>)
>        - the answerList from the second iterator, depends from the current
> item from the first list
>
> Something like:
>
> <s:iterator value="questionList" status="qStatus">
>         <s:select label="<s:property value='description' />"
>                <s:iterator value="answerList(<s:property
> value=questionId/>)" status="aStatus">
>                        <option value="<s:property
> value='AnswerDescription'/>" name="<s:property value='answerId'/>" />
>             </s:iterator>
> </s:iterator>
>
> Thank you for your help,
> Mat
>
> -----Ursprüngliche Nachricht-----
> Von: Chris Pratt [mailto:thechrispratt@gmail.com]
> Gesendet: Montag, 17. Januar 2011 19:22
> An: Struts Users Mailing List
> Betreff: Re: Dynamic dropDown List
>
> The Struts documentation can be pretty helpful here.  Here's an excerpt
> from http://struts.apache.org/2.1.8.1/docs/iterator.html (I changed the
> variable names to match yours):
>
>  <s:iterator value="questionList" status="qStatus">
>     <tr class="<s:if test="#qStatus.odd == true
> ">odd</s:if><s:else>even</s:else>">
>         <td><s:property value="name"/></td>
>         <td><s:property value="description"/></td>
>         <td>
>             <s:iterator value="answerList" status="aStatus">
>                 <s:property value="description"/><s:if
> test="!#aStatus.last">,</s:if>
>             </s:iterator>
>         </td>
>     </tr>
>  </s:iterator>
>
> If you need to access the current question while inside the answer loop,
> look at the var attribute.
>  (*Chris*)
>
> On Mon, Jan 17, 2011 at 2:59 AM, mreisz@4sxs.de <mr...@4sxs.de> wrote:
>
> > Hello,
> >
> > This is my first request in this mailing list, I hope I am doing it right
> !
> >
> > I am currently developing a Portlet for Liferay using Struts 2, it is
> > working good and I am often surprised with all the possibilities from
> > Struts2.
> > Unfortunately I have a blocker !
> > I would like to design a form with a survey thanks to dropDown List
> > and would like to get all the content from a database.
> > In the database, there are a table question (questionId, questionName)
> > and a table answer (answerId, answerName, questionId) and I would like
> > to generate all the dropdown from these table...
> >
> > While (question)
> > {
> >        While {answer from this question)
> >        {
> > }
> >
> >
> > I tried many solutions, but I didn't achieved it!
> >
> > Thank you for your help,
> > Mat
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

AW: Dynamic dropDown List

Posted by "mreisz@4sxs.de" <mr...@4sxs.de>.
Hi Chris,

Thank you for your reply, I had already try with the iterator but I had two problem:
	- I would like to put the <:property value="name"> in a dropdown List (<s:select>)
	- the answerList from the second iterator, depends from the current item from the first list

Something like:

<s:iterator value="questionList" status="qStatus">
     	<s:select label="<s:property value='description' />"
                <s:iterator value="answerList(<s:property value=questionId/>)" status="aStatus">
                	<option value="<s:property value='AnswerDescription'/>" name="<s:property value='answerId'/>" />
             </s:iterator>
</s:iterator>

Thank you for your help,
Mat

-----Ursprüngliche Nachricht-----
Von: Chris Pratt [mailto:thechrispratt@gmail.com] 
Gesendet: Montag, 17. Januar 2011 19:22
An: Struts Users Mailing List
Betreff: Re: Dynamic dropDown List

The Struts documentation can be pretty helpful here.  Here's an excerpt from http://struts.apache.org/2.1.8.1/docs/iterator.html (I changed the variable names to match yours):

 <s:iterator value="questionList" status="qStatus">
     <tr class="<s:if test="#qStatus.odd == true ">odd</s:if><s:else>even</s:else>">
         <td><s:property value="name"/></td>
         <td><s:property value="description"/></td>
         <td>
             <s:iterator value="answerList" status="aStatus">
                 <s:property value="description"/><s:if test="!#aStatus.last">,</s:if>
             </s:iterator>
         </td>
     </tr>
 </s:iterator>

If you need to access the current question while inside the answer loop, look at the var attribute.
  (*Chris*)

On Mon, Jan 17, 2011 at 2:59 AM, mreisz@4sxs.de <mr...@4sxs.de> wrote:

> Hello,
>
> This is my first request in this mailing list, I hope I am doing it right !
>
> I am currently developing a Portlet for Liferay using Struts 2, it is 
> working good and I am often surprised with all the possibilities from 
> Struts2.
> Unfortunately I have a blocker !
> I would like to design a form with a survey thanks to dropDown List 
> and would like to get all the content from a database.
> In the database, there are a table question (questionId, questionName) 
> and a table answer (answerId, answerName, questionId) and I would like 
> to generate all the dropdown from these table...
>
> While (question)
> {
>        While {answer from this question)
>        {
> }
>
>
> I tried many solutions, but I didn't achieved it!
>
> Thank you for your help,
> Mat
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Dynamic dropDown List

Posted by Chris Pratt <th...@gmail.com>.
The Struts documentation can be pretty helpful here.  Here's an excerpt from
http://struts.apache.org/2.1.8.1/docs/iterator.html (I changed the variable
names to match yours):

 <s:iterator value="questionList" status="qStatus">
     <tr class="<s:if test="#qStatus.odd == true
">odd</s:if><s:else>even</s:else>">
         <td><s:property value="name"/></td>
         <td><s:property value="description"/></td>
         <td>
             <s:iterator value="answerList" status="aStatus">
                 <s:property value="description"/><s:if
test="!#aStatus.last">,</s:if>
             </s:iterator>
         </td>
     </tr>
 </s:iterator>

If you need to access the current question while inside the answer loop,
look at the var attribute.
  (*Chris*)

On Mon, Jan 17, 2011 at 2:59 AM, mreisz@4sxs.de <mr...@4sxs.de> wrote:

> Hello,
>
> This is my first request in this mailing list, I hope I am doing it right !
>
> I am currently developing a Portlet for Liferay using Struts 2, it is
> working good and I am often surprised with all the possibilities from
> Struts2.
> Unfortunately I have a blocker !
> I would like to design a form with a survey thanks to dropDown List and
> would like to get all the content from a database.
> In the database, there are a table question (questionId, questionName) and
> a table answer (answerId, answerName, questionId) and I would like to
> generate all the dropdown from these table...
>
> While (question)
> {
>        While {answer from this question)
>        {
> }
>
>
> I tried many solutions, but I didn't achieved it!
>
> Thank you for your help,
> Mat
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>