4

我想在对struts 2 jQuery网格的值做一些 服务器端验证之后,在网格顶部显示动作错误。 任何帮助,将不胜感激。在struts2-jQuery网格视图中的操作错误

这是我的动作错误。

addActionError("You can not delete this data"); 

但不幸的是,我无法在我的jsp页面中显示错误。请分享你关于这个问题的知识。

+0

显示您的JSP页面和操作配置。 – 2013-03-06 10:19:45

+0

如何从服务器端实现jqGrid中的错误或信息消息? – sjkon 2013-03-06 10:30:00

+0

你是什么意思?显示你的代码。 – 2013-03-06 10:31:07

回答

0

试试这个

基本概念: 你必须做出一个JSP。

说error.jsp和错误返回,只需加载error.jsp。

在error.jsp中写入addActionError("You can not delete this data");

,包括这error.jsp文件到您的主网的页面,你想,以示对服务器端验证错误消息

+0

我们如何包含一个页面?请给我一个相同的例子吗? – sjkon 2013-03-06 12:05:27

0

我用aftersubmit事件JSON响应如下图所示

navGrid("#pager2",{}, //options 
      {height:280,width:700,reloadAfterSubmit:false}, // edit options 
      {height:280,width:700,reloadAfterSubmit:false, 
      afterSubmit : function(response, postdata) { 
       var msg = "noError"; 
       var res = $.parseJSON(response.responseText); 
       if (res && res.userMessage) { 
        alert(res.userMessage); 
        msg = res.userMessage; 
       } 

       //alert(msg); 
      if(msg == "noError") { 
       return [true, "Validation pass"]; 
      } else { 
       return [false, msg]; 
      } 
      }}, // add options 

      {reloadAfterSubmit:false}, // del options 
      {} // search options 
    ); 

和支柱进入

  <action name="jsontableEditValidationApartmentResource" class="com.loa.monitor.action.JsonActionResource" method="editValidate" > 
    <result name="success" type = "json"></result> 
    <result name="error" type="redirectAction"> 
      <param name="actionName">proceedApartment</param> 
    </result> 
</action> 

和行动方法

 public String editValidate() { 
    userMessage = "test msg1"; 
    return "success"; 
} 

private String userMessage ; 


public String getUserMessage() { 
    return userMessage; 
} 

public void setUserMessage(String userMessage) { 
    this.userMessage = userMessage; 
} 

让我知道这是否有用

+0

阅读常见问题http://stackoverflow.com/faq#signatures – 2013-03-27 10:11:14