本帖最后由 张云杰 于 2013-1-21 18:40 编辑
package com.softfz.control;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.beanutils.BeanUtils;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.softfz.dao.DictionaryDao;
import com.softfz.dao.RoleDao;
import com.softfz.dao.UserDao;
import com.softfz.model.Dictionary;
import com.softfz.model.PageModel;
import com.softfz.model.Role;
import com.softfz.model.UserInfo;
public class UserAction extends ActionSupport implements ModelDriven<UserInfo> {
//模型驱动
private UserInfo model = new UserInfo();
private List<Dictionary> list;
private List<Role> rolelist;
private PageModel pageModel;
private int statusCode = 200;
private String tipsMessage;
public String forwardUrl;
public String rel;
public String navTabId;
public String callbackType;
private int pageNum=1;
private int numPerPage=10 ;
public String qureypage(){
UserDao dao = new UserDao();
pageModel = dao.query(model, this.pageNum, this.numPerPage);
return "list";
}
public String addpage(){
DictionaryDao dicdao = new DictionaryDao();
list = dicdao.getDic();
RoleDao roledao = new RoleDao();
rolelist = roledao.getRole();
return "addpage";
}
public String updatepage() throws IllegalAccessException, InvocationTargetException{
UserDao dao = new UserDao();
UserInfo user = dao.qureyByid(model.getId());
BeanUtils.copyProperties(model, user);
DictionaryDao dicdao = new DictionaryDao();
list = dicdao.getDic();
RoleDao roledao = new RoleDao();
rolelist = roledao.getRole();
return "addpage";
}
public String deletesave(){
UserDao dao = new UserDao();
int i = dao.delete(model);
if(i>0){
return returnCommand();
}else{
return returnCommand("失败了,请重新操作");
}
}
public String updatesave(){
UserDao dao = new UserDao();
int i = dao.update(model);
if(i>0){
return returnCommand();
}else{
return returnCommand("失败了,请重新操作");
}
}
public String addupdate(){
UserDao dao = new UserDao();
if(model.getId()==null||model.getId().trim().equals("")){
int i = dao.add(model);
if(i>0){
return returnCommand();
}else{
return returnCommand("失败了,请重新操作");
}
}else{
int j = dao.update(model);
if(j>0){
return returnCommand();
}else{
return returnCommand("失败了,请重新操作");
}
}
}
protected String returnCommand() {
this.statusCode = 200;
this.tipsMessage = "操作成功";
return "ajaxDone";
}
public String returnCommand(String message) {
this.statusCode = 300;
this.tipsMessage = message;
return "ajaxDone";
}
public List<Dictionary> getList() {
return list;
}
public void setList(List<Dictionary> list) {
this.list = list;
}
public UserInfo getModel() {
return model;
}
public PageModel getPagemodel() {
return pageModel;
}
public void setPagemodel(PageModel pageModel) {
this.pageModel = pageModel;
}
public int getStatusCode() {
return statusCode;
}
public void setStatusCode(int statusCode) {
this.statusCode = statusCode;
}
public String getTipsMessage() {
return tipsMessage;
}
public List<Role> getRolelist() {
return rolelist;
}
public void setRolelist(List<Role> rolelist) {
this.rolelist = rolelist;
}
public void setTipsMessage(String tipsMessage) {
this.tipsMessage = tipsMessage;
}
public String getForwardUrl() {
return forwardUrl;
}
public void setForwardUrl(String forwardUrl) {
this.forwardUrl = forwardUrl;
}
public String getRel() {
return rel;
}
public void setRel(String rel) {
this.rel = rel;
}
public String getNavTabId() {
return navTabId;
}
public void setNavTabId(String navTabId) {
this.navTabId = navTabId;
}
public String getCallbackType() {
return callbackType;
}
public void setCallbackType(String callbackType) {
this.callbackType = callbackType;
}
public PageModel getPageModel() {
return pageModel;
}
public void setPageModel(PageModel pageModel) {
this.pageModel = pageModel;
}
public int getPageNum() {
return pageNum;
}
public void setPageNum(int pageNum) {
this.pageNum = pageNum;
}
public int getNumPerPage() {
return numPerPage;
}
public void setNumPerPage(int numPerPage) {
this.numPerPage = numPerPage;
}
}
这个是Action代码,
<p>
<label>选择角色</label>
<s:iterator value="rolelist" var="role"><input name="rolename" type="checkbox" /><s:property value="#role.rolename"/><br/></s:iterator>
<!-- <s:checkboxlist name="rolename" list="rolelist" listKey="rid" listValue="rolename"></s:checkboxlist> -->
</p>
界面上不允许用S标签做回填 S标签我已做出回填了..
只能用input里的check 做, 请问怎么做?
|
|