Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to retain the selected value from the drop down menu

 
Hari Kiran
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In my application, i am using the html:select , where i am populating using htmlptions from the bean. I have defined onchange method where it invokes the action class.
After invoking, the page gets refreshed, and what ever the value which is selected in the drop down would be reset to the "Please Select"(default option in the drop down menu).
One more problem: If i try accesing the value of the drop down in the action class i am getting the null value.

I am looking for some one who can tell me how do i retain the value and pass the value to the form bean.

which i have selected before the page refresh.

Thanks In Advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to ask Struts questions in the Struts forum. This post has been moved there for you.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An <html:select> tag if properly coded will both retain the value when the page is redisplayed and cause the value to be available in the Action class, so it sounds like you've made some mistake in your coding. If you'd like help in debugging it, please show us relevant portions of your JSP, your ActionForm, and your struts-config.xml file.
 
Hari Kiran
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Merrill Higginson:
An <html:select> tag if properly coded will both retain the value when the page is redisplayed and cause the value to be available in the Action class, so it sounds like you've made some mistake in your coding. If you'd like help in debugging it, please show us relevant portions of your JSP, your ActionForm, and your struts-config.xml file.

JSP Code:
<tr>
<td class="columnHeader">
Service No
</td>
<td>
<html:select property="serviceNo" onchange="location.href='/DFSWeb/grievance/getServiceDetails.do'" >
<html ptions property="stationList" />
</html:select>
</td>
</tr>

Struts Config File :
<action
attribute="GrievanceAllotmentForm"
name="GrievanceAllotmentForm"
input="grievance/grievanceAllot.jsp"
path="/getServiceDetails"
scope="session"
type="com.dfs.grievance.action.GetServiceDetailsAction">
<forward name="success" path="/grievanceAllot.jsp" />
<forward name="error" path="/grievanceAllot.jsp" />
</action>

Action Class:
ArrayList serviceItemsList = new ArrayList();
GrievanceDAO grDAO = new GrievanceDAO();
GrievanceAllotmentForm serviceBean = (GrievanceAllotmentForm) form;

serviceItemsList = grDAO.getServiceDetails("1");
HttpSession session= request.getSession(true);

session.setAttribute("serviceItemsList",serviceItemsList);

return (mapping.findForward("success"));


Hi,
Please look at the code what i am using.
Please help me fixing this issue.

Thanks in Advance
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is with the following line:

in your onchange event, you've given a JavaScript command to navigate to another page without submitting the form. The reason the value is not being retained is that the form is not submitted.

What I'd suggest is to specify "/getServiceDetails" as the action in your <html:form> tag and specify "this.form.submit()" as the onchange event for your <html:select> tag.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic