FileDocCategorySizeDatePackage
DWRValidator.javaAPI DocExample5648Mon Jul 23 13:26:54 BST 2007org.apache.struts2.validators

DWRValidator

public class DWRValidator extends Object

Use the dwr configuration as follows :-



<dwr<
<allow<
<create creator="new" javascript="validator" class="org.apache.struts2.validators.DWRValidator"/<
<convert converter="bean" match="com.opensymphony.xwork2.ValidationAwareSupport"/<
</allow<
</dwr<


Fields Summary
private static final Log
LOG
Constructors Summary
Methods Summary
public com.opensymphony.xwork2.ValidationAwareSupportdoPost(java.lang.String namespace, java.lang.String action, java.util.Map params)


              
        HttpServletRequest req = WebContextFactory.get().getHttpServletRequest();
        ServletContext servletContext = WebContextFactory.get().getServletContext();
        HttpServletResponse res = WebContextFactory.get().getHttpServletResponse();

        Map requestParams = new HashMap(req.getParameterMap());
        if (params != null) {
            requestParams.putAll(params);
        } else {
            params = requestParams;
        }
        Map requestMap = new RequestMap(req);
        Map session = new SessionMap(req);
        Map application = new ApplicationMap(servletContext);
        Dispatcher du = Dispatcher.getInstance();
        HashMap ctx = du.createContextMap(requestMap,
                params,
                session,
                application,
                req,
                res,
                servletContext);

        try {
            Configuration cfg = du.getConfigurationManager().getConfiguration();
            ValidatorActionProxy proxy = new ValidatorActionProxy(namespace, action, ctx);
            cfg.getContainer().inject(proxy);
            proxy.prepare();
            proxy.execute();
            Object a = proxy.getAction();

            if (a instanceof ValidationAware) {
                ValidationAware aware = (ValidationAware) a;
                ValidationAwareSupport vas = new ValidationAwareSupport();
                vas.setActionErrors(aware.getActionErrors());
                vas.setActionMessages(aware.getActionMessages());
                vas.setFieldErrors(aware.getFieldErrors());

                return vas;
            } else {
                return null;
            }
        } catch (Exception e) {
            LOG.error("Error while trying to validate", e);
            return null;
        }