目前我的render属性中有一些条件来决定是否显示复选框。相反,我希望用条件来指示复选框是可单击还是显示为灰色(表示用户没有单击它的权限)。
我对JSF完全是个新手。
试试这样
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@ManagedBean
@ViewScoped
public class MyMB implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private boolean disabledCheckbox = false;
public void toggle(){
this.disabledCheckbox = !this.disabledCheckbox;
}
public boolean isDisabledCheckbox() {
return disabledCheckbox;
}
public void setDisabledCheckbox(boolean disabledCheckbox) {
this.disabledCheckbox = disabledCheckbox;
}
}
和
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form>
<p:panel>
<h:selectBooleanCheckbox id="cb" disabled="#{myMB.disabledCheckbox}"
value="#{true}" />
<p:commandButton action="#{myMB.toggle}" update="cb" />
</p:panel>
</h:form>
</h:body>
</html>