mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
Uses default error key if specified key doesn't exist
This commit is contained in:
@@ -26,7 +26,6 @@ import com.opensymphony.xwork2.inject.Container;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
|
||||
import com.opensymphony.xwork2.interceptor.ValidationAware;
|
||||
import com.opensymphony.xwork2.util.LocalizedTextUtil;
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -38,7 +37,6 @@ import org.apache.struts2.dispatcher.multipart.UploadedFile;
|
||||
import org.apache.struts2.util.ContentTypeMatcher;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.*;
|
||||
|
||||
@@ -258,11 +256,16 @@ public class FileUploadInterceptor extends AbstractInterceptor {
|
||||
|
||||
MultiPartRequestWrapper multiWrapper = (MultiPartRequestWrapper) request;
|
||||
|
||||
if (multiWrapper.hasErrors()) {
|
||||
if (multiWrapper.hasErrors() && validation != null) {
|
||||
TextProvider textProvider = getTextProvider(action);
|
||||
for (LocalizedMessage error : multiWrapper.getErrors()) {
|
||||
if (validation != null) {
|
||||
validation.addActionError(LocalizedTextUtil.findText(error.getClazz(), error.getTextKey(), ActionContext.getContext().getLocale(), error.getDefaultMessage(), error.getArgs()));
|
||||
String errorMessage;
|
||||
if (textProvider.hasKey(error.getTextKey())) {
|
||||
errorMessage = textProvider.getText(error.getTextKey(), Arrays.asList(error.getArgs()));
|
||||
} else {
|
||||
errorMessage = textProvider.getText("struts.messages.error.uploading", error.getDefaultMessage());
|
||||
}
|
||||
validation.addActionError(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -231,7 +231,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
|
||||
req.setContentType("text/xml"); // not a multipart contentype
|
||||
req.addHeader("Content-type", "multipart/form-data");
|
||||
|
||||
MyFileupAction action = new MyFileupAction();
|
||||
MyFileupAction action = container.inject(MyFileupAction.class);
|
||||
MockActionInvocation mai = new MockActionInvocation();
|
||||
mai.setAction(action);
|
||||
mai.setResultCode("success");
|
||||
@@ -252,7 +252,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
|
||||
req.addHeader("Content-type", "multipart/form-data");
|
||||
req.setContent(null); // there is no content
|
||||
|
||||
MyFileupAction action = new MyFileupAction();
|
||||
MyFileupAction action = container.inject(MyFileupAction.class);
|
||||
MockActionInvocation mai = new MockActionInvocation();
|
||||
mai.setAction(action);
|
||||
mai.setResultCode("success");
|
||||
@@ -386,7 +386,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
|
||||
"-----1234--\r\n");
|
||||
req.setContent(content.getBytes("US-ASCII"));
|
||||
|
||||
MyFileupAction action = new MyFileupAction();
|
||||
MyFileupAction action = container.inject(MyFileupAction.class);
|
||||
|
||||
MockActionInvocation mai = new MockActionInvocation();
|
||||
mai.setAction(action);
|
||||
@@ -453,7 +453,7 @@ public class FileUploadInterceptorTest extends StrutsInternalTestCase {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
private class MyFileupAction extends ActionSupport {
|
||||
public static class MyFileupAction extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = 6255238895447968889L;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user