• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

update html:options

 
Luke Zechariah
Ranch Hand
Posts: 128
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using struts, in my jsp page I have options menu where the value is selected depending on the database value, but the value in the database can be any some new value all the time. How should I make a new list then.

For ex: Let's assume there is a field in database: officeCodes having values from 1 through 10.

Now a new value 11 has been added to officeCodes, how should I update the list. The only code I have is as follows:


<bean:message key="clmrcpt.fromFO" />
<html:select name="ClaimReceiptForm" property="fromOffice">
<html ption value="1">one</html ption>
<html ption value="2">two</html ption>
<html ption value="3">three</html ption>
<html ption value="4">four</html ption>
<html ption value="5">five</html ption>
<html ption value="6">six</html ption>
<html ption value="7">seven</html ption>
<html ption value="8">eight</html ption>
<html ption value="9">nine</html ption>
<html ption value="10">ten</html ption>
</html:select>


I do not know how to proceed pls guide me. Thanks for the help in advance.

Arun.
 
alan do
Ranch Hand
Posts: 354
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
instead of using html ption, use html ptions which uses a collection to generate the dropdowns. each time the page is displayed, go back to the database to get the list and put it into the request scope.

you can put the list in the session scope if you don't mind the dropdowns not updated when the user has not established a new session.
 
Luke Zechariah
Ranch Hand
Posts: 128
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alan,

Thanks for the reply. Is it possible for you to send me a sample code on html ptions and give a brief explanation. I really appreciate for your time.

Arun.
 
G.T. Reddy
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//server side
public ArrayList getPressSystems(){
ArrayList pressSystems = new ArrayList();
Connection con = DatabaseHelper.prepareConnection();
String query = SDCQueries.SELECT_REF_PART_PRESS_SYSTEMS;
psmt = con.prepareStatement(query);
rs = psmt.executeQuery();
while (rs.next()) {
pressSystems.add(new LabelValueBean(rs.getString(1), rs.getString(1)));

}
return pressSystems;

}

////in action class
ArrayList pressSystems =(ArrayList) searchBo.getPressSystems(estimateId);

form.setPressSystems(pressSystems);

return mapping.findForward(jsppage);

//in jsp page

<html:select name="form" property="pressSystem" size="1">
<html ptions collection = "pressSystems" property = "value" labelproperty = "label"/>
</html:select>
 
Luke Zechariah
Ranch Hand
Posts: 128
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot G.T. Reddy. This really helped me move faster...!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic