• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

values for select tag from the database

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using a select tag . I just wanted to have the values for the list attribute of select tag from the database. I am using strut 2.0. I have set the project values in the action to a arraylist. I can use iterator to get those values in the jsp. But my question is how to set the values to the list..


Any advise..
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Create an action property containing the items from the DB. Use the <s:select> tag.
 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have set the values in the action. how will I be able to bring the values under the list attribute of select tag
 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am able to set this values from the database in a list. Can anyone help me how to bring these values inside the list for the users..

<html:select name="strProjectName" list="#{'SELECT':'Select','I want the list to be displayed here'}" >
</html:select></td>
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By putting the elements in a list and using the select tag--the link I provided has examples.
 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I see in the link.. But I am not able to correlate what are these values for each attribute..

<s:select label="Pets"
name="petIds"
list="petDao.pets"
listKey="id"
listValue="name"
multiple="true"
size="3"
required="true"
value="%{petDao.pets.{id}}"

I have a list arrProjList and a variable strProjName has the project name..
>
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you read the documentation for the select tag? It describes how each attribute should be used. If that still isn't enough information, you'd have to actually post your code in order to do your work for you--I have no idea what your list property is, the beans contained within the list, etc.
 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an action where I set the projectNames in a list arrProjectList. When I try to fetch these values in a jsp using an iterator in a text field, I am able to get the first value in the list. So I am sure this works fine.

I wanted to bring it under the select tag

ProjectAction.class :

method() {
arrProjectList = objProjectDAO.getProjectInfo();
(which will have the project list)
this.setArrProjectList(arrProjectList);
}

public ArrayList<ProjectVO> getArrProjectList() {
return arrProjectList;
}

public void setArrProjectList(ArrayList<ProjectVO> arrProjectList) {
this.arrProjectList = arrProjectList;
}

In My jsp

<html:iterator value="arrApplicationList" >
<td class="rmpCombo"><html:text name="Project Name *"></html:text>      
<html:select list="#{this is the place}" value="%{strProjectName}" >
</html:select></td>
</html:iterator>
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an action where I set the projectNames in a list arrProjectList. When I try to fetch these values in a jsp using an iterator in a text field, I am able to get the first value in the list. So I am sure this works fine.

I wanted to bring it under the select tag

ProjectAction.class :


In My jsp
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, it's a *really* bad idea to use a Struts 1 prefix with the Struts 2 tags. It's very, very confusing and misleading.

What about the select tag documentation is giving you a problem?
 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry for that.. I have posted the code the way I tried with the select tag documentation


where the objProjectVO is the object where I set the projectName as a string using objProjectVO.setStrProjName(). Then I put this object inside a list arrProjectList and set this in the action using

 
rahulJ james
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its working now.. I got it.. the way I posted is the correct way..
 
reply
    Bookmark Topic Watch Topic
  • New Topic