我想从enum
中的java script
检查托管bean中设置的JSF
值。我怎么能这样做?
我的JSF有类似下面的内容。
<script language="javascript">
function displayMsg() {
setwindowOverlayPos('popup_window', - 100, - 150);
}
window.onload = function () {
// this is the enum value I want to check. if the value is cust1 , I call the popup window.
var cust1= '#{myBean.customerType.custType == "cust1"}';
if(cust1){
displayMsg();
}
}
</script>
我有客户类型的枚举
public enum CustomerTypeEnum {
CUST1("CUST1"),
CUST2("CUST2");
private String custType;
private CustomerTypeEnum(String s) {
custType = s;
}
/**
* @return customer type
*/
public String CustomerTypeEnum() {
return custType;
}
}
我的托管bean有
@ManagedBean(name = "home")
@ViewScoped
public class HomeBean extends BaseOrderStepBean {
private CustomerTypeEnum customerType;
public void method1(){
customerType = CustomerTypeEnum.CUST1;
}
}
答案 0 :(得分:0)
我写这篇文章是为了别人的利益。我解决了这个问题。只需要像下面那样更改javascript。
var od = '#{MyBean.customerType.custType == "OD"}';
var alreadyHasIC = '#{sessionBean.icNumber}'
if ("true" == od) {
if(!alreadyHasIC){
displayMyForm();
}
}
这意味着可以像这样从Java脚本访问Bean的Enum。