简体   繁体   English

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

[英]How can jqGrid receive error message from struts2 action?

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? 我在jqGrid中修改了一条记录,并将其提交给stuts2操作,当记录数据非法时,操作将向jqGrid返回“错误”消息,jqGrid如何接收错误消息并显示出来? 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: 这是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>

是一个完整的工作示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM