You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Brandon Goodin <ma...@phase.ws> on 2003/04/13 08:58:33 UTC

[ADVICE] ValidatorLookupDispatchAction...

I have combined the ValidatorLookupDispatchAction, DispatchAction,
LookupDispatchAction into one class called DispatchValidatorAction.
Basically a check is done on the parameter to see if it matches a method
first. If that fails then it does a Lookup against the key. If that fails
then then the error is thrown. Otherwise, the action method is called and
processing is completed.

Also, built into this class is the ability to perform validations using
Validator against certain methods. An associated ActionMapping class
provides a way to specify methods that will be validated and methods that
will not be validated.

For example:

<action path="/foo/myaction"
  parameter="submit"
  type="com.foo.MyAction"
  name="myForm"
  scope="request"
  validate="false"
  className="org.apache.struts.actions.DispatchValidatorMapping">
    <set-property property="validateMethod(add)"
      value="false"/>
    <set-property property="validateMethod(edit)"
      value="false"/>
    <set-property property="validateMethod(delete)"
      value="false"/>
    <forward name="success"
      path="com.foo.success"
      redirect="false"/>
    <forward name="failure"
      path="com.foo.failure"
      redirect="false"/>
</action>

If you specify a methods validation to false you can still perform the
validations by manually calling validate in your dispatch validator action
class. If you specify true then the validation will happen and redirect to
the inputForward upon failures. If the className attribute of the <action>
is not used at all then all methods except "unspecified" and "execute" will
validate and forward to inputForward upon failure.

For example:

public ActionForward add(
  ActionMapping mapping,
  ActionForm form,
  HttpServletRequest request,
  HttpServletResponse response)
  throws Exception {

  MyForm myForm = (MyForm) form;

  ActionErrors aes =
    validate(mapping,form,request,response);

  if (!aes.isEmpty()) {
    saveErrors(request,aes);
  }

  MyDAO myDAO = new MyDAO();

  cmsForm.setFoos(
  myDAO.fetchFoos(null));

  return mapping.findForward("auth");

}

I don't do javascript validation on my pages. So, I haven't spent the time
figuring out how to get the Dispatch to work "on page" for validation. But,
other than that this is all very handy for validation against different
methods and the varied requirements each method might have for validation.
Also, I default to the unspecified method if a parameter is not found in the
query string.

For example, if /foo/myAction and /foo/myAction?submit= are called they will
both default to the unspecified method. The only time an error is thrown is
when there is no matching method or there is not paramter specified in the
struts-config.xml.

Anyways, I just wanted to find out if you guys wanted me to add this as a
patch or just leave the ValidatorLookupDispatchAction as it is. I like this
solution better because it consolidates the three actions into one.

Brandon Goodin



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


RE: [ADVICE] ValidatorLookupDispatchAction...

Posted by Brandon Goodin <ma...@phase.ws>.
Uuuh... One more thing... The name is actually DispatchValidatorAction and
DispatchValidatorActionMapping :-D Sorry.. me so sorry :-))

Brandon Goodin
Phase Web and Multimedia
PO Box 85
Whitefish MT 59937
P (406) 862-2245
F (406) 862-0354
mail@phase.ws
http://www.phase.ws


-----Original Message-----
From: Brandon Goodin [mailto:mail@phase.ws]
Sent: Sunday, April 13, 2003 1:05 AM
To: Struts Developers List
Subject: RE: [ADVICE] ValidatorLookupDispatchAction...


MAN! No matter how much I proof read my emails they never come out right.
When I am writing them at 1:00 am in the morning they are always full of
wierd verbage and major typos. From my message you would think I was from
anywhere but America. :-D Sorry, for the bad grammar. But, I hope you get
the jist.

Brandon Goodin

-----Original Message-----
From: Brandon Goodin [mailto:mail@phase.ws]
Sent: Sunday, April 13, 2003 12:59 AM
To: Struts Dev
Subject: [ADVICE] ValidatorLookupDispatchAction...


I have combined the ValidatorLookupDispatchAction, DispatchAction,
LookupDispatchAction into one class called DispatchValidatorAction.
Basically a check is done on the parameter to see if it matches a method
first. If that fails then it does a Lookup against the key. If that fails
then then the error is thrown. Otherwise, the action method is called and
processing is completed.

Also, built into this class is the ability to perform validations using
Validator against certain methods. An associated ActionMapping class
provides a way to specify methods that will be validated and methods that
will not be validated.

For example:

<action path="/foo/myaction"
  parameter="submit"
  type="com.foo.MyAction"
  name="myForm"
  scope="request"
  validate="false"
  className="org.apache.struts.actions.DispatchValidatorMapping">
    <set-property property="validateMethod(add)"
      value="false"/>
    <set-property property="validateMethod(edit)"
      value="false"/>
    <set-property property="validateMethod(delete)"
      value="false"/>
    <forward name="success"
      path="com.foo.success"
      redirect="false"/>
    <forward name="failure"
      path="com.foo.failure"
      redirect="false"/>
</action>

If you specify a methods validation to false you can still perform the
validations by manually calling validate in your dispatch validator action
class. If you specify true then the validation will happen and redirect to
the inputForward upon failures. If the className attribute of the <action>
is not used at all then all methods except "unspecified" and "execute" will
validate and forward to inputForward upon failure.

For example:

public ActionForward add(
  ActionMapping mapping,
  ActionForm form,
  HttpServletRequest request,
  HttpServletResponse response)
  throws Exception {

  MyForm myForm = (MyForm) form;

  ActionErrors aes =
    validate(mapping,form,request,response);

  if (!aes.isEmpty()) {
    saveErrors(request,aes);
  }

  MyDAO myDAO = new MyDAO();

  cmsForm.setFoos(
  myDAO.fetchFoos(null));

  return mapping.findForward("auth");

}

I don't do javascript validation on my pages. So, I haven't spent the time
figuring out how to get the Dispatch to work "on page" for validation. But,
other than that this is all very handy for validation against different
methods and the varied requirements each method might have for validation.
Also, I default to the unspecified method if a parameter is not found in the
query string.

For example, if /foo/myAction and /foo/myAction?submit= are called they will
both default to the unspecified method. The only time an error is thrown is
when there is no matching method or there is not paramter specified in the
struts-config.xml.

Anyways, I just wanted to find out if you guys wanted me to add this as a
patch or just leave the ValidatorLookupDispatchAction as it is. I like this
solution better because it consolidates the three actions into one.

Brandon Goodin



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org


RE: [ADVICE] ValidatorLookupDispatchAction...

Posted by Brandon Goodin <ma...@phase.ws>.
MAN! No matter how much I proof read my emails they never come out right.
When I am writing them at 1:00 am in the morning they are always full of
wierd verbage and major typos. From my message you would think I was from
anywhere but America. :-D Sorry, for the bad grammar. But, I hope you get
the jist.

Brandon Goodin

-----Original Message-----
From: Brandon Goodin [mailto:mail@phase.ws]
Sent: Sunday, April 13, 2003 12:59 AM
To: Struts Dev
Subject: [ADVICE] ValidatorLookupDispatchAction...


I have combined the ValidatorLookupDispatchAction, DispatchAction,
LookupDispatchAction into one class called DispatchValidatorAction.
Basically a check is done on the parameter to see if it matches a method
first. If that fails then it does a Lookup against the key. If that fails
then then the error is thrown. Otherwise, the action method is called and
processing is completed.

Also, built into this class is the ability to perform validations using
Validator against certain methods. An associated ActionMapping class
provides a way to specify methods that will be validated and methods that
will not be validated.

For example:

<action path="/foo/myaction"
  parameter="submit"
  type="com.foo.MyAction"
  name="myForm"
  scope="request"
  validate="false"
  className="org.apache.struts.actions.DispatchValidatorMapping">
    <set-property property="validateMethod(add)"
      value="false"/>
    <set-property property="validateMethod(edit)"
      value="false"/>
    <set-property property="validateMethod(delete)"
      value="false"/>
    <forward name="success"
      path="com.foo.success"
      redirect="false"/>
    <forward name="failure"
      path="com.foo.failure"
      redirect="false"/>
</action>

If you specify a methods validation to false you can still perform the
validations by manually calling validate in your dispatch validator action
class. If you specify true then the validation will happen and redirect to
the inputForward upon failures. If the className attribute of the <action>
is not used at all then all methods except "unspecified" and "execute" will
validate and forward to inputForward upon failure.

For example:

public ActionForward add(
  ActionMapping mapping,
  ActionForm form,
  HttpServletRequest request,
  HttpServletResponse response)
  throws Exception {

  MyForm myForm = (MyForm) form;

  ActionErrors aes =
    validate(mapping,form,request,response);

  if (!aes.isEmpty()) {
    saveErrors(request,aes);
  }

  MyDAO myDAO = new MyDAO();

  cmsForm.setFoos(
  myDAO.fetchFoos(null));

  return mapping.findForward("auth");

}

I don't do javascript validation on my pages. So, I haven't spent the time
figuring out how to get the Dispatch to work "on page" for validation. But,
other than that this is all very handy for validation against different
methods and the varied requirements each method might have for validation.
Also, I default to the unspecified method if a parameter is not found in the
query string.

For example, if /foo/myAction and /foo/myAction?submit= are called they will
both default to the unspecified method. The only time an error is thrown is
when there is no matching method or there is not paramter specified in the
struts-config.xml.

Anyways, I just wanted to find out if you guys wanted me to add this as a
patch or just leave the ValidatorLookupDispatchAction as it is. I like this
solution better because it consolidates the three actions into one.

Brandon Goodin



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org