You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ddd ddd <st...@rediffmail.com> on 2004/03/15 04:49:25 UTC
Drop box problem please help
Hi All
I am new bie and learning to populate the drop box by all different ways .
1. By Collections of strings
2. By collections beans
3. Hard coding
I am unable to achieve even first way tried a lot but failed can any body suggest me where I am wrong. Also pl. suggest me how the collection of beans will be coded . any body has simple java nd jsp code please Post me
Manay many thanks
Regrds
StrutsGuy
strtusGuy@rediffmail.com
Below is Jps ,stutsconfig and java files and errors of browser .
<%@ page language="java" import="StudentForm" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<jsp:useBean id="sf" class="StudentForm" scope="session" >
</jsp:useBean>
<html:html>
<head>
<title><bean:message key="hello"/> </title>
</head>
<body>
<B>LOGIN PAGE <B>
<html:errors />
<html:form action="/LoginForm" focus="studentid" onsubmit="return validateStudentForm(this);">
<table>
<html:select property="passwd" >
<html:options name="sf" labelName="sf" />
</html:select>
<td>LOGIN ID</td>
<td><html:text property="student"/></td>
<td>PASSWORD</td>
<td><html:text property="passwd"/> </td>
</table>
<html:submit><bean:message key="button"/></html:submit>
<html:reset><bean:message key="reset"/></html:reset>
<html:cancel><bean:message key="cancel" /></html:cancel>
</html:form>
<html:javascript formName="studentForm" dynamicJavascript="true" staticJavascript="true"/>
<script language="Javascript1.1" src="staticJavascript.jsp"></script>
</body>
</html:html>
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.commons.beanutils.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import javax.servlet.jsp.PageContext;
// use The seSSion stuf
public class StudentAction extends Action
{
public ActionForward execute( ActionMapping map,ActionForm form, HttpServletRequest req , HttpServletResponse res) throws Exception
{
String action = req.getParameter("action");
if (action == null)
{
StudentDatabase stBase = new StudentDatabase ();
StudentForm sf= new StudentForm();
String[] str = stBase.getAllNames();
String strng ="blah" ;
sf.setPasswd(strng);
req.setAttribute("sf", sf);
ActionErrors er= new ActionErrors();
er.add(ActionErrors.GLOBAL_ERROR , new ActionError("errorRakesh"));
if(!er.empty())
{
saveErrors(req,er);
return(map.findForward("RakyError"));
}
else
return(map.findForward("RakyCancel"));
}
else
{
return(map.findForward("RakyCancel"));
}
}// end of class
}
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.*;
import org.apache.struts.validator.ValidatorForm;
public class StudentForm extends ValidatorForm
{
private int student =0;
private String passwd = null;
public StudentForm()
{
student=0;
passwd = new String();
}
public StudentForm( int student ,String passwd)
{
student=student;
passwd= passwd;
}
public int getStudent()
{
return this.student;
}
public void setStudent(int student)
{
this.student=student;
}
public String getPasswd( )
{
return this.passwd;
}
public void setPasswd(String passwd)
{
this.passwd=passwd;
}
public void reset(ActionMapping mapping ,HttpServletRequest request)
{
this.student=0;
this.passwd=null;
}
public ActionErrors validate( ActionMapping map,HttpServletRequest req)
{
ActionErrors errors=super.validate(map,req);
if(student == 0)
{
System.out.println("HELLO blah "+student);
errors.add("student", new ActionError("IDProblem"));
}
return errors;
} // end of action errors
}// end of Student from class
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<!-- This is the Struts configuration file for the rakesh application -->
<struts-config>
<!-- Form bean smust be maped here first -->
<form-beans>
<form-bean name="StudentForm" type="StudentForm"/>
</form-beans>
<!-- All Action msut be mapped here -->
<action-mappings>
<!-- Calling a jsp page through link -->
<action path="/LoginJsp" forward="/Login.jsp"/>
<action path="/LoginForm" type="StudentAction" name="StudentForm" scope="request" validate="true">
<forward name="RakySuccess" path="/Start.jsp"/>
<forward name="RakyCancel" path="/Start.jsp"/>
<forward name="RakyError" path="/Start.jsp"/>
</action>
</action-mappings>
<message-resources parameter="propertyInfo" />
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml"/>
</plug-in>
</struts-config>
propertyInfo.properties
hello=This is test page
start=This is first page of the application
info=This page stores contains text files and drop downs
error=There is problem please have a look
submit=ADD TO DATABASE
clear=Clear the Data
cancel=Cancel Button
click=Please Click to start the application
button=Login
cancel=CancelButton
reset=ResetButton
IDProblem=There is problem in id has greater value than 4 pl. recheck it
prompt.username= Please Enter the User Name by blah
prompt.password=Please enter the password by bla
errors.required={0} is required.
errors.minlength={0} cannot be less than {1} characters.
errors.maxlength={0} cannot be greater than {2} characters.
errors.invalid={0} is invalid.
errors.byte={0} must be an byte.
errors.short={0} must be an short.
errors.integer={0} must be an integer.
errors.long={0} must be an long.
errors.float={0} must be an float.
errors.double={0} must be an double.
errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is not a valid credit card number.
errors.email={0} is an invalid e-mail address.
rakeshErROR=This is first ssuccessfyl errro by blah
errorRakesh=This is type of error in jsp page
eError is
HTTP Status 500 -
________________________________________
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Cannot create iterator for StudentForm@223610
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1014)
at org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:961)
at org.apache.struts.action.RequestProcessor.processForward(RequestProcessor.java:544)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:252)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:492)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline
Re: Drop box problem please help
Posted by as as <sa...@yahoo.com>.
Hi,
Try my snippet below
I populated my jsp/form bean with values from database (dynamic)
<td>
<%
java.util.List driversList = (java.util.List)request.getAttribute("drivers");
%>
<select name="fullName" style="width:225px">
<logic:iterate id="supervisor" name="supervisors"> <option value="<bean:write name="supervisor" property ="employeeID"/>">
<bean:write name="supervisor" property ="fullName"/>
</option>
</logic:iterate>
</select>
</td>
ddd ddd <st...@rediffmail.com> wrote:
Hi All
I am new bie and learning to populate the drop box by all different ways .
1. By Collections of strings
2. By collections beans
3. Hard coding
I am unable to achieve even first way tried a lot but failed can any body suggest me where I am wrong. Also pl. suggest me how the �collection of beans� will be coded . any body has simple java nd jsp code please Post me
Manay many thanks
Regrds
StrutsGuy
strtusGuy@rediffmail.com
Below is Jps ,stutsconfig and java files and errors of browser .
LOGIN PAGE
LOGIN ID
PASSWORD
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.commons.beanutils.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import javax.servlet.jsp.PageContext;
// use The seSSion stuf
public class StudentAction extends Action
{
public ActionForward execute( ActionMapping map,ActionForm form, HttpServletRequest req , HttpServletResponse res) throws Exception
{
String action = req.getParameter("action");
if (action == null)
{
StudentDatabase stBase = new StudentDatabase ();
StudentForm sf= new StudentForm();
String[] str = stBase.getAllNames();
String strng ="blah" ;
sf.setPasswd(strng);
req.setAttribute("sf", sf);
ActionErrors er= new ActionErrors();
er.add(ActionErrors.GLOBAL_ERROR , new ActionError("errorRakesh"));
if(!er.empty())
{
saveErrors(req,er);
return(map.findForward("RakyError"));
}
else
return(map.findForward("RakyCancel"));
}
else
{
return(map.findForward("RakyCancel"));
}
}// end of class
}
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.*;
import org.apache.struts.validator.ValidatorForm;
public class StudentForm extends ValidatorForm
{
private int student =0;
private String passwd = null;
public StudentForm()
{
student=0;
passwd = new String();
}
public StudentForm( int student ,String passwd)
{
student=student;
passwd= passwd;
}
public int getStudent()
{
return this.student;
}
public void setStudent(int student)
{
this.student=student;
}
public String getPasswd( )
{
return this.passwd;
}
public void setPasswd(String passwd)
{
this.passwd=passwd;
}
public void reset(ActionMapping mapping ,HttpServletRequest request)
{
this.student=0;
this.passwd=null;
}
public ActionErrors validate( ActionMapping map,HttpServletRequest req)
{
ActionErrors errors=super.validate(map,req);
if(student == 0)
{
System.out.println("HELLO blah "+student);
errors.add("student", new ActionError("IDProblem"));
}
return errors;
} // end of action errors
}// end of Student from class
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
propertyInfo.properties
hello=This is test page
start=This is first page of the application
info=This page stores contains text files and drop downs
error=There is problem please have a look
submit=ADD TO DATABASE
clear=Clear the Data
cancel=Cancel Button
click=Please Click to start the application
button=Login
cancel=CancelButton
reset=ResetButton
IDProblem=There is problem in id has greater value than 4 pl. recheck it
prompt.username= Please Enter the User Name by blah
prompt.password=Please enter the password by bla
errors.required={0} is required.
errors.minlength={0} cannot be less than {1} characters.
errors.maxlength={0} cannot be greater than {2} characters.
errors.invalid={0} is invalid.
errors.byte={0} must be an byte.
errors.short={0} must be an short.
errors.integer={0} must be an integer.
errors.long={0} must be an long.
errors.float={0} must be an float.
errors.double={0} must be an double.
errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is not a valid credit card number.
errors.email={0} is an invalid e-mail address.
rakeshErROR=This is first ssuccessfyl errro by blah
errorRakesh=This is type of error in jsp page
eError is
HTTP Status 500 -
________________________________________
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Cannot create iterator for StudentForm@223610
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1014)
at org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:961)
at org.apache.struts.action.RequestProcessor.processForward(RequestProcessor.java:544)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:252)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:492)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam