这个功能要是用JS实现是有些麻烦的,用JSF把前台与后台bean进行绑定就可轻松实现。
(这个里面还存在有大量的JSP思想,现在修改如下:)
页面代码:
<
h:selectBooleanCheckbox
value="#{recu_planBB.selectAll}" onclick="return displayAll();"/>
修改后为:
<
h:selectBooleanCheckbox
value="#{recu_planBB.selectAll}" onclick="submit();" valueChangeListener="#{recu_planBB.queryAll}"/>
其中valueChangeListener是JSF自带的属性;
下面这段脚本去掉
<SPAN style="TEXT-DECORATION: line-through"><SPAN style="COLOR: #ff0000">function displayAll(){
document.form1.action="/recruit/planAudit.jsf";
document.form1.submit();
return true;
}</SPAN></SPAN>
document.form1.action="/recruit/planAudit.jsf";
document.form1.submit();
return true;
}</SPAN></SPAN>
后台bean代码:
private
boolean selectAll;
public boolean getSelectAll() {
return selectAll;
}
public void setSelectAll( boolean selectAll) {
this.selectAll = selectAll;
}
public boolean getSelectAll() {
return selectAll;
}
public void setSelectAll( boolean selectAll) {
this.selectAll = selectAll;
}
bean代码修改如下:
private
boolean selectAll;
public boolean getSelectAll() {
return selectAll;
}
public void setSelectAll( boolean selectAll) { this.selectAll = selectAll;
}
public void queryAll(ValueChangeEvent event){
selectAll= "true".equals(event.getNewValue().toString());
queryPlanList();
}
public boolean getSelectAll() {
return selectAll;
}
public void setSelectAll( boolean selectAll) { this.selectAll = selectAll;
}
public void queryAll(ValueChangeEvent event){
selectAll= "true".equals(event.getNewValue().toString());
queryPlanList();
}
在checkbox没有选中的情况下,默认的值为false,选中后即可变成true,这样以来,只要你选中了checkbox它就会一直处于选中状态,除非你把它去掉。(
这样以来就完全是JSF的思想了)
本文转自sucre03 51CTO博客,原文链接:http://blog.51cto.com/sucre/354191,如需转载请自行联系原作者