jsf - Using Properties from ResourceBundle in ManagedProperty -


i have jsf validator i'm building has properties in have loaded resourcebundle. however, i'm not quite sure how work this, isn't loading properly. ideas on how can make work?

i've tried using @postcontruct it, i'm getting following error in eclipse:

access restriction: type postconstruct not accessible due restriction on required library /system/library/java/javavirtualmachines/1.6.0.jdk/contents/classes/classes.jar

so, i'm not sure best way work this. sample of i'm talking below...

the validator...

@facesvalidator("usernamevalidator") public class usernamevalidator implements validator {    @managedproperty(value="#{props_usernamepattern}")   private string usernamepattern;      @managedproperty(value="#{props_minusernamelength}")   private int minusernamelength;      @managedproperty(value="#{props_maxusernamelength}")   private int maxusernamelength;    public void validate(facescontext context, uicomponent component, object         value) throws validatorexception {     //my validations here...      }    //setters class properties  } 

faces-config.xml

<resource-bundle>     <base-name>settings</base-name> </resource-bundle> 

settings.properties

props_usernamepattern = /^[a-z0-9_-]+$/ props_minusernamelength = 3 props_maxusernamelength = 30 

the @managedproperty works on @managedbean classes only. @postconstruct not correct solution functional requirement. intented placed on method executed when class has been constructed and dependency injections been finished. error you're facing caused specific combination of older eclipse+jre versions. if upgrading not option, disable warning/error window > preferences > java > compiler > errors/warnings > deprecated , restricted api > forbidden reference > ignore.

as functional requirement, unfortunately no annotation achieves comes mind. programmatically.

string bundlename = "settings"; locale locale = facescontext.getcurrentinstance().getviewroot().getlocale(); resourcebundle bundle = resourcebundle.getbundle(bundlename, locale); string usernamepattern = bundle.getstring("props_usernamepattern"); // ... 

you can in constructor of validator. when used new instance created every view anyway.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -