struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Husted <hus...@apache.org>
Subject Re: How to set up validation on existing page?
Date Sat, 10 Nov 2001 20:46:18 GMT
The two ActionMappings are specifying different ActionForm beans. It's
possible that only one ActionForm bean class is really needed here.
Another approach would be to specify the first ActionMapping as the
input property, e.g. input="/do/class/editClass" or
input="/class/editClass.do". 

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/struts/



"David M. Karr" wrote:
> 
> I've read the documentation, and I've looked at code examples, but I don't
> understand what I'm doing wrong.
> 
> I have an existing simple Struts application.  I have two pages (among several
> others).  The first one shows a list of student classes, each one showing a
> class name and a teacher name.  Each table row has an Edit button, which goes
> to a page to edit this class, displaying a text field for the class name, and
> an optionlist for the teacher's name.  Below the fields I have Edit and Cancel
> buttons.
> 
> This basically works.  When I edit either the class name or change to a
> different teacher name and click Save, it jumps back to the list page, showing
> the new value.
> 
> I now want to add validation, so it will detect that an empty class name has
> been entered.
> 
> My two pages are called "listClasses.jsp" and "editClass.jsp".  I have relevant
> class names "ListClassesForm", "EditClassForm", "SaveClassForm",
> "ListClassesAction", "EditClassAction", and "SaveClassAction".
> 
> Before trying to add validation, I had the following two actions in my
> "struts-config.xml":
> 
>   <action path="/class/editClass" name="editClassForm"
>                          scope="request"
>                          type="com.intsoft.sgs.web.actions.EditClassAction">
>    <forward name="success" path="/class/editClass.jsp"/>
>   </action>
>   <action path="/class/saveClass" name="saveClassForm"
>           scope="request"
>                          type="com.intsoft.sgs.web.actions.SaveClassAction">
>    <forward name="success" path="/class/listClasses.do"/>
>   </action>
> 
> So, to add validation, I thought I had to do the following:
> 
> 1. Add an "input" attribute to the SECOND action, set to
>    "/class/editClass.jsp".
> 2. Add a "validate" method to "SaveClassForm", which adds an ActionError to the
>    ActionErrors list if the name is null or empty.
> 3. Add a "<html:errors/>" tag to "editClass.jsp".
> 4. Add three resources to my properties file:
>    a. error string
>    b. errors header
>    c. errors footer
> 
> AFAIK, this is all I have to do.
> 
> What happens when I run this is as follows:
> 
> When I get to "editClass.jsp" and empty the value in the name field and click
> "Save", I get the following exception:
> 
> javax.servlet.ServletException: Cannot find bean editClassForm in scope null
>         at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:459)
>         at c_00025ass._0002fclass_0002feditClass_0002ejspeditClass_jsp_32._jspService(_0002fclass_0002feditClass_0002ejspeditClass_jsp_32.java:839)
> 
> I had put print statements in the "set" methods of "SaveClassForm", and in the
> "validate()" method.  When I clicked "Save", I saw those execute.
> 
> So, it appears as if it was trying to go back to "editClass.jsp", but it
> couldn't find the form bean.
> 
> So what could I be doing wrong?
> 
> --
> ===================================================================
> David M. Karr          ; Best Consulting
> dmkarr@earthlink.net   ; Java/Unix/XML/C++/X ; BrainBench CJ12P (#12004)
> 
> --
> 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