社区
Web 开发
帖子详情
struts2 又出问题
sungirlzcy
2009-05-27 01:49:58
我写了俩checkbox
我的意思是想让它被选择的时候就显示1,不选择就显示0,
可是,当我不选择的时候就出这个Invalid field value for field "role.moduleFlag".
这是咋整啊?
要贴代码吗?
...全文
66
8
打赏
收藏
struts2 又出问题
我写了俩checkbox 我的意思是想让它被选择的时候就显示1,不选择就显示0, 可是,当我不选择的时候就出这个Invalid field value for field "role.moduleFlag". 这是咋整啊? 要贴代码吗?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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值是什么
最好有代码~
Struts
2实战.pdf
资深开发人员深入剖析
Struts
2核心概念和组件 学习
Struts
不可不读 作者简介 作者:(美国)Donald Brown (美国)Chad Michael Davis (美国)Scott Stanlick 译者:马召 等 Donald Brown,Atlassian软件系统公司托管...
最新版本的
Struts
2+Spring4+Hibernate4框架整合
整合使用最新版本的三大框架(即
Struts
2、Spring4和Hibernate4),搭建项目架构原型。 项目架构原型:
Struts
2.3.16 + Spring4.1.1 + Hibernate4.3.6。 此外,还有:log4j、slf4j、junit4、ehcache等知识点。 项目...
深入浅
出
Struts
2
本课程主要讲授如何使用
Struts
2框架开发Web应用程序,其特色在于其讲解的过程中,通过当堂编写代码的讲授方式讲解“关键知识点”,这些“关键知识点”可保证学生从始至终都写
出
可运行的程序。
struts
2 项目实例
struts
2.0 小例子 希望对刚学
struts
2的同胞能有所帮助
struts
2必备jar包官方绿色版
struts
2最新官网的jar包,已经是最少的包的无法再删除了, commons-fileupload-1.2.2.jar commons-io-2.0.1.jar commons-lang3-3.1.jar commons-logging-1.1.1.jar freemarker-2.3.19.jar javassist-3.11.0.GA.jar ...
Web 开发
81,094
社区成员
341,711
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章