Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Struts
Search Coderanch
Advance search
Google search
Register / Login
This week's book giveaway is in the
Raspberry Pi
forum.
We're giving away four copies of
Getting started with Java on the Raspberry Pi
and have Frank DelPorte on-line!
See
this thread
for details.
Win a copy of
Getting started with Java on the Raspberry Pi
this week in the
Raspberry Pi
forum!
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
Ron McLeod
Paul Clapham
Tim Cooke
Jeanne Boyarsky
Sheriffs:
Rob Spoor
Devaka Cooray
Liutauras Vilda
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Piet Souris
Forum:
Struts
html:iterate or html:multibox problem
Shibin Paul
Greenhorn
Posts: 18
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
------------------------------------------------------- The jsp page ------------------------------------------------------- <%@ taglib uri="/WEB-INF/struts-html" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-bean" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-logic" prefix="logic" %> <html:html> <head> <title>User Details</title> </head> <body> <html:form styleId="user" scriptLanguage="JavaScript" action="confirm001" focus = "fname"> <table > <tr> <td>First Name:</td><td><html:text property = "fname" /></td> </tr> <tr> <td>Middle Name:</td><td><html:text property = "mname" /><br></td> </tr> <tr> <td>Last Name:</td><td><html:text property = "lname" /></td> </tr> <tr> <td> <html:radio property = "sex" value = "male" /> male </td> <td> <html:radio property = "sex" value = "female" /> female </td> </tr> <tr> <td> State <logic :-P resent name = "vecState"> <html:select property="state" onchange="doSubmit()"> <html :-o ptionsCollection name ="vecState" label = "strState" value = "intID"></html :-o ptionsCollection> </html:select> </logic :-P resent> </td> </tr> <tr> <td> City <logic :-P resent name = "vecCity"> <html:select property="city" onchange="doSubmit()"> <html :-o ptionsCollection name ="vecCity" label = "strCity" value = "intCity"></html :-o ptionsCollection> </html:select> </logic :-P resent> </td> </tr> <tr> <td> <logic :-P resent name = "vecSkill"> <logic:iterate name="vecSkill" id = "strInterest"> <!-- <bean:write name="strInterest"/> --> <html:multibox property = "skill" value = "skillSet" /> <bean:write name="strInterest" property="strInterest" /><br> </logic:iterate> </logic :-P resent> </td> </tr> <SCRIPT LANGUAGE="JavaScript"> function doSubmit() { document.forms[0].action = 'UserDet001.do'; document.forms[0].submit(); } </SCRIPT> <tr> </tr> <tr> <th colspan = "2"><html:submit></html:submit></th> </tr> </table> </html:form> </body> </html:html> -------------------------------------------------------------------------- UserDetails form -------------------------------------------------------------------------- package com.example; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; public class UserDetails001Form extends ActionForm { private String fname=""; private String mname=""; private String lname=""; private String sex = ""; private String state = ""; private String city = ""; //private String[] skillSelected = new String[UserDataBean001.skillSize]; private String[] skill = new String[UserDataBean001.skillSize]; //private String skill = ""; public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getFname() { System.out.println(fname); return fname; } public void setFname(String fname) { this.fname = fname; System.out.println(fname); } public String getLname() { System.out.println(lname); return lname; } public void setLname(String lname) { System.out.println(lname); this.lname = lname; } public String getMname() { System.out.println(mname); return mname; } public void setMname(String mname) { System.out.println("Welcome"); System.out.println(mname); this.mname = mname; } public String getState() { System.out.println("getState " + state); return state; } public void setState(String state) { System.out.println("setState " + state); this.state = state; } public void reset(ActionMapping mapping, HttpServletRequest request) { this.fname=""; this.mname=""; this.lname=""; this.sex = ""; this.state = ""; this.city = ""; skill = new String[UserDataBean001.skillSize]; } public String[] getSkill() { return skill; } public void setSkill(String[] skill) { this.skill = skill; } } ------------------------------------------------------- struts-config.xml -------------------------------------------------------- <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"> <struts-config> <data-sources> <data-source type="org.apache.commons.dbcp.BasicDataSource" > <set-property property = "driverClassName" value = "sun.jdbc.odbc.JdbcOdbcDriver"/> <set-property property = "url" value = "jdbc :-o dbc:UserDet" /> <set-property property = "username" value="" /> <set-property property = "password" value="" /> </data-source> </data-sources> <form-beans> <form-bean name = "LoginForm" type = "com.example.LoginForm" /> <form-bean name = "UserDetailsForm" type = "com.example.UserDetailsForm" /> <form-bean name = "UserDetails001Form" type = "com.example.UserDetails001Form" /> </form-beans> <global-forwards> <forward name = "login" path="Login.jsp"></forward> </global-forwards> <action-mappings> <action path = "/goto" type = "com.example.LoginAction" name = "LoginForm" validate ="true" input = "/Login.jsp" scope= "session"> <forward name = "success" path = "/Success.jsp" /> <forward name = "fail" path = "/Login.jsp" /> </action> <action path = "/UserDet" type = "com.example.UserDetailsAction" name = "UserDetailsForm" scope = "request"> <forward name = "success" path = "/Success.jsp" /> <forward name = "fail" path = "/UserDetails.jsp" /> </action> <action path = "/confirm" type = "com.example.UserDetailsAction" name = "UserDetailsForm" scope = "request"> <forward name = "success" path = "/Success.jsp" /> <forward name = "fail" path = "/UserDetails.jsp" /> </action> <action path = "/UserDet001" type = "com.example.UserDetails001Action" name = "UserDetails001Form" scope = "request"> <forward name = "success" path = "/Success.jsp" /> <forward name = "fail" path = "/UserDetails001.jsp" /> </action> <action path = "/confirm001" type = "com.example.UserDetails001Action" name = "UserDetails001Form" scope = "request"> <forward name = "success" path = "/Success.jsp" /> <forward name = "fail" path = "/UserDetails001.jsp" /> </action> </action-mappings> <message-resources parameter="com.example.messageProperties" /> </struts-config> ------------------------------------------------------------------ Problem -------------------------------------------------------------------- Even if I select only one check box and and click the submit button, by default all checkboxes get selected.What could be the reason for this? Thanks in advance.
Merrill Higginson
Ranch Hand
Posts: 4864
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
In a series of multibox elements, the
property
remains constant but the
value
must change. So, you need to change
<html:multibox property = "skill" value = "skillSet" />
to
<html:multibox property = "skill" value = "<%=strInterest%>" />
If your web application is a
Servlet
2.4 application, I'd recommend using the EL expression ${strInterest} rather than the scriptlet.
Merrill
Consultant,
Sima Solutions
Shibin Paul
Greenhorn
Posts: 18
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks for the help Merill.
please buy my thing and then I'll have more money:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Validation error
problem in logic:iterate
NullPointerException
Struts 1.2.4 File Upload - Form File is null in action
Struts Validation Empty alert Box
More...