我有一个JSF验证器,我正在构建它的属性,我想从ResourceBundle加载。但是,我不太清楚如何处理这个问题,因为它没有正确加载。关于如何使这项工作的任何想法?在ManagedProperty中使用来自ResourceBundle的属性
我使用@PostContruct
做尝试,但我发现在Eclipse以下错误:
访问限制:该类型 PostConstruct不上所需的库 由于 限制访问/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
所以,我也不太清楚什么是最好的方式来解决这个。下面我说一下什么是样本...
验证器...
@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 for the 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
谢谢!我实现了你的解决方案,它完美的工作! – mikesir87 2011-04-11 18:47:59
不客气。 – BalusC 2011-04-11 18:48:35