struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Hermann <therm...@mtg.de>
Subject Re: Validation with DefaultActionValidatorManager throws NullPointerExeption
Date Wed, 26 Feb 2014 15:59:13 GMT
Am 26.02.2014 13:48, schrieb Lukasz Lenart:
> 2014-02-26 13:35 GMT+01:00 Thomas Hermann <thermann@mtg.de>:
>> Hello,
>>
>> In a JUnit-Test and in a Ajax-Server I try to validate an Object with
>> com.opensymphony.xwork2.validator.DefaultActionValidatorManager (Version
>> 2.3.15.3).
>>
>> The MyObject-validation.xml file is provided in the same directory as the
>> MyObject-Class (no action alias used).
>>
>> I instantiate the validator manually with the new operator because the
>> ActionValidatorManagerFactory is no longer supported in the version
>> 2.3.15.3:
>>
>> --------------------------------------
>> DefaultActionValidatorManager validator = new
>> DefaultActionValidatorManager();
>> validator.validate(myObject, null);
>> --------------------------------------
>>
>> but at runtime I get a NullPointerException:
>>
>> --------------------------------------
>> java.lang.NullPointerException
>>      at
>> com.opensymphony.xwork2.validator.DefaultActionValidatorManager.loadFile(DefaultActionValidatorManager.java:342)
>>      at
>> com.opensymphony.xwork2.validator.DefaultActionValidatorManager.buildClassValidatorConfigs(DefaultActionValidatorManager.java:245)
>>      at
>> com.opensymphony.xwork2.validator.DefaultActionValidatorManager.buildValidatorConfigs(DefaultActionValidatorManager.java:324)
>>      at
>> com.opensymphony.xwork2.validator.DefaultActionValidatorManager.buildValidatorConfigs(DefaultActionValidatorManager.java:305)
>>      at
>> com.opensymphony.xwork2.validator.DefaultActionValidatorManager.buildValidatorConfigs(DefaultActionValidatorManager.java:305)
>>      at
>> com.opensymphony.xwork2.validator.DefaultActionValidatorManager.getValidators(DefaultActionValidatorManager.java:93)
>>      at
>> com.opensymphony.xwork2.validator.DefaultActionValidatorManager.validate(DefaultActionValidatorManager.java:127)
>>      at
>> com.opensymphony.xwork2.validator.DefaultActionValidatorManager.validate(DefaultActionValidatorManager.java:119)
>>      at
>> com.opensymphony.xwork2.validator.DefaultActionValidatorManager.validate(DefaultActionValidatorManager.java:114)
>> --------------------------------------
>>
>> The problem seems to be caused by the fileManager, that is set to NULL.
>>
>> Has anyone an idea how to solve the problem?
>> How is the DefaultActionValidatorManager used correctly?
> You must inject FileManagerFactory - manually via setter (new
> DefaultFileManagerFactory()) - but as far I understand you use
> DefaultActionValidatorManager outside struts, right? If in struts
> action, you can use @Inject to inject proper instance.
>
>
> Regards

Do you simply mean:

-------------------------------------------------
DefaultActionValidatorManager validator = new 
DefaultActionValidatorManager();
validator.setFileManagerFactory(new DefaultFileManagerFactory());
validator.validate(request, null);
--------------------------------------------------
?

The DefaultFileManagerFactory is not instantiated properly. I get the 
following exception now:

---------------------------------------------------
java.lang.NullPointerException
     at 
com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory.lookupFileManager(DefaultFileManagerFactory.java:57)
     at 
com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory.getFileManager(DefaultFileManagerFactory.java:41)
     at 
com.opensymphony.xwork2.validator.DefaultActionValidatorManager.setFileManagerFactory(DefaultActionValidatorManager.java:73)
---------------------------------------------------

Isn't there an easy way to initialize the DefaultActionValidatorManager 
properly?

Thanks,
Thomas




Mime
View raw message