下面是页面:
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.tongtech.tongintegrator.monitorcenter.view.bean.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>编辑用户</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="../css/css.css">
</head>
<body>
<f:view>
<table border="0" width="100%" cellspacing="0" cellpadding="3"
class="small">
<tr>
<td align="left">
<h:graphicImage id="node_user" value="../images/node_user.gif"></h:graphicImage>
<h:outputText value="编辑用户" id="opt1"></h:outputText>
</td>
</tr>
</table>
<h:form>
<table border="0" cellspacing="1" width="90%" cellpadding="3"
align="center">
<tr>
<td style="width: 122px; height: 30px">
<h:outputLabel for="userName">
<h:outputText value="用户名: " id="outputText11"></h:outputText>
</h:outputLabel>
</td>
<td>
<h:inputText id="userName" required="true"
value="#{userBean.userName}"></h:inputText> <h:message for="userName" id="usernameMsg"></h:message>
<h:inputHidden value="#{userBean.user_id}" id="user_id"></h:inputHidden> </td>
</tr>
<tr>
<td>
<h:outputLabel for="password">
<h:outputText value="密码:" id="outputText8"></h:outputText>
</h:outputLabel>
</td>
<td>
<h:inputSecret id="password" required="true"
value="#{userBean.password}" redisplay="true"></h:inputSecret>
</td>
</tr>
<tr>
<td>
<h:outputLabel for="repassword">
<h:outputText value="确认密码:" id="outputText3"></h:outputText>
</h:outputLabel>
</td>
<td>
<h:inputSecret id="repassword" value="#{userBean.repassword}"
required="true" redisplay="true">
</h:inputSecret>
<h:message for="repassword" id="passwordMsg"></h:message>
</td>
</tr>
<tr>
<td>
<h:outputLabel for="department">
<h:outputText value="部门:" id="outputText44"></h:outputText>
</h:outputLabel>
</td>
<td>
<h:selectOneMenu id="department">
<f:selectItems value="#{userInfoBean.department}" />
</h:selectOneMenu>
</td>
</tr>
<tr>
<td>
<h:outputLabel for="roleEdit">
<h:outputText value="角色: " id="outputText66"></h:outputText>
</h:outputLabel>
</td>
<td>
<h:selectManyCheckbox layout="lineDirection" id="roleEdit">
<f:selectItems value="#{userInfoBean.roles}" />
</h:selectManyCheckbox>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<h:commandButton value="修改" id="bt1" type="submit"
action="#{userBean.modify}"
onclick="parent.userTree.location.reload();" />
<h:commandButton value="删除" id="bt2" type="submit"
action="#{userBean.delete}"
onclick="parent.userTree.location.reload();" />
</td>
</tr> </table>
</h:form>
</f:view>
</body>
</html>
下面是userBean:
public class UserBean extends BaseBean {
private String userName;
private String password;
private String repassword;
private String dpt;// 新加用户时,存放用户的部门  
//private List <SelectItem> department;//在编辑用户时,选择用户所在的部门
private String phone;
//private boolean[] role;
//private List groupAll;
private MonitorUser userInfo;
private String user_id;
private MonitorUser user;
//private List<MonitorGroup> allGroup;

public UserBean() {
super();
//department = new ArrayList<SelectItem>();
MonitorUserService monitorUserService = (MonitorUserService) getServiceBean("monitorUserService");
//allGroup = monitorUserService.findGroupAll();
String userid = FacesUtils.getRequestParameter("userid");
/*for(int i = 0;i<allGroup.size();i++){
MonitorGroup group = (MonitorGroup)allGroup.get(i);
this.department.add(new SelectItem(group.getGroupId(),group.getGroupName()));
}*/
if (userid != null) {
Integer id = Integer.valueOf(FacesUtils
.getRequestParameter("userid"));
userInfo = monitorUserService.findUserByUserID(id);
userName = userInfo.getUsername();
user_id = String.valueOf(userInfo.getUserid());
password = userInfo.getPassword();
repassword = password;
}
} public String modify() {
MonitorUserService monitorUserService = (MonitorUserService) getServiceBean("monitorUserService");
if (user_id != null) {
Integer userId = Integer.valueOf(user_id);
userInfo = monitorUserService.findUserByUserID(userId);
userInfo.setUsername(userName);
userInfo.setPassword(password);
monitorUserService.updateUser(userInfo);
return "modify success";
}
return " modify false";
} public String delete() {
MonitorUserService monitorUserService = (MonitorUserService) getServiceBean("monitorUserService");
if (user_id != null) {
Integer userId = Integer.valueOf(user_id);
user = monitorUserService.findUserByUserID(userId);
monitorUserService.deleteUser(user);
return "delete success";
}
return "delete false";
}

}下面是userInfoBean:
public UserInfoBean(){
super();
department = new ArrayList<SelectItem>();
roles = new ArrayList<SelectItem>();
MonitorUserService monitorUserService = (MonitorUserService) getServiceBean("monitorUserService");
allGroup = monitorUserService.findGroupAll();
allRole = monitorUserService.findRoleAll();
//String userid = FacesUtils.getRequestParameter("userid");
for(int i = 0;i<allGroup.size();i++){
MonitorGroup group = (MonitorGroup)allGroup.get(i);
this.department.add(new SelectItem(group.getGroupId(),group.getGroupName()));
}
for(int i = 0;i<allRole.size();i++){
MonitorRole role = (MonitorRole)allRole.get(i);
this.roles.add(new SelectItem(role.getRoleId(),role.getRoleName()));
}
}
当页面中没有
<h:selectOneMenu id="department">
  <f:selectItems value="#{userInfoBean.department}" />
</h:selectOneMenu>
和 
<h:selectManyCheckbox layout="lineDirection" id="roleEdit">
  <f:selectItems value="#{userInfoBean.roles}" />
</h:selectManyCheckbox>
时  修改和删除按钮都可以执行,加上后,两个按钮就失效了,还不报错

解决方案 »

  1.   

    #{userInfoBean.department}和#{userInfoBean.roles}的类型不正确,
    它们的类型必须是 SelectItem[]
    即你的方法应该是这样的
    public SelectItem[] getDepartment(){}才可以的。
    解决了就给分
      

  2.   

    不好意思,上面说错了,你的问题不在那里,是数据类型的问题,
    department,roles中要用到的数据类型必须都是string的类型,例如id之类的,不能用int的,你要用的话必须在后台自己再去转换。
      

  3.   

    你在前台页面加入标签<h:messages />就可以看到错误了,基本上因该是类型转换错误,就是说
    selectManyCheckbox它们不能自动的将string转换为int,所你的department,roles中的属性必须是string类型的
      

  4.   

    selectManyCheckbox可以成功的从库中调出,但是就是两个按钮不能使用了,而且页面还没有报错
      

  5.   

    如:
    <h:selectOneMenu value="#{userInfoBean.depart}" > 
       <f:selectItems value="#{userInfoBean.department}" / > 
    </h:selectOneMenu >