struts2 又出问题

sungirlzcy 2009-05-27 01:49:58
我写了俩checkbox
我的意思是想让它被选择的时候就显示1,不选择就显示0,
可是,当我不选择的时候就出这个Invalid field value for field "role.moduleFlag".
这是咋整啊?
要贴代码吗?
...全文
66 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
cust28 2009-05-27
  • 打赏
  • 举报
回复
估计是 struts2自定义标签就那么设计的
有兴趣的话,可以看看标签的源码
给分啊~ 呵呵
sungirlzcy 2009-05-27
  • 打赏
  • 举报
回复
好了,太感谢你了,老感谢了,我一辈子都会记得你的,
呵呵
可是为什么用标签那个不行啊
真的太感谢你了
cust28 2009-05-27
  • 打赏
  • 举报
回复
表单中<s:checkbox name="role.moduleFlag" fieldValue="1"/>
换成<input type="checkbox" name="role.moduleFlag" value="1" />
就不会报那个错误了
cust28 2009-05-27
  • 打赏
  • 举报
回复
当你选择的时候,struts2会把值赋给role.moduleFlag,即表单中的1
如果你不选择的时候,struts2会把role.moduleFlag解析为
role.moduleFlag=false

由于你role中定义的moduleFlag为int,所以报Invalid field value for field "role.moduleFlag"
sungirlzcy 2009-05-27
  • 打赏
  • 举报
回复
struts

private static final long serialVersionUID = 1L;

private String roleId;

private List<Role> roles;

private Role role;

private IRoleManager roleManager;

// private int customerFlag;

// private int moduleFlag;

private String roleName;

public String getRoleName() {
return roleName;
}

public void setRoleName(String roleName) {
this.roleName = roleName;
}

/*public int getModuleFlag() {
return moduleFlag;
}

public void setModuleFlag(int moduleFlag) {
this.moduleFlag = moduleFlag;
}

public int getCustomerFlag() {
return customerFlag;
}

public void setCustomerFlag(int customerFlag) {
this.customerFlag = customerFlag;
}*/

public void setRoles(Role roles) {
this.role = roles;
}

public Role getRole() {
return role;
}

public void setRoles(List<Role> roles) {
this.roles = roles;
}

public List<Role> getRoles() {
return roles;
}

public void setRole(Role role) {
this.role = role;
}

public IRoleManager getRoleManager() {
return roleManager;
}

public void setRoleManager(IRoleManager roleManager) {
this.roleManager = roleManager;
}

@Override
public String execute() throws Exception {
return SUCCESS;
}

public String list() throws Exception {
roles = roleManager.getAllRoles();
return SUCCESS;
}

public String edit() throws Exception{
return SUCCESS;
}

public String delete() throws Exception {
if (roleId != null)
roleManager.deleteRole(roleId);
return SUCCESS;
}

public String save_role() throws Exception {
if (StringUtils.isBlank(roleId)) {
role.getModuleFlag();
role.getCustomerFlag();
System.out.println("moduleFlag is "+role.getModuleFlag());
roleManager.addRole(role);
}
return SUCCESS;
}

/*
* (non-Javadoc)
*
* @see com.opensymphony.xwork2.Preparable#prepare()
*/
public void prepare() throws Exception {
if (!StringUtils.isBlank(this.roleId)) {
role = (Role)roleManager.getAllRoles();
}
}

public String getRoleId() {
return roleId;
}

public void setRoleId(String roleId) {
this.roleId = roleId;
}
sungirlzcy 2009-05-27
  • 打赏
  • 举报
回复
action
private static final long serialVersionUID = 1L;

private String roleId;

private List<Role> roles;

private Role role;

private IRoleManager roleManager;

// private int customerFlag;

// private int moduleFlag;

private String roleName;

public String getRoleName() {
return roleName;
}

public void setRoleName(String roleName) {
this.roleName = roleName;
}

/*public int getModuleFlag() {
return moduleFlag;
}

public void setModuleFlag(int moduleFlag) {
this.moduleFlag = moduleFlag;
}

public int getCustomerFlag() {
return customerFlag;
}

public void setCustomerFlag(int customerFlag) {
this.customerFlag = customerFlag;
}*/

public void setRoles(Role roles) {
this.role = roles;
}

public Role getRole() {
return role;
}

public void setRoles(List<Role> roles) {
this.roles = roles;
}

public List<Role> getRoles() {
return roles;
}

public void setRole(Role role) {
this.role = role;
}

public IRoleManager getRoleManager() {
return roleManager;
}

public void setRoleManager(IRoleManager roleManager) {
this.roleManager = roleManager;
}

@Override
public String execute() throws Exception {
return SUCCESS;
}

public String list() throws Exception {
roles = roleManager.getAllRoles();
return SUCCESS;
}

public String edit() throws Exception{
return SUCCESS;
}

public String delete() throws Exception {
if (roleId != null)
roleManager.deleteRole(roleId);
return SUCCESS;
}

public String save_role() throws Exception {
if (StringUtils.isBlank(roleId)) {
role.getModuleFlag();
role.getCustomerFlag();
System.out.println("moduleFlag is "+role.getModuleFlag());
roleManager.addRole(role);
}
return SUCCESS;
}

/*
* (non-Javadoc)
*
* @see com.opensymphony.xwork2.Preparable#prepare()
*/
public void prepare() throws Exception {
if (!StringUtils.isBlank(this.roleId)) {
role = (Role)roleManager.getAllRoles();
}
}

public String getRoleId() {
return roleId;
}

public void setRoleId(String roleId) {
this.roleId = roleId;
}
sungirlzcy 2009-05-27
  • 打赏
  • 举报
回复
jsp
<form action="save_role" method="post" enctype="multipart/form-data">
<s:hidden name="roleId" value="%{role.roleId}"/>
<table align="center">
<tr>
<td>角色名称</td>
<td>
<s:textfield name="role.roleName" /></td>
</tr>
<tr>
<td>是否可以访问所有模块</td>
<td>
<s:checkbox name="role.moduleFlag" fieldValue="1"/>
</td>
</tr>
<tr>
<td>是否可以访问所有客户</td>
<td>
<s:checkbox name="role.customerFlag" fieldValue="1" ></s:checkbox>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="submit" value="保存">
<input type="button" name="button" value="取消" onClick="re()">
</td>
</tr>
</table>
</form>
cust28 2009-05-27
  • 打赏
  • 举报
回复
校验的问题

你页面传的参数,跟model 接收的参数类型不匹配.
检查下你不选择的时候,model中的moduleFlag值是什么

最好有代码~

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧