Announcement Announcement Module
Collapse

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions (http://www.springsource.org/extensions) project, this forum has been decommissioned in favour of Spring Extensions one at:
http://forum.springsource.org/forumdisplay.php?f=44

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Cheers,
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
See more
See less
Unable to implement server side validation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to implement server side validation

    Hi folks

    I am new to spring-modules-validation....

    And am really having tough time integerating the validation in my SimpleFormcontroller

    I am not at all seeing any validations when i submit my form....
    Can you please help me get through this....

    beans.xml
    --------------------------------
    <bean id="inboundConnector"
    class="com.novenaltd.dis.admin.controller.InConnec torController">
    <property name="configSender" ref="sender" />
    <property name="commandClass" value="com.novenaltd.dis.config.ws.InboundConnecto r"/>
    <property name="commandName" value="inboundConnector"/>
    <property name="formView" value="inconnector" />
    <property name="successView" value="redirect:viewinboundconnector.htm" />
    <property name="validator" ref="beanValidator" />
    </bean>

    <bean id="beanValidator" class="org.springmodules.validation.commons.Defaul tBeanValidator">
    <property name="validatorFactory" ref="validatorFactory" />
    </bean>


    <bean id="validatorFactory"
    class="org.springmodules.validation.commons.Defaul tValidatorFactory">
    <property name="validationConfigLocations">
    <list>
    <value>/WEB-INF/validator-rules.xml</value>
    <value>/WEB-INF/validation.xml</value>
    </list>
    </property>
    </bean>


    ------------------------------------------------
    validation.xml
    ----------------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <form-validation>
    <formset>
    <form name="inboundConnector">
    <field property="connectorUri" depends="required">
    <arg0 key="inboundConnector.connectorURI"/>
    </field>
    </form>
    </formset>
    </form-validation>

    -------------------------------------------------------------------

    Controller
    ----------------------------------------------------------------
    package com.novenaltd.dis.admin.controller;

    import java.util.HashMap;
    import java.util.Map;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.springframework.beans.propertyeditors.StringTr immerEditor;
    import org.springframework.validation.BindException;
    import org.springframework.web.bind.ServletRequestDataBin der;
    import org.springframework.web.bind.ServletRequestUtils;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.SimpleFormCont roller;

    import com.novenaltd.dis.config.cli.ConfigSender;
    import com.novenaltd.dis.config.ws.InboundConnector;
    import com.novenaltd.dis.config.ws.ProtocolType;

    public class InConnectorController extends SimpleFormController {
    private ConfigSender configSender;

    ProtocolType[] protocol ={ProtocolType.JMS, ProtocolType.HTTP, ProtocolType.FILE};
    boolean[] booleanArr = { true, false };

    public ConfigSender getConfigSender() {
    return configSender;
    }

    public void setConfigSender(ConfigSender configSender) {
    this.configSender = configSender;
    }

    protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    //super.initBinder(request, binder);
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    }
    protected Object formBackingObject(HttpServletRequest request)
    throws Exception {
    InboundConnector inConnectorForm = (InboundConnector) super
    .formBackingObject(request);
    Long inConnectorId = null;
    if((inConnectorId = ServletRequestUtils.getLongParameter(request, "id")) != null) {
    inConnectorForm = configSender.getInboundConnector(inConnectorId);
    }
    return inConnectorForm;
    }

    protected Map referenceData(HttpServletRequest request) throws Exception {
    Map referenceData = new HashMap();
    referenceData.put("protocol", protocol);
    referenceData.put("boolean", booleanArr);
    return referenceData;
    }

    protected ModelAndView onSubmit(Object command, BindException bindException)
    throws Exception {
    InboundConnector connector = (InboundConnector) command;
    configSender.saveInConnector(connector);
    return new ModelAndView(getSuccessView());
    }

    protected ModelAndView processFormSubmission(HttpServletRequest request,
    HttpServletResponse response,Object command, BindException errors)
    throws Exception {
    System.out.println(errors);
    return super.processFormSubmission(request, response, command, errors);
    }

    protected void onBindAndValidate(HttpServletRequest request,Object command, BindException errors)
    throws Exception {
    super.onBindAndValidate(request, command, errors);
    getValidator().validate(command, errors);
    System.out.println("OnBindandValidate" + errors);
    }
    }
    ---------------------------------------------------------------------
    validator-rules.xml (validator_1_0.dtd)
    -----------------------------------------------------------------
    <validator name="required"
    classname="org.springmodules.commons.validator.Fie ldChecks"
    method="validateRequired"
    methodParams="java.lang.Object,
    org.apache.commons.validator.ValidatorAction,
    org.apache.commons.validator.Field,
    org.springframework.validation.Errors"
    msg="errors.required">

    ---------------------------------------------------------

    Thanks and Regards
Working...
X