java - Can classes that extend Struts2/XWork ValidatorSupport have state -


if extend validatorsupport class in struts 2 can have instance variables on class? can have state or have stateless?

i know action classes aren't singletons , can have state i'm not sure associated validators.

i need know if can have instance variable within validator extends validatorsupport. example:

public class somevalidator extends validatorsupport {     private boolean alreadyhaserroronpage;  } 

if validators signlestons, using alreadyhaserroronpage since result in race condition , never consistent default state each request/response. if aren't singletons , new somevalidator instance created each request/response using alreadyhaserroronpage safe.

take following grain of salt because i'm not sure how of related project i'm working on.

validators singles on our project. went in , debugged application , found instance members not @ default state after second request/response. carry on value first or previous request/response.

the reason i'm still not sure because our project seems have wrapped , validatorsuppport , exposed interface our validators implement. within our codebase there seems code stores instance of validators in map making them singletons. haven't been able determine if stock struts2 behaves in same manner.

they should have state, because state subject validate, should set validator before it's executed. validator instance should built same way actions in struts2.

the object passed validator via validate method. has signature

void validate(object object) throws validationexception;   

generally object action instance can validate in method implementation. validator instance built via validator factory. 1 used object factory build validator , inject container if there available injectors. object factory, ever implementation use, create new instance , return it. so, each time use validator factory build validator new instance created. might seen validator has properties such message, messagekey, messageparameters, etc. these properties define state of validator. can extend validatorsupport custom properties without fear. because new instance of validator created each time per validation, it's thread safe.

can have state or have stateless?

it's has state, stateless bean doesn't have public properties.


Comments