jqGrid如何接收来自struts2操作的错误消息?
我修改了jqGrid中的一条记录并将其提交给stuts2 action,当记录数据非法时,action会向jqGrid返回“错误”消息,jqGrid如何接收错误消息并显示它? 谢谢!
这是action中的方法代码:
public String editPerson() {
String result = SUCCESS;
if ("add".equals(oper)) {
List<Person> personList = personService.findByPersonId(personId);
if(Personlist.size() > 0){
result = ERROR;
message = "duplicated person!";
}else{
Person person = new Person();
person.setPersonId(personId);
person.setName(name);
person.setAge(age);
person.setGender(gender);
personService.save(person);
}
}
}
这是jsp文件中的代码:
<s:url id="remoteURL" action="personListAction" />
<s:url id="editURL" action="personEditAction" />
<sjg:grid id="gridtable" caption="Person List" dataType="json"
href="%{remoteURL}" pager="true" gridModel="gridModel"
rowList="10,20,30" rowNum="10" rownumbers="true" viewrecords="true"
navigator="true" editurl="%{editURL}"
navigatorAddOptions="{height:280,reloadAfterSubmit:true}"
multiselect="true" cellEdit="true" sortable="true">
<sjg:gridColumn name="personId" index="PersonId" title="Person Id"
sortable="true" editable="true" required="true" />
<sjg:gridColumn name="name" index="name" title="Person Name" editable="true" required="true"/>
<sjg:gridColumn name="gender" index="gender" title="Gender"
sortable="false" editable="true" edittype="select"
editoptions="{value:'1:male;2:female'}" />
<sjg:gridColumn name="age" index="age" title="Age" sortable="false"
editable="true" editrules="{number:true}"/>
</sjg:grid>
I modified a record in jqGrid and submitted it to stuts2 action, when the record data is illegal, action will return a "error" message to jqGrid, how can jqGrid receive the error message and display it?
thanks!
here are the method code in the action:
public String editPerson() {
String result = SUCCESS;
if ("add".equals(oper)) {
List<Person> personList = personService.findByPersonId(personId);
if(Personlist.size() > 0){
result = ERROR;
message = "duplicated person!";
}else{
Person person = new Person();
person.setPersonId(personId);
person.setName(name);
person.setAge(age);
person.setGender(gender);
personService.save(person);
}
}
}
and here is the code in jsp file:
<s:url id="remoteURL" action="personListAction" />
<s:url id="editURL" action="personEditAction" />
<sjg:grid id="gridtable" caption="Person List" dataType="json"
href="%{remoteURL}" pager="true" gridModel="gridModel"
rowList="10,20,30" rowNum="10" rownumbers="true" viewrecords="true"
navigator="true" editurl="%{editURL}"
navigatorAddOptions="{height:280,reloadAfterSubmit:true}"
multiselect="true" cellEdit="true" sortable="true">
<sjg:gridColumn name="personId" index="PersonId" title="Person Id"
sortable="true" editable="true" required="true" />
<sjg:gridColumn name="name" index="name" title="Person Name" editable="true" required="true"/>
<sjg:gridColumn name="gender" index="gender" title="Gender"
sortable="false" editable="true" edittype="select"
editoptions="{value:'1:male;2:female'}" />
<sjg:gridColumn name="age" index="age" title="Age" sortable="false"
editable="true" editrules="{number:true}"/>
</sjg:grid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里是一个完整的工作示例。
Here is a complete working example.