ayeen
asked on
struts problem: pulldown menu
hi all,
i'm just wondering if someone could help me with my struts pulldown menu problem.... i'm trying to convert my multibox to a pulldown menu... the user can only choose 1 driver...
thanks in advance!
- @
i have this multibox:
<logic:notEmpty name="processFilterFormBea n" property="driverlist">
<logic:iterate name="processFilterFormBea n" property="driverlist" id="driver">
<tr>
<td>
<html:multibox name="driver" property="selecteddriverid ">
<bean:write name="driver" property="drivername"/>
</html:multibox>
<bean:write name="driver" property="drivername" />
</td>
</tr>
</logic:iterate>
</logic:notEmpty>
that i want to make into a pulldown menu...
i've tried doing the several <html:select>/<html:option sCollectio n> tutorials i found online but i can't make it work and i would really appreciate your help guys...
-------------------------- ---------- ---
here's what my struts-config.xml looks:
-------------------------- ---------- ---
<action-mappings>
<action path="/maintenance" type="com.webtest.resource s.Maintena nceAction" name="processFilterFormBea n" scope="request">
<forward name="start" path = "/WEB-INF/pages/Maintenanc e.jsp"/>
</action>
</action-mappings>
<form-beans>
<form-bean name="processFilterFormBea n" type="com.webtest.resource s.ProcessF ilterFormB ean">
</form-bean>
</form-beans>
-------------------------- ---------- ---
here's my Form Bean:
-------------------------- ---------- ---
public class ProcessFilterFormBean extends ActionForm {
private Collection driverlist;
private String[] selecteddriverid;
private String driverid = "";
private String drivername = "";
// for driver list
public void setDriverlist(Collection driverlist){
this.driverlist = driverlist;
}
public Collection getDriverlist(){
return driverlist;
}
public String[] getSelecteddriverid(){
return selecteddriverid;
}
public void setSelecteddriverid(String [] driverid){
this.selecteddriverid = driverid;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
driverlist = new ArrayList();
}
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
return errors;
}
}
-------------------------- ---------- ---
here's my action class:
-------------------------- ---------- ---
public class MaintenanceAction extends Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward();
ProcessFilterFormBean pfbean = (ProcessFilterFormBean) form;
//call the DB
SimulateDB simulateDB = new SimulateDB();
pfbean.setDriverlist(simul ateDB.getD riverlist( request.ge tSession() ));
return (mapping.findForward("star t"));
}
}
-------------------------- ---------- ---
here is my SimulateDB:
-------------------------- ---------- ---
public class SimulateDB {
private String drivername;
private Collection dlist;
private String result;
private void init(HttpSession session) {
//test data while DB is not yet ready
dlist = new ArrayList();
dlist.add(new Driver("CCMP", "Suspense", false));
dlist.add(new Driver("EXALL", "Exclusion Indicator", false));
dlist.add(new Driver("EXSUB", "Exclusion Subscriber", false));
dlist.add(new Driver("MAIL", "Mail to Option", false));
dlist.add(new Driver("PTD", "Paid to Date", false));
dlist.add(new Driver("SUSP", "Suspense Days", false));
dlist.add(new Driver("TERM", "Termination Days", false));
dlist.add(new Driver("OTHER", "Other", false));
session.setAttribute("driv erDB", dlist);
//another set..trying LabelValueBean
ArrayList dlist2 = new ArrayList();
dlist2.add(new org.apache.struts.util.Lab elValueBea n("CCMP", "Suspense"));
dlist2.add(new org.apache.struts.util.Lab elValueBea n("EXALL", "Exclusion Indicator"));
dlist2.add(new org.apache.struts.util.Lab elValueBea n("EXSUB", "Exclusion Subscriber"));
dlist2.add(new org.apache.struts.util.Lab elValueBea n("MAIL", "Mail to Option"));
dlist2.add(new org.apache.struts.util.Lab elValueBea n("PTD", "Paid to Date"));
dlist2.add(new org.apache.struts.util.Lab elValueBea n("SUSP", "Suspense Days"));
dlist2.add(new org.apache.struts.util.Lab elValueBea n("TERM", "Termination Days"));
dlist2.add(new org.apache.struts.util.Lab elValueBea n("OTHER", "Other"));
session.setAttribute("fulf illment_dr ivers", dlist2);
}
private void loadData(HttpSession session) {
dlist = (Collection) session.getAttribute("driv erDB");
if (dlist == null || elist == null)
init(session);
}
public String getDrivername(HttpSession session) {
loadData(session);
return drivername;
}
public void loadDriverlist(HttpSession session){
//put them in our session
dlist = (Collection) session.getAttribute("driv erDB");
if (dlist == null)
init(session);
}
public Collection getDriverlist(HttpSession session) {
loadDriverlist(session);
return dlist;
}
}
-------------------------- ---------- ---
here's my Driver class:
-------------------------- ---------- ---
public class Driver {
private String driverid = "";
private String[] selecteddriverid;
private String drivername = "";
public Driver(){}
public Driver(String driverid, String drivername, boolean checked){
this.driverid = driverid;
this.drivername = drivername;
}
public void setDriverid(String driverid){
this.driverid = driverid;
}
public String getDriverid(){
return driverid;
}
public String[] getSelecteddriverid(){
return selecteddriverid;
}
public void setSelecteddriverid(String [] driverid){
this.selecteddriverid = driverid;
}
public void setDrivername(String drivername){
this.drivername = drivername;
}
public String getDrivername(){
return drivername;
}
}
i'm just wondering if someone could help me with my struts pulldown menu problem.... i'm trying to convert my multibox to a pulldown menu... the user can only choose 1 driver...
thanks in advance!
- @
i have this multibox:
<logic:notEmpty name="processFilterFormBea
<logic:iterate name="processFilterFormBea
<tr>
<td>
<html:multibox name="driver" property="selecteddriverid
<bean:write name="driver" property="drivername"/>
</html:multibox>
<bean:write name="driver" property="drivername" />
</td>
</tr>
</logic:iterate>
</logic:notEmpty>
that i want to make into a pulldown menu...
i've tried doing the several <html:select>/<html:option
--------------------------
here's what my struts-config.xml looks:
--------------------------
<action-mappings>
<action path="/maintenance" type="com.webtest.resource
<forward name="start" path = "/WEB-INF/pages/Maintenanc
</action>
</action-mappings>
<form-beans>
<form-bean name="processFilterFormBea
</form-bean>
</form-beans>
--------------------------
here's my Form Bean:
--------------------------
public class ProcessFilterFormBean extends ActionForm {
private Collection driverlist;
private String[] selecteddriverid;
private String driverid = "";
private String drivername = "";
// for driver list
public void setDriverlist(Collection driverlist){
this.driverlist = driverlist;
}
public Collection getDriverlist(){
return driverlist;
}
public String[] getSelecteddriverid(){
return selecteddriverid;
}
public void setSelecteddriverid(String
this.selecteddriverid = driverid;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
driverlist = new ArrayList();
}
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
return errors;
}
}
--------------------------
here's my action class:
--------------------------
public class MaintenanceAction extends Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward();
ProcessFilterFormBean pfbean = (ProcessFilterFormBean) form;
//call the DB
SimulateDB simulateDB = new SimulateDB();
pfbean.setDriverlist(simul
return (mapping.findForward("star
}
}
--------------------------
here is my SimulateDB:
--------------------------
public class SimulateDB {
private String drivername;
private Collection dlist;
private String result;
private void init(HttpSession session) {
//test data while DB is not yet ready
dlist = new ArrayList();
dlist.add(new Driver("CCMP", "Suspense", false));
dlist.add(new Driver("EXALL", "Exclusion Indicator", false));
dlist.add(new Driver("EXSUB", "Exclusion Subscriber", false));
dlist.add(new Driver("MAIL", "Mail to Option", false));
dlist.add(new Driver("PTD", "Paid to Date", false));
dlist.add(new Driver("SUSP", "Suspense Days", false));
dlist.add(new Driver("TERM", "Termination Days", false));
dlist.add(new Driver("OTHER", "Other", false));
session.setAttribute("driv
//another set..trying LabelValueBean
ArrayList dlist2 = new ArrayList();
dlist2.add(new org.apache.struts.util.Lab
dlist2.add(new org.apache.struts.util.Lab
dlist2.add(new org.apache.struts.util.Lab
dlist2.add(new org.apache.struts.util.Lab
dlist2.add(new org.apache.struts.util.Lab
dlist2.add(new org.apache.struts.util.Lab
dlist2.add(new org.apache.struts.util.Lab
dlist2.add(new org.apache.struts.util.Lab
session.setAttribute("fulf
}
private void loadData(HttpSession session) {
dlist = (Collection) session.getAttribute("driv
if (dlist == null || elist == null)
init(session);
}
public String getDrivername(HttpSession session) {
loadData(session);
return drivername;
}
public void loadDriverlist(HttpSession
//put them in our session
dlist = (Collection) session.getAttribute("driv
if (dlist == null)
init(session);
}
public Collection getDriverlist(HttpSession session) {
loadDriverlist(session);
return dlist;
}
}
--------------------------
here's my Driver class:
--------------------------
public class Driver {
private String driverid = "";
private String[] selecteddriverid;
private String drivername = "";
public Driver(){}
public Driver(String driverid, String drivername, boolean checked){
this.driverid = driverid;
this.drivername = drivername;
}
public void setDriverid(String driverid){
this.driverid = driverid;
}
public String getDriverid(){
return driverid;
}
public String[] getSelecteddriverid(){
return selecteddriverid;
}
public void setSelecteddriverid(String
this.selecteddriverid = driverid;
}
public void setDrivername(String drivername){
this.drivername = drivername;
}
public String getDrivername(){
return drivername;
}
}
ASKER
thanks jathrek.... i tried doing what you have suggested..but i'm still getting errors...this is my code:
<form-bean name="singleSelectForm"
type="org.apache.struts.ac tion.DynaA ctionForm" >
<form-property name="control" type="java.lang.String"/>
</form-bean>
approach 1: error: Jsp Translate: Attribute <html: option has no value
inside my jsp:
<html:select property="control" size="2">
<logic:iterate id="driver" name="driverlist"
<html:option value="<%=driver.getDriver id()%>">
<bean:write name="driver" property="drivername"/>
</html:option>
</logic:iterate>
</html:select>
2nd approach: error: Error 500: No getter method available for property driver for bean under name org.apache.struts.taglib.h tml.BEAN
inside my struts-config.xml
<form-bean name="singleSelectForm"
type="org.apache.struts.ac tion.DynaA ctionForm" >
<form-property name="control" type="java.lang.String"/>
</form-bean>
inside my jsp:
<html:select property="singleSelectForm ">
<html:options collection="driverlist" property="selecteddriverid " labelProperty="drivername" />
</html:select>
thanks for your time..
<form-bean name="singleSelectForm"
type="org.apache.struts.ac
<form-property name="control" type="java.lang.String"/>
</form-bean>
approach 1: error: Jsp Translate: Attribute <html: option has no value
inside my jsp:
<html:select property="control" size="2">
<logic:iterate id="driver" name="driverlist"
<html:option value="<%=driver.getDriver
<bean:write name="driver" property="drivername"/>
</html:option>
</logic:iterate>
</html:select>
2nd approach: error: Error 500: No getter method available for property driver for bean under name org.apache.struts.taglib.h
inside my struts-config.xml
<form-bean name="singleSelectForm"
type="org.apache.struts.ac
<form-property name="control" type="java.lang.String"/>
</form-bean>
inside my jsp:
<html:select property="singleSelectForm
<html:options collection="driverlist" property="selecteddriverid
</html:select>
thanks for your time..
For the option, you may try;
<html:option name="driver" property="selecteddriverid ">...</htm l:option>
For the second error;
I do not really understand the error message, it seems you've an struts tag generating a HTML field which value is based on a property "driver". Though, the small JSP code you show me is using a "selecteddriverid" , so I think the error message is not related to that select element.
Anyway, try correcting the first case and tell me how it works out?
Sorry for those little disturbance, I'm far from being perfect (at least for now :p)...
<html:option name="driver" property="selecteddriverid
For the second error;
I do not really understand the error message, it seems you've an struts tag generating a HTML field which value is based on a property "driver". Though, the small JSP code you show me is using a "selecteddriverid" , so I think the error message is not related to that select element.
Anyway, try correcting the first case and tell me how it works out?
Sorry for those little disturbance, I'm far from being perfect (at least for now :p)...
ASKER
hi again Jathrek,
this is how my jsp now ooks:
<html:select property="control">
<logic:iterate id="" name="driverlist"
<html:option name="driver" property="selecteddriverid >
<bean:write name="driver" property="drivername"/>
</html:option>
</logic:iterate>
</html:select>
and this is the error --> JspTranslate: Attribute <html:option has no value
this is how my jsp now ooks:
<html:select property="control">
<logic:iterate id="" name="driverlist"
<html:option name="driver" property="selecteddriverid
<bean:write name="driver" property="drivername"/>
</html:option>
</logic:iterate>
</html:select>
and this is the error --> JspTranslate: Attribute <html:option has no value
Is it a copy and paste?
If yes, it seems that the logic:iterate tag is missing the value for the ID attribute (which probably should be "driver".
Otherwise, I have no idea what causes that error; I've never seen it, and it should work as is :(
If yes, it seems that the logic:iterate tag is missing the value for the ID attribute (which probably should be "driver".
Otherwise, I have no idea what causes that error; I've never seen it, and it should work as is :(
ASKER
hi...sorry about that: here it is:
<html:select property="control" size="2">
<logic:iterate id="driver" name="driverlist">
<html:option name="driver" property="selecteddriverid ">
<bean:write name="driver" property="drivername"/>
</html:option>
</logic:iterate>
</html:select>
the error is now: JspTranslate: Attribute name invalid according to the specified TLD
thanks again!
<html:select property="control" size="2">
<logic:iterate id="driver" name="driverlist">
<html:option name="driver" property="selecteddriverid
<bean:write name="driver" property="drivername"/>
</html:option>
</logic:iterate>
</html:select>
the error is now: JspTranslate: Attribute name invalid according to the specified TLD
thanks again!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sorry for bugging you again..i'm new in struts and i'm really just getting the hang of it..
i'm getting this error:
Error 500: No getter method available for property control for bean under name org.apache.struts.taglib.h tml.BEAN
here's my jsp code:
<html:select property="control" size="2">
<logic:iterate id="driver" name="driverlist">
<option value="<bean:write name="driver" property="selecteddriverid "/>">
<bean:write name="driver" property="drivername"/>
</option>
</logic:iterate>
</html:select>
here is my struts-config.xml entries:
<form-beans>
<form-bean name="singleSelectForm"
type="org.apache.struts.ac tion.DynaA ctionForm" >
<form-property name="control" type="java.lang.String"/>
</form-bean>
<form-bean name="processFilterFormBea n" type="com.webtest.resource s.ProcessF ilterFormB ean">
</form-bean>
</form-beans>
all other files and codes are still the same as i posted above....
i'm getting this error:
Error 500: No getter method available for property control for bean under name org.apache.struts.taglib.h
here's my jsp code:
<html:select property="control" size="2">
<logic:iterate id="driver" name="driverlist">
<option value="<bean:write name="driver" property="selecteddriverid
<bean:write name="driver" property="drivername"/>
</option>
</logic:iterate>
</html:select>
here is my struts-config.xml entries:
<form-beans>
<form-bean name="singleSelectForm"
type="org.apache.struts.ac
<form-property name="control" type="java.lang.String"/>
</form-bean>
<form-bean name="processFilterFormBea
</form-bean>
</form-beans>
all other files and codes are still the same as i posted above....
Well, don't worry, I taught I was getting good at Struts, but it seems I'm still pretty far from it ^^
Anyway, for your other problem, I can only tell you to check a few things;
- Is the html:select correctly surrounded by a html:form?
- Is the action referenced by your html:form corretly linked to the action form "singleSelectForm"
That's about it, and I must admit that I've not been working a lot with dynamic action forms (damn, one more thing I dont know in Struts :( ...)
Anyway, for your other problem, I can only tell you to check a few things;
- Is the html:select correctly surrounded by a html:form?
- Is the action referenced by your html:form corretly linked to the action form "singleSelectForm"
That's about it, and I must admit that I've not been working a lot with dynamic action forms (damn, one more thing I dont know in Struts :( ...)
ASKER
thanks again for your reply.
yes, the html:select is enclosed in html:form
as to your 2nd question, my current action is linked to displaydriverdetails.do which is calling processFilterFormBean and not singleSelectForm. the processFilterFormBean contains all my getter/setter methods for the other form fields in my jsp. but just the same, i tried changing my action to singleSelectForm but it complains about driverlist: Error 500: Cannot find bean driverlist in any scope
i'm sorry i'm kinda lost...
----------------------
STRUTS CONFIG ENTRIES
----------------------
<struts-config>
<form-beans>
<form-bean name="singleSelectForm"
type="org.apache.struts.ac tion.DynaA ctionForm" >
<form-property name="control" type="java.lang.String"/>
</form-bean>
<form-bean name="processFilterFormBea n" type="com.webtest.resource s.ProcessF ilterFormB ean">
</form-bean>
</form-beans>
<action-mappings>
<action path="/displaydriverdetail s" type="com.webtest.resource s.ProcessF ilterActio n" name="processFilterFormBea n" scope="session">
<forward name="filter" path = "/WEB-INF/pages/ProcessFil ter.jsp"/>
</action>
</action-mappings>
</struts-config>
----------------------
JSP code
----------------------
<html:form action="displaydriverdetai ls.do" method="post">
<html:select property="control" size="2">
<logic:iterate id="driver" name="driverlist">
<option value="<bean:write name="driver" property="selecteddriverid "/>">
<bean:write name="driver" property="drivername"/>
</option>
</logic:iterate>
</html:select>
Enter Entity ID# : <html:text property="entityid" name="processFilterFormBea n" disabled="false"/>
...and more form fields here...
</html:form>
-------------------------- ---------- ---
here's my Form Bean:
-------------------------- ---------- ---
public class ProcessFilterFormBean extends ActionForm {
private Collection driverlist;
private String[] selecteddriverid;
private String driverid = "";
private String drivername = "";
private String entityid = "";
// for driver list
public void setDriverlist(Collection driverlist){
this.driverlist = driverlist;
}
public Collection getDriverlist(){
return driverlist;
}
public String[] getSelecteddriverid(){
return selecteddriverid;
}
public void setSelecteddriverid(String [] driverid){
this.selecteddriverid = driverid;
}
public String getEntityid(){
return entityid;
}
public void setEntityid(String entityid){
this.entityid = entityid;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
driverlist = new ArrayList();
}
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
return errors;
}
}
-------------------------- ---------- ---
here's my action class:
-------------------------- ---------- ---
public class ProcessFilterAction extends Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward();
ProcessFilterFormBean pfbean = (ProcessFilterFormBean) form;
String form_entityid = request.getParameter("enti tyid");
String form_driver = request.getParameter("???" ); //how to call the form field for this?
//calls the DB to load drivers
SimulateDB simulateDB = new SimulateDB();
pfbean.setDriverlist(simul ateDB.getD riverlist( request.ge tSession() ));
return (mapping.findForward("star t"));
}
}
...codes for SimulateDB is on my first post...
thank you so much again..
yes, the html:select is enclosed in html:form
as to your 2nd question, my current action is linked to displaydriverdetails.do which is calling processFilterFormBean and not singleSelectForm. the processFilterFormBean contains all my getter/setter methods for the other form fields in my jsp. but just the same, i tried changing my action to singleSelectForm but it complains about driverlist: Error 500: Cannot find bean driverlist in any scope
i'm sorry i'm kinda lost...
----------------------
STRUTS CONFIG ENTRIES
----------------------
<struts-config>
<form-beans>
<form-bean name="singleSelectForm"
type="org.apache.struts.ac
<form-property name="control" type="java.lang.String"/>
</form-bean>
<form-bean name="processFilterFormBea
</form-bean>
</form-beans>
<action-mappings>
<action path="/displaydriverdetail
<forward name="filter" path = "/WEB-INF/pages/ProcessFil
</action>
</action-mappings>
</struts-config>
----------------------
JSP code
----------------------
<html:form action="displaydriverdetai
<html:select property="control" size="2">
<logic:iterate id="driver" name="driverlist">
<option value="<bean:write name="driver" property="selecteddriverid
<bean:write name="driver" property="drivername"/>
</option>
</logic:iterate>
</html:select>
Enter Entity ID# : <html:text property="entityid" name="processFilterFormBea
...and more form fields here...
</html:form>
--------------------------
here's my Form Bean:
--------------------------
public class ProcessFilterFormBean extends ActionForm {
private Collection driverlist;
private String[] selecteddriverid;
private String driverid = "";
private String drivername = "";
private String entityid = "";
// for driver list
public void setDriverlist(Collection driverlist){
this.driverlist = driverlist;
}
public Collection getDriverlist(){
return driverlist;
}
public String[] getSelecteddriverid(){
return selecteddriverid;
}
public void setSelecteddriverid(String
this.selecteddriverid = driverid;
}
public String getEntityid(){
return entityid;
}
public void setEntityid(String entityid){
this.entityid = entityid;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
driverlist = new ArrayList();
}
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
return errors;
}
}
--------------------------
here's my action class:
--------------------------
public class ProcessFilterAction extends Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
ActionErrors errors = new ActionErrors();
ActionForward forward = new ActionForward();
ProcessFilterFormBean pfbean = (ProcessFilterFormBean) form;
String form_entityid = request.getParameter("enti
String form_driver = request.getParameter("???"
//calls the DB to load drivers
SimulateDB simulateDB = new SimulateDB();
pfbean.setDriverlist(simul
return (mapping.findForward("star
}
}
...codes for SimulateDB is on my first post...
thank you so much again..
ASKER
i had it working!
looks like i messed up the <logic:iterate tag
here's the working jsp entry for my pulldown
<html:select property="selecteddriverid " size="1">
<logic:iterate name="processFilterFormBea n" property="driverlist" id="driver">
<option value="<bean:write name="driver" property="selecteddriverid "/>">
<bean:write name="driver" property="drivername"/>
</option>
</logic:iterate>
</html:select>
thanks for the patience and effort Jathrek!
looks like i messed up the <logic:iterate tag
here's the working jsp entry for my pulldown
<html:select property="selecteddriverid
<logic:iterate name="processFilterFormBea
<option value="<bean:write name="driver" property="selecteddriverid
<bean:write name="driver" property="drivername"/>
</option>
</logic:iterate>
</html:select>
thanks for the patience and effort Jathrek!
Bah, sorry for taking so long to solve this problem :(
I hope you'll be able to continue improve your knowledge in Struts without too many problems ^^
I hope you'll be able to continue improve your knowledge in Struts without too many problems ^^
Maybe you could even remove the loop by using a single html:optionsCollection which would refer the collection you have in your actionForm.
Anyway, you'll find informations for those tags in the official taglib reference;
http://struts.apache.org/1.3.8/struts-taglib/tagreference.html#struts-html.tld