You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Schmitz, Jeffrey A" <Je...@boeing.com> on 2010/02/18 20:40:19 UTC

Validator ?s

Hello,
   In the validator documentation is states the following:

As an alternative for fd:java, you can also add validators at run time to a form instance, using the addValidator method on a form or widget. Since you then instantiate the validator yourself, you can pass it anything you want, and it can be stateful.

However, it doesn't really say where in the cocoon ecosystem this injection of a validator needs to occur.  Can anyone provide specifics on this?  E.g. is this done somewhere in the flowscript?

Also, I've tried following the instructions for added a java validtor using fd:java, but it's not getting triggered.  Below is my code, any ideas why it doesn't seem to be working?

    <fd:field id="name" required="true">
      <fd:label>Name:</fd:label>
      <fd:datatype base="string"/>
      <fd:validation>
        <fd:length min="2"/>
      </fd:validation>
      <fd:validation>
         <fd:java class="com.boeing.ssp.cforms.LoginValidator"/>
         <fd:failmessage>User does not exist.</fd:failmessage>
       </fd:validation>
    </fd:field>

package com.boeing.ssp.cforms;

import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.cocoon.forms.formmodel.Widget;
import org.apache.cocoon.forms.validation.WidgetValidator;

import com.boeing.mifssp.CFormUtils;

public class LoginValidator extends AbstractLogEnabled  implements WidgetValidator {

          /**
     * @see org.apache.cocoon.forms.validation.WidgetValidator#validate(org.apache.cocoon.forms.formmodel.Widget)
     */
    public boolean validate(Widget widget) {
      String loginStrs[] = new String[1];
      getLogger().info("Validating user " + (String) widget.getValue());

          loginStrs[0] = (String) widget.getValue();
          boolean goodLogin = CFormUtils.submitIfQuery("loginCheck", "ivhm", "ModelManagement", null, null, loginStrs);
      return goodLogin;
    }
}

Thanks,
Jeff




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: Validator ?s

Posted by Gary Larsen <ga...@envisn.com>.
Hi Jeff,

I think the error condition needs to be set in the validator:

((ValidationErrorAware)widget).setValidationError(new
ValidationError("date_selection_error", true));

Hope that's what you're looking for.  There are a few constructors - this
one uses i18n.

gary

> -----Original Message-----
> From: Schmitz, Jeffrey A [mailto:Jeffrey.A.Schmitz@boeing.com]
> Sent: Thursday, February 18, 2010 2:40 PM
> To: users@cocoon.apache.org
> Subject: Validator ?s
> 
> Hello,
>    In the validator documentation is states the following:
> 
> As an alternative for fd:java, you can also add validators at run time to
> a form instance, using the addValidator method on a form or widget. Since
> you then instantiate the validator yourself, you can pass it anything you
> want, and it can be stateful.
> 
> However, it doesn't really say where in the cocoon ecosystem this
> injection of a validator needs to occur.  Can anyone provide specifics on
> this?  E.g. is this done somewhere in the flowscript?
> 
> Also, I've tried following the instructions for added a java validtor
> using fd:java, but it's not getting triggered.  Below is my code, any
> ideas why it doesn't seem to be working?
> 
>     <fd:field id="name" required="true">
>       <fd:label>Name:</fd:label>
>       <fd:datatype base="string"/>
>       <fd:validation>
>         <fd:length min="2"/>
>       </fd:validation>
>       <fd:validation>
>          <fd:java class="com.boeing.ssp.cforms.LoginValidator"/>
>          <fd:failmessage>User does not exist.</fd:failmessage>
>        </fd:validation>
>     </fd:field>
> 
> package com.boeing.ssp.cforms;
> 
> import org.apache.avalon.framework.logger.AbstractLogEnabled;
> import org.apache.cocoon.forms.formmodel.Widget;
> import org.apache.cocoon.forms.validation.WidgetValidator;
> 
> import com.boeing.mifssp.CFormUtils;
> 
> public class LoginValidator extends AbstractLogEnabled  implements
> WidgetValidator {
> 
>           /**
>      * @see
> org.apache.cocoon.forms.validation.WidgetValidator#validate(org.apache.coc
> oon.forms.formmodel.Widget)
>      */
>     public boolean validate(Widget widget) {
>       String loginStrs[] = new String[1];
>       getLogger().info("Validating user " + (String) widget.getValue());
> 
>           loginStrs[0] = (String) widget.getValue();
>           boolean goodLogin = CFormUtils.submitIfQuery("loginCheck",
> "ivhm", "ModelManagement", null, null, loginStrs);
>       return goodLogin;
>     }
> }
> 
> Thanks,
> Jeff
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org