• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to select a value in the drop down list with value getting from database?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
i m devoloping struts application and arrived with the problem with setting dropdown list.
i want to set perticuler month or year or other value in the drop down list .these value will come from database...
i have property in bean there i am getting the value in integer...like form month january is 1,feb is 2 so on....now i want to set the values in the list accordingly...such that if value is 1 then in the list the january will be selected.....
can anybody please help me...... ...
 
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
Which version of Struts?

If S1, if the value is set appropriately in the form bean then html tags should already be selecting it appropriately. If S2, if the value is set on the action property and the tag is used correctly it should be pre-selected.
 
sruti roy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is s1.2
i m getting in action class property but unfortunately it is not showing in the html drop down list... here i m posting my code...please tell me where i make the mistake....
//this is jsp..view page
<html:select name="topsheetactionForm" size="1" property="month">
<html:option value="0">Select Month</html:option>
<html:option value="1">January</html:option>
<html:option value="2">February</html:option>
<html:option value="3">March</html:option>
<html:option value="4">April</html:option>
<html:option value="5">May</html:option>
<html:option value="6">June</html:option>
<html:option value="7">July</html:option>
<html:option value="8">August</html:option>
<html:option value="9">September</html:option>
<html:option value="10">October</html:option>
<html:option value="11">November</html:option>
<html:option value="12">December</html:option>
</html:select>

//this is bean corresponding to month
public String getMonth() {
return month;
}

public void setMonth(String month) {
this.month = month;
}
//from database i m getting the value of month in the variable...this is my action class
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
topsheetActionForm tpform1 = (topsheetActionForm) form;//object of bean

try{
resultset rst=stmt.executequery(select month from table where condition);//this are done properly...//getting data from database....connecting are done...
while(rst.next()){
tpform.setMonth(rst.getString("month"));
}
}
by this way if i set the ttext box then there is no problem..but it is not selecting the drop down list...
please help....i m stuck in my porject....
 
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.

You're setting all the options manually--if you're going to create the options manually then you'll have to choose the selected one manually as well.
 
sruti roy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
then what is the alternative....how can i get it done...???...how should i do it?
 
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
Use the options or optionsCollection tag?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic