• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
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 html:options 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.
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.
 
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.
 
Here. Have a potato. I grew it in my armpit. And from my other armpit, this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic