checkboxgroupbean.java
来自「OperaMasks是一种基于J2EE的Web开发技术」· Java 代码 · 共 43 行
JAVA
43 行
package demo.form.single;
import javax.faces.model.SelectItem;
import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.annotation.SelectItems;
@ManagedBean(name="CheckBoxGroupBean", scope=ManagedBeanScope.REQUEST)
public class CheckBoxGroupBean {
@Bind
private String response;
@Bind
@SelectItems
private SelectItem[] colors = new SelectItem[]{
new SelectItem(false, "红色"),
new SelectItem(false, "蓝色"),
new SelectItem(false, "绿色"),
};
@Action
public void selectColor_oncheck(){
response = "您选择的颜色是:";
for(SelectItem item : colors){
if((Boolean)item.getValue()){
String color = "";
if("红色".endsWith(item.getLabel())){
color = "red";
}
if("蓝色".endsWith(item.getLabel())){
color = "blue";
}
if("绿色".endsWith(item.getLabel())){
color = "green";
}
response += String.format("<span style='color:%s'>%s</span> ",color,item.getLabel());
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?