aspose file tools*
The moose likes Struts and the fly likes values for select tag from the database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "values for select tag from the database" Watch "values for select tag from the database" New topic
Author

values for select tag from the database

rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
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..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Create an action property containing the items from the DB. Use the <s:select> tag.
rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
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

Joined: Oct 03, 2008
Posts: 123
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

By putting the elements in a list and using the select tag--the link I provided has examples.
rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Oct 03, 2008
Posts: 123
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Oct 03, 2008
Posts: 123
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Oct 03, 2008
Posts: 123
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

Joined: Oct 03, 2008
Posts: 123
Its working now.. I got it.. the way I posted is the correct way..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: values for select tag from the database
 
Similar Threads
Dynamic Changes in JSP - Urgent
Struts Html select tag
JS Function with Two Parameters
new to Struts
Using html:select