struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Raffy_L...@ffic.com
Subject RE: Validator problem (or user problem... not sure which yet)
Date Wed, 19 Jun 2002 20:28:56 GMT

Lot's of stuff in your action class, but I see that you defined a
DynaValidatorForm in your <form-bean> but you are casting it as a
DynaActionForm in your action class...if you cast it correctly as a
DynaValidatorForm and then invoke the validate() method (like in my
previous email), it might correct the problem...try it...





wbchmura@Ensign-BickfordInd.com on 06/19/2002 01:24:28 PM

Please respond to "Struts Users Mailing List"
      <struts-user@jakarta.apache.org>

To:   struts-user@jakarta.apache.org
cc:
Subject:  RE: Validator problem (or user problem... not sure which yet)



Here is everything:

Thanks in advance for any solutions!


Struts-config.xml
============================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD
Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<data-sources><data-source key="MySql"><set-property
property="autoCommit" value="false" /><set-property
property="description" value="MySql" /><set-property
property="driverClass" value="org.gjt.mm.mysql.Driver" /><set-property
property="maxCount" value="4" /><set-property property="minCount"
value="2" /><set-property property="password" value="vuud"
/><set-property property="user" value="vuud" /><set-property
property="url" value="jdbc:mysql://localhost/plantsecurity"
/></data-source></data-sources>
<form-beans>
<form-bean name="formNewRequest"
type="org.apache.struts.validator.DynaValidatorForm" dynamic="true">
<form-property name="employeeFirstName" type="java.lang.String"
initial="" />
<form-property name="employeeLastName" type="java.lang.String"
initial="" />
<form-property name="contactInfo" type="java.lang.String" initial="" />
<form-property name="vendorCompanyName" type="java.lang.String"
initial="" />
<form-property name="vendorEmployeeName" type="java.lang.String"
initial="" />
<form-property name="startDate" type="java.lang.String" initial="" />
<form-property name="endDate" type="java.lang.String" initial="" />
<form-property name="campus" type="java.lang.String" initial="Simsbury"
/>
<form-property name="accessAreas" type="java.lang.String" initial="" />
<form-property name="notes" type="java.lang.String" initial="" />
</form-bean>

</form-beans>

<action-mappings>
<action path="/index" parameter="" unknown="true"
forward="plantsec.mainmenu"><forward name="success"
path="plantsec.mainmenu" redirect="false" /></action>
<action path="/todo" parameter="" forward="plantsec.todo" />

<action path="/createNew" parameter=""
type="com.ebind.plantsec.create.actionCreateNew"
name="formNewRequest"
validate="true"
input="plantsec.create.new"
scope="request">

<forward name="continue" path="plantsec.create.new" redirect="false" />
<forward name="success" path="plantsec.mainmenu" redirect="false" />
</action>

<action path="/search" parameter=""
type="com.ebind.plantsec.search.actionSearch" />
<action path="/search1w" parameter="7"
type="com.ebind.plantsec.search.actionSearch" />
<action path="/search2w" parameter="14"
type="com.ebind.plantsec.search.actionSearch" />
<action path="/search4w" parameter="28"
type="com.ebind.plantsec.search.actionSearch" />
<action path="/searchAllFuture" parameter="AllFuture"
type="com.ebind.plantsec.search.actionSearch" />
<action path="/searchAllPast" parameter="AllPast"
type="com.ebind.plantsec.search.actionSearch" />

</action-mappings>

<controller
processorClass="org.apache.struts.tiles.TilesRequestProcessor" />

<message-resources parameter="ApplicationResources" />
<!-- ========== Message Resources Definitions
=========================== -->


<!-- ========== Plug Ins Configuration
================================== -->
<message-resources
parameter="org.apache.struts.webapp.validator.ApplicationResources,Appli
cationResources.properties" />

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validator.xml" />
</plug-in>

</struts-config>

============================

Validator.xml
============================
<form-validation>
   <global>
   </global>
   <formset>

   <form name="formNewRequest">

         <field property="employeeFirstName"
             depends="required">
               <arg0 key="registrationForm.firstname.displayname"/>
         </field>

         <field property="employeeLastName"
             depends="required">
               <arg0 key="registrationForm.firstname.displayname"/>
         </field>

         <field property="vendorCompanyName"
             depends="required">
               <arg0 key="registrationForm.firstname.displayname"/>
         </field>

         <field property="contactName"
             depends="required">
               <arg0 key="registrationForm.firstname.displayname"/>
         </field>

         <field property="accessAreas"
             depends="required">
               <arg0 key="registrationForm.firstname.displayname"/>
         </field>
    </form>
   </formset>
</form-validation>






============================

actionCreateNew.java
============================
package com.ebind.plantsec.create;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.*;
import java.util.Locale;
import java.util.Vector;
import java.util.ArrayList;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.ParsePosition;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.util.MessageResources;
import com.ebind.plantsec.visitors.*;
import javax.sql.*;
import com.ebind.plantsec.database.*;
import org.apache.struts.action.DynaActionForm;

/**
 *
 */
public final class actionCreateNew extends Action {


    public ActionForward perform(ActionMapping mapping,
                     ActionForm form,
                     HttpServletRequest request,
                     HttpServletResponse response)
     throws IOException, ServletException {

        HttpSession session = request.getSession();
        DynaActionForm myForm = (DynaActionForm) form;

        System.out.println("ActionCreateNew: >" +
myForm.get("employeeLastName") + "<");


        // Now we want to make a plantvisit bean and move all the data
into it
        if (myForm.get("employeeLastName") == null ||
"".equals(myForm.get("employeeLastName"))) {

            System.out.println("ELN not set");
            return (mapping.findForward("continue"));
        }

        beanVisitorRequest vreq = new beanVisitorRequest();


        // Set the required fields (already been checked to see if they
are present)
        vreq.setEmployeeLastName
((String)myForm.get("employeeLastName"));
        vreq.setEmployeeFirstName
((String)myForm.get("employeeFirstName"));
        vreq.setEmployeeContactInfo ((String)myForm.get("contactInfo"));
        vreq.setVendorCompanyName
((String)myForm.get("vendorCompanyName"));
        vreq.setAccessAreas         ((String)myForm.get("accessAreas"));
        vreq.setCampus              ((String)myForm.get("campus"));
        vreq.setStartDate           ((String)myForm.get("startDate"));
        vreq.setEndDate             ((String)myForm.get("endDate"));

        // Optional Fields
        if (myForm.get("contactInfo") != null) {

vreq.setEmployeeContactInfo((String)myForm.get("contactInfo"));
        }

        if (myForm.get("vendorEmployeeName") != null) {

vreq.setVendorEmployeeName((String)myForm.get("vendorEmployeeName"));
        }

        if (myForm.get("notes") != null) {
            vreq.setNote((String)myForm.get("notes"));
        }

        ActionMessages amsgs = new ActionMessages();

        // Now we are going to save the dang thing
        javax.sql.DataSource ds = null;

        try {
            ds = (DataSource)
servlet.getServletContext().getAttribute("MySql");
            daoMySql db = new daoMySql(ds);
            db.setVisitorRequest(vreq);

        }
        catch (Exception e)
        {
            System.out.println("Exception " + e);
            e.printStackTrace();

            ActionMessage am = new
ActionMessage("create.error.addingrecord");
            amsgs.add(ActionMessages.GLOBAL_MESSAGE,am);
            saveMessages(request, amsgs);
            return (mapping.findForward("continue"));
        }
        ActionMessage am = new ActionMessage("newrequest.addedrecord");
        amsgs.add(ActionMessages.GLOBAL_MESSAGE,am);
        saveMessages(request, amsgs);
        return (mapping.findForward("success"));
    }

    private Date convertToDate (String value) {
        SimpleDateFormat formatter = new SimpleDateFormat
("MM/dd/yyyy");
        ParsePosition pos = new ParsePosition(0);
        Date newDate = formatter.parse(value,pos);
        return (newDate);
   }
}
============================



-----Original Message-----
From: Raffy.Lata [mailto:Raffy_Lata@ffic.com]
Sent: Wednesday, June 19, 2002 4:08 PM
To: struts-user
Subject: RE: Validator problem (or user problem... not sure which yet)



you'll need to post you action class's code as well.





wbchmura@Ensign-BickfordInd.com on 06/19/2002 01:06:19 PM

Please respond to "Struts Users Mailing List"
      <struts-user@jakarta.apache.org>

To:   struts-user@jakarta.apache.org
cc:
Subject:  RE: Validator problem (or user problem... not sure which yet)



I really thought that was going to fix it...

Still have the exact same problem!


<form-beans>
<form-bean name="formNewRequest"
type="org.apache.struts.validator.DynaValidatorForm" dynamic="true">
<form-property name="employeeFirstName" type="java.lang.String"
initial="" />
<form-property name="employeeLastName" type="java.lang.String"
initial="" />
<form-property name="contactInfo" type="java.lang.String" initial="" />
<form-property name="vendorCompanyName" type="java.lang.String"
initial="" />
<form-property name="vendorEmployeeName" type="java.lang.String"
initial="" />
<form-property name="startDate" type="java.lang.String" initial="" />
<form-property name="endDate" type="java.lang.String" initial="" />
<form-property name="campus" type="java.lang.String" initial="Simsbury"
/>
<form-property name="accessAreas" type="java.lang.String" initial="" />
<form-property name="notes" type="java.lang.String" initial="" />
</form-bean>

</form-beans>

<action-mappings>
<action path="/index" parameter="" unknown="true"
forward="plantsec.mainmenu"><forward name="success"
path="plantsec.mainmenu" redirect="false" /></action>
<action path="/todo" parameter="" forward="plantsec.todo" />
<action path="/createNew" parameter=""
type="com.ebind.plantsec.create.actionCreateNew" name="formNewRequest"
validate="true"
input="plantsec.create.new"
scope="request"><forward name="continue"
path="plantsec.create.new"
redirect="false" /><forward name="success" path="plantsec.mainmenu"
redirect="false" /></action>

-----Original Message-----
From: Raffy.Lata [mailto:Raffy_Lata@ffic.com]
Sent: Wednesday, June 19, 2002 3:49 PM
To: struts-user
Subject: RE: Validator problem (or user problem... not sure which yet)



have you tried setting validate="true" in your action?

like,

action path="/createNew" parameter=""
type="com.ebind.plantsec.create.actionCreateNew" name="formNewRequest"
input="plantsec.create.new" scope="request" validate="true"><forward
name
="continue"
path="plantsec.create.new" redirect="false" /><forward name="success"
path="plantsec.mainmenu" redirect="false" /></action>


or invoke the validate method inside the action's execute() method

like,

errors = ((DynaValidatorForm)form).validate(mapping,request);
        if (!errors.empty()) {
           saveErrors(request, errors);
           return new ActionForward(mapping.getInput());
        }

???




wbchmura@Ensign-BickfordInd.com on 06/19/2002 12:46:39 PM

Please respond to "Struts Users Mailing List"
      <struts-user@jakarta.apache.org>

To:   struts-user@jakarta.apache.org
cc:
Subject:  RE: Validator problem (or user problem... not sure which yet)



tried that... Still ignoring me...


-----Original Message-----
From: william.wws [mailto:william_wws@hotmail.com]
Sent: Wednesday, June 19, 2002 3:21 PM
To: struts-user
Subject: Re: Validator problem (or user problem... not sure which yet)



Try to do something like this

<form-bean name="myForm" dynamic="true"
type="org.apache.struts.validator.DynaValidatorForm">

Don't forget the dynamic="true"

William.


>From: wbchmura@Ensign-BickfordInd.com
>Reply-To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
>To: struts-user@jakarta.apache.org
>Subject: Validator problem (or user problem... not sure which yet)
>Date: Wed, 19 Jun 2002 15:23:43 -0400
>
>
>As I feared I am having trouble with the same spot I was having before:
>I have the DynaActionForm working well enough.  It passes through to
the
>action fine, and all my data appears to be there.
>
>However, when I try to do validation with it by declaring my form bean
>as org.apache.struts.validator.DynaValidatorForm or
>DynaValidatorActionForm it does absolutely nothing validation wise.  It
>cruises right through to my action...
>
>-----
>Here is what my struts-config.xml looks like:
>
><form-bean name="formNewRequest"
>type="org.apache.struts.validator.DynaValidatorActionForm">
><set-property property="dynamic" value="true" /><form-property
>name="employeeFirstName" type="java.lang.String" initial=""
>/><form-property name="employeeLastName" type="java.lang.String"
>initial="" /><form-property name="contactInfo" type="java.lang.String"
>initial="" /><form-property name="vendorCompanyName"
>type="java.lang.String" initial="" /><form-property
>name="vendorEmployeeName" type="java.lang.String" initial=""
>/><form-property name="startDate" type="java.lang.String" initial=""
>/><form-property name="endDate" type="java.lang.String" initial=""
>/><form-property name="campus" type="java.lang.String"
>initial="Simsbury" /><form-property name="accessAreas"
>type="java.lang.String" initial="" /><form-property name="notes"
>type="java.lang.String" initial="" /></form-bean>
>
><action path="/createNew" parameter=""
>type="com.ebind.plantsec.create.actionCreateNew" name="formNewRequest"
>input="plantsec.create.new" scope="request"><forward name="continue"
>path="plantsec.create.new" redirect="false" /><forward name="success"
>path="plantsec.mainmenu" redirect="false" /></action>
>
>----------------------------------------------
>
>My validator.xml looks like so:
>
>    <formset>
>    <form name="formNewRequest">
>          <field property="employeeFirstName"
>                 depends="required">
>                   <arg0
key="registrationForm.firstname.displayname"/>
>          </field>
>     </form>
>     </formset>
>
>-
>
>
>
>-----Original Message-----
>From: william.wws [mailto:william_wws@hotmail.com]
>Sent: Wednesday, June 19, 2002 1:56 PM
>To: struts-user
>Subject: Re: Validator problem (or user problem... not sure which yet)
>
>
>
>Why don't you use DynaActionForm ? I don't have problem to use the
>validate
>with DynaActionForms !
>William.
>
> >From: wbchmura@Ensign-BickfordInd.com
> >Reply-To: "Struts Users Mailing List"
<struts-user@jakarta.apache.org>
> >To: struts-user@jakarta.apache.org
> >Subject: Validator problem (or user problem... not sure which yet)
> >Date: Wed, 19 Jun 2002 13:42:49 -0400
> >
> >
> >Hiya,
> >
> >
> >I am having trouble getting validator to work under 1.1b (I never
used
> >it before).
> >
> >I have the plug in defined, I have the validator.xml set up with my
>form
> >name like so:
> >
> ><form  name="formNewRequest">
> >  <field    property="value(employeeFirstName)"
> >         depends="required">
> >                 <arg0
>key="registrationForm.firstname.displayname"/>
> ></field>
> ></form>
> >
> >Notice the property?  Can I do this?  My bean has a setValue( ) and
> >getValue( ) method that I work with.
> >
> >The result of this is nothing.  It returns back to the form page, but
> >that could be because of my normal validate routine
> >
> >The other strange thing is that although it calls my validate method
in
> >my formbean any error messages disappear off into the bit bucket...
> >
> >Should I just migrate to dynaforms?  Would that be best?
> >
> >Thanks
> >
> >Bill
> >
> >
> >--
> >To unsubscribe, e-mail:
> ><mailto:struts-user-unsubscribe@jakarta.apache.org>
> >For additional commands, e-mail:
> ><mailto:struts-user-help@jakarta.apache.org>
>
>
>
>
>_________________________________________________________________
>Chat with friends online, try MSN Messenger: http://messenger.msn.com
>
>
>--
>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>
>




_________________________________________________________________
Get your FREE download of MSN Explorer at
http://explorer.msn.com/intl.asp.


--
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>






**********************************************************************
Please Note:
The information in this E-mail message, and any files transmitted
with it, is confidential and may be legally privileged.  It is
intended only for the use of the individual(s) named above.  If you
are the intended recipient, be aware that your use of any confidential
or personal information may be restricted by state and federal
privacy laws.  If you, the reader of this message, are not the
intended recipient, you are hereby notified that you should not
further disseminate, distribute, or forward this E-mail message.
If you have received this E-mail in error, please notify the sender
and delete the material from any computer.  Thank you.
**********************************************************************




--
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>






**********************************************************************
Please Note:
The information in this E-mail message, and any files transmitted
with it, is confidential and may be legally privileged.  It is
intended only for the use of the individual(s) named above.  If you
are the intended recipient, be aware that your use of any confidential
or personal information may be restricted by state and federal
privacy laws.  If you, the reader of this message, are not the
intended recipient, you are hereby notified that you should not
further disseminate, distribute, or forward this E-mail message.
If you have received this E-mail in error, please notify the sender
and delete the material from any computer.  Thank you.
**********************************************************************




--
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>






**********************************************************************
Please Note:
The information in this E-mail message, and any files transmitted
with it, is confidential and may be legally privileged.  It is
intended only for the use of the individual(s) named above.  If you
are the intended recipient, be aware that your use of any confidential
or personal information may be restricted by state and federal
privacy laws.  If you, the reader of this message, are not the
intended recipient, you are hereby notified that you should not
further disseminate, distribute, or forward this E-mail message.
If you have received this E-mail in error, please notify the sender
and delete the material from any computer.  Thank you.
**********************************************************************




--
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