struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject RE: Struts 1.1b1 HTML:Form
Date Mon, 01 Jul 2002 18:25:54 GMT


On Mon, 1 Jul 2002, Jacob Hookom wrote:

> Date: Mon, 1 Jul 2002 12:32:11 -0500
> From: Jacob Hookom <hookomjj@uwec.edu>
> Reply-To: Struts Users Mailing List <struts-user@jakarta.apache.org>
> To: 'Struts Users Mailing List' <struts-user@jakarta.apache.org>
> Subject: RE: Struts 1.1b1 HTML:Form
>
> Thanks for the clarification.
>
> My thought was that struts w/should be able to accommodate pre-existing
> beans on the system for ease of generating jsp's-- without generating
> new beans that contain the same object definition and just extend from a
> different class.
>

You can do that for non-form-beans just fine.  But the decision to make
you create form beans is a very deliberate part of the design of Struts.
In a single sentence, form beans are part of the view tier in the MVC
architecture, not the model tier like a typical JavaBean that represents
data from your database.

Consider the case where you've got a bean property that is an integer
(i.e. data type is "int").  Now, this will typically get displayed as a
text entry field on your form, and you'll need to do a String->int
conversion someplace.

Now, consider what happens when the user types "1a3" instead of "123".
The user expects your app to complain about this, AND to redisplay the
value exactly the way it was typed ("1a3") so that it can be corrected.
That's the way any well-behaved GUI program behaves, and that is the way
webapps should work as well.

The Struts approach to this is that the form bean would use a String for
this property, with a rule in your validate() method to ensure that the
conversion is possible.  That way, you can live up to the user's
expectations for high quality input, and the need for the application to
validate everything sent by the client.  The actual conversion only
happens in your Action that processes the form, after validation has been
completed successfully.

As an extra added benefit, you don't have to worry about your model beans
getting scribbled on with form data that hasn't been validated yet.  That
is all hidden away n the form bean, and you only copy it out when you know
that the validation rules have all passed.

> -Jake

Craig


>
> -----Original Message-----
> From: Craig R. McClanahan [mailto:craigmcc@apache.org]
> Sent: Monday, July 01, 2002 12:06 PM
> To: Struts Users Mailing List
> Subject: Re: Struts 1.1b1 HTML:Form
>
> It is correct to say that all of the automatic Struts machinery for form
> beans only works if your bean is a subclass of ActionForm.  (In Struts
> 1.1, that includes the DynaActionForm class as well.)
>
> Craig
>
>
> On Mon, 1 Jul 2002, Jacob Hookom wrote:
>
> > Date: Mon, 1 Jul 2002 01:23:40 -0500
> > From: Jacob Hookom <hookomjj@uwec.edu>
> > Reply-To: Struts Users Mailing List <struts-user@jakarta.apache.org>
> > To: 'Struts Users Mailing List' <struts-user@jakarta.apache.org>
> > Subject: Struts 1.1b1 HTML:Form
> >
> > With struts 1.1b, the only way it will instantiate a bean for a form
> > correctly is if the bean actually extends ActionForm?  The jsp works
> > fine on my JRun server running the old release of struts.
> >
> > I’m seeing that only my forms with specialized ActionForms seem to
> work
> > correctly with 1.1b; and it’s only when I use the <html:form> tag,
> > otherwise using <form action=”/action.do”> works.
> >
> > [see below for exception thrown from <html:form>]
> >
> > If forms now require being extended from actionform, do I have to
> > basically duplicate bean logic specifically for a form on a page?
> >
> > Regards,
> > Jake Hookom
> > University of Wisconsin, Eau Claire
> >
> > Exception Thrown:
> > javax.servlet.jsp.JspException: Exception creating bean of class
> > com.dds.bean.Workspace: {1}
> > 	at
> > org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:610)
> > 	at
> >
> org.apache.jsp.workspace_0002dinsert$jsp._jspService(workspace_0002dinse
> > rt$jsp.java:302)
> > 	at
> > org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
> > 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> > 	at
> >
> org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServle
> > t.java:201)
> > 	at
> >
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
> > 	at
> > org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
> > 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> > 	at
> >
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
> > tionFilterChain.java:247)
> > 	at
> >
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
> > erChain.java:193)
> > 	at
> >
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
> > e.java:243)
> > 	at
> >
> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
> > va:566)
> > 	at
> >
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
> > 72)
> > 	at
> > org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> > 	at
> >
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
> > e.java:190)
> > 	at
> >
> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
> > va:566)
> > 	at
> >
> org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.ja
> > va:246)
> > 	at
> >
> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
> > va:564)
> > 	at
> >
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
> > 72)
> > 	at
> > org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> > 	at
> >
> org.apache.catalina.core.StandardContext.invoke(StandardContext.java:234
> > 7)
> > 	at
> >
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
> > :180)
> > 	at
> >
> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
> > va:566)
> > 	at
> >
> org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherVa
> > lve.java:170)
> > 	at
> >
> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
> > va:564)
> > 	at
> >
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
> > :170)
> > 	at
> >
> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
> > va:564)
> > 	at
> >
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468
> > )
> > 	at
> >
> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
> > va:564)
> > 	at
> >
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
> > 72)
> > 	at
> > org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> > 	at
> >
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
> > java:174)
> > 	at
> >
> org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.ja
> > va:566)
> > 	at
> >
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
> > 72)
> > 	at
> > org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
> > 	at
> >
> org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.j
> > ava:1027)
> > 	at
> >
> org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:
> > 1125)
> > 	at java.lang.Thread.run(Thread.java:536)
> >
> >
> > ---
> > Outgoing mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.371 / Virus Database: 206 - Release Date: 6/13/2002
> >
> >
>
>
> --
> To unsubscribe, e-mail:
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:struts-user-help@jakarta.apache.org>
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.371 / Virus Database: 206 - Release Date: 6/13/2002
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.371 / Virus Database: 206 - Release Date: 6/13/2002
>
>
>
> --
> To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message