查看Omnifaces importConstants。它應該爲你做所有的工作。
http://showcase.omnifaces.org/taghandlers/importConstants
從omnifaces例如採取...
Managed Bean的
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.omnifaces.showcase.model.ExampleEnum;
@ManagedBean
@RequestScoped
public class ConstantsBean {
public static final String CONSTANT1 = "Constant one";
public static final String CONSTANT2 = "Constant two";
private ExampleEnum exampleEnum;
public ExampleEnum getExampleEnum() {
return exampleEnum;
}
public void setExampleEnum(ExampleEnum exampleEnum) {
this.exampleEnum = exampleEnum;
}
}
ExampleEnum
public enum ExampleEnum {
ONE, TWO, THREE;
public String getFriendlyName() {
return name().charAt(0) + name().substring(1).toLowerCase();
}
}
在XHTML
使用示例
<o:importConstants type="org.omnifaces.showcase.taghandlers.ConstantsBean" />
<o:importConstants type="org.omnifaces.showcase.model.ExampleEnum" />
<h3>All constants of <code>ConstantsBean</code></h3>
<ul>
<li>#{ConstantsBean.CONSTANT1}</li>
<li>#{ConstantsBean.CONSTANT2}</li>
</ul>
<hr />
<h3>All values of <code>ExampleEnum</code></h3>
<ul>
<li>#{ExampleEnum.ONE}</li>
<li>#{ExampleEnum.TWO}</li>
<li>#{ExampleEnum.THREE}</li>
</ul>