jqGrid如何从struts2动作接收错误消息?

时间:2011-10-26 08:46:35

标签: java jqgrid struts2

我在jqGrid中修改了一条记录并将其提交给stuts2动作,当记录数据非法时,动作会向jqGrid返回一条“错误”消息,jqGrid如何收到错误信息并显示出来?      谢谢!

以下是操作中的方法代码:

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>

1 个答案:

答案 0 :(得分:1)

Here是一个完整的工作示例。