struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <j...@apache.org>
Subject [jira] Updated: (STR-2904) Problem during loading multiple validation files
Date Wed, 21 Mar 2007 06:07:51 GMT

     [ https://issues.apache.org/struts/browse/STR-2904?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Henri Yandell updated STR-2904:
-------------------------------

    Comment: was deleted

> Problem during loading multiple validation files
> ------------------------------------------------
>
>                 Key: STR-2904
>                 URL: https://issues.apache.org/struts/browse/STR-2904
>             Project: Struts 1
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.2.9
>         Environment: System: Windows XP (Version 2002 - Service Pack 2)
> App Server: Tomcat 5.5.9
> Struts Version: 1.2.9
>            Reporter: Felipe Desiderati e Souza
>             Fix For: 1.4.0
>
>
> There is a feature in the Struts (1.x) that allows the user to define multiples struts
configuration files (struts-config.xml) without use modules. To do this, the user must define
a list of files separated by comma in the "config" parameter inside the web.xml file, as you
can see:
> <servlet>
>    <servlet-name>action</servlet-name>
>    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
>    <init-param>
> 	<param-name>config</param-name>
> 	<param-value>/WEB-INF/struts-config.xml,/WEB-INF/struts-config-2.xml,/WEB-INF/struts-config-3.xml,/WEB-INF/struts-config-4.xml</param-value>
>    </init-param>
>    ...
> </servlet>
> So here comes the problem. If the user defines for each of them a separated validation
configuration file, i.e., the file /WEB-INF/struts-config.xml has: 
> ...
> <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
>     <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validator.xml"
/>
> </plug-in>
> ...
> And the file /WEB-INF/struts-config-2.xml has:
> ...
> <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
>     <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validator-2.xml"
/>
> </plug-in>
> ...
> And so on. Then, after the bootstrap, only the last validation configuration file was
loaded. So, all others files was discarted. This occurs because after each initialization
of the struts config file, the ValidatorPlugin reset the resources in the servlet context.
As you can see in the follow piece of code:
> ...
> this.initResources();
> servlet.getServletContext().setAttribute(VALIDATOR_KEY + config.getPrefix(),  resources);
> ...
> I guess to solve this problem we first need to verify if the resources stored in the
servlet context has any value. If yes, instead of reset the new value, we have to add the
constants, formsets and actions (from the new resouce readed) to previous resources stored.
> Something like this:
> ...
> this.initResources();
> ValidatorResources resources = (ValidatorResources) servlet.getServletContext().getAttribute(VALIDATOR_KEY
+ config.getPrefix());
> if (resources != null) {
>    // Copy constants from previous resources.
>    for (Iterator i = this.resources.getConstants().keySet().iterator(); i.hasNext();)
{
>       String name = (String) i.next();
>       resources.addConstant(name, (String) this.resources.getConstants().get(name));
>    }
>    // Copy validator actions from previous resources.
>    for (Iterator i = this.resources.getActions().values().iterator(); i.hasNext();) {
>       ValidatorAction action = (ValidatorAction) i.next();
>       resources.addValidatorAction(action);
>    }
>    // Copy form sets from previous resources.
>    for (Iterator i = this.resources.getFormSets().values().iterator(); i.hasNext();)
{
>       FormSet formSet = (FormSet) i.next();
>       resources.addFormSet(formSet);
>    }
>    this.resources = resources;
> }
> servlet.getServletContext().setAttribute(VALIDATOR_KEY + config.getPrefix(), this.resources);
> servlet.getServletContext().setAttribute(STOP_ON_ERROR_KEY + '.' + config.getPrefix(),
(this.stopOnFirstError ? Boolean.TRUE : Boolean.FALSE));
> ...
> But here comes another problem. The methods [getFormSets(), getActions(), getConstants()]
are protected. So to do this we have to:
> 1) Put those methods as public. But they are in another apache project.
> 2) Create a subclass of ValidatorResources exposing other three methods that are public
and return each specified value. One for form set, other for validation action and other for
constant.
> 3) Think in another approach.
> Felipe.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message