package action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.googlecode.jsonplugin.annotations.JSON;
import common.CacheManager;
import domain.ListRange;
import domain.User;
import UserService;
import ErrorMessage;
public class UserAction extends BaseActionSupport{
private UserService userService;
private int userid;
private String name;
private String loginid;
private String usertype;
public String list(){
listrange=new ListRange();
List l=cacheManager.getUsersList();
if (l==null||l.size()==0){
listrange.setTotalSize(0);
return SUCCESS;
}
listrange.setTotalSize(l.size());
List l2=null;
if (limit<=0)
l2=l;
else{
l2=new ArrayList();
for (int i=start;i<start+limit&&i<l.size();i++){
l2.add(l.get(i));
}
}
listrange.setData(l2.toArray());
return SUCCESS;
}
public String save(){
int rtn=0;
if (userid==0){
rtn=userService.addUser(loginid, name, usertype);
} else {
User user=new User();
user.setUserid(userid);
user.setName(name);
user.setUsertype(usertype);
user.setLoginid(loginid);
rtn=userService.updateUser(user);
}
setReturn(rtn);
return SUCCESS;
}
@JSON(serialize=false)
public String getLoginid() {
return loginid;
}
public void setLoginid(String loginid) {
this.loginid = loginid;
}
@JSON(serialize=false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@JSON(serialize=false)
public String getUsertype() {
return usertype;
}
public void setUsertype(String usertype) {
this.usertype = usertype;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
@JSON(serialize=true)
public int getUserid() {
return userid;
}
public void setUserid(int userid) {
this.userid = userid;
}
@JSON(name="list")
public ListRange getListrange() {
return listrange;
}
@JSON
public boolean isFailure() {
return failure;
}
@JSON
public boolean isSuccess() {
return success;
}
@JSON
public String getInfo() {
return info;
}
}
<action name="user" class="userAction"> <result type="json"/> </action>