• 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

Dynamically include and show what's been selected in the last page

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On my first JSP page, I have few picklist box like "Item", "Price Range", "Brand Name", etc. After user makes choices, I will call a servlet to search the database based on what user selected, then return with the invoice list, but I want to keep the "Item", "Price Range", "Brand Name" at where they are and the default selection for each picklist should be what user just selected. In this way, user can change their selection and then click "Get Result" button and it should return the new result, that's it. Looks simple. But my question is --
1. If I create a JSP page including these picklists, and then it calls the servlet, then the servlet forward to another JSP (or the same JSP) including the new invoice part, then how can the second JSP change its default selction for each picklist ? It seems impossible.
2. I can create a helper class to dynamically create this picklist HTML part, in other words, I use this class to generate the "<OPTION VALUE=.., SELECTED>" dynamically, and output this whole string to the JSP page. This works but I am wondering if there is better way to do it.
Thanks.
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Consider the case where u have a JSP with picklist and u r submitting the request to a servlet and servlet fetches infomation from the DataBase and forwards to the same JSP.
Two ways u can handle the situation.
1.Write a javascript in onChange of the combo(picklist) and in the function u store the selected value in a hidden variable.
2.The hidden variable value is availble in the request.So in servlet get the value of the hidden variable and put it the request object as request.setAttribute().Once the servlet forwards the request and response to the original JSP(from where u submitted to the servlet), in the JSP retrieve the value and call a function populate in onLoad of the page.
in populate set the value
<%
String value = request.getParameter("hiddenValue");
%>
function populate()
{
document.form.picklist.options[document.form.picklist.selectedIndex].value = "<%=value%>"
}
Cheers
Geeta
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic