| Author |
Not able to retain the selected value from the drop down menu
|
Hari Kiran
Greenhorn
Joined: May 11, 2007
Posts: 3
|
|
Hi, In my application, i am using the html:select , where i am populating using html ptions 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
Joined: Jan 10, 2002
Posts: 56554
|
|
|
Please be sure to ask Struts questions in the Struts forum. This post has been moved there for you.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
|
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.
|
Merrill
Consultant, Sima Solutions
|
 |
Hari Kiran
Greenhorn
Joined: May 11, 2007
Posts: 3
|
|
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
Joined: Feb 15, 2005
Posts: 4864
|
|
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.
|
 |
 |
|
|
subject: Not able to retain the selected value from the drop down menu
|
|
|