나는이 문제를 해결할 수있었습니다. 나이 필드에 대해 간단한 사용자 정의 유효성 검사기를 사용하는 방법을 설명합니다.이 유효성 검사기는 Employee에 대해 18보다 커야합니다. Validator가 이미 validator.xml에 선언되어 액션에 매핑되어 있고 ValidationException의 경우 메시지가 "Employee must be than 18"이라고 가정합니다.
방화범을 사용하여 양식의 오류 영역 ID가 FormError라는 것을 알아 냈습니다. jqgrid에서 콜백 함수 errorTextFormat을 구성하여 서버에서 응답을 받고 처리 할 수 있습니다. 있는 jqGrid 구성에서, 하나는
var errorFormat = function(response) {
var text = response.responseText;
$('#FormError').text(text); //sets the text in the error area to the validation //message from the server
return text;
};
문제는 서버가 암시 적으로 전체 예외 스택 추적을 포함하는 응답을 보낼 것 지금과
errorTextFormat : errorFormat,
을 작성할 수 있습니다. 이를 처리하기 위해 새로운 결과 유형을 만들기로 결정했습니다.
<package name="default" abstract="true" extends="struts-default">
...
<result-types>
<result-type name="validationError"
class="exercises.ex5.result.MyResult">
</result-type>
</result-types>
...
<action name="myaction">
...
<result name="validationException" type="validationError"></result>
<exception-mapping result="validationException"
exception="java.lang.Exception"></exception-mapping>
</action>
...
</package>
이 내가 추가/편집 창에서 유효성 검사 오류 메시지를 얻기 위해 다음 단계는 지금은 작동 다음과 같이
public class MyResult implements Result {
/**
*
*/
private static final long serialVersionUID = -6814596446076941639L;
private int errorCode = 500;
public void execute(ActionInvocation invocation) throws Exception {
ActionContext actionContext = invocation.getInvocationContext();
HttpServletResponse response = (HttpServletResponse) actionContext
.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse");
Exception exception = (Exception) actionContext
.getValueStack().findValue("exception");
response.setStatus(getErrorCode());
try {
PrintWriter out = response.getWriter();
out.print(exception.getMessage());
} catch (IOException e) {
throw e;
}
}
/**
* @return the errorCode
*/
public int getErrorCode() {
return errorCode;
}
/**
* @param errorCode the errorCode to set
*/
public void setErrorCode(int errorCode) {
this.errorCode = errorCode;
}
}
은 또한 struts.xml에서 구성해야합니다.