Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing problem: validation errors ignored on redirects. Closes #476 #725

Merged
merged 21 commits into from
Aug 30, 2014
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import br.com.caelum.vraptor.View;
import br.com.caelum.vraptor.interceptor.TypeNameExtractor;
import br.com.caelum.vraptor.ioc.Container;
import br.com.caelum.vraptor.validator.Validator;
import br.com.caelum.vraptor.view.Results;

/**
* A basic implementation of a Result
Expand All @@ -48,28 +50,41 @@ public class DefaultResult extends AbstractResult {
private final Container container;
private final ExceptionMapper exceptions;
private final TypeNameExtractor extractor;
private Validator validator;

private Map<String, Object> includedAttributes;
private boolean responseCommitted = false;


/**
* @deprecated CDI eyes only
*/
protected DefaultResult() {
this(null, null, null, null);
this(null, null, null, null, null);
}

@Inject
public DefaultResult(HttpServletRequest request, Container container, ExceptionMapper exceptions, TypeNameExtractor extractor) {
public DefaultResult(HttpServletRequest request, Container container, ExceptionMapper exceptions, TypeNameExtractor extractor,
Validator validator) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Receive validationErrors here, instead of Validator. And check for hasUnhandledErrors

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Messages?

this.request = request;
this.container = container;
this.extractor = extractor;
this.includedAttributes = new HashMap<>();
this.exceptions = exceptions;
this.validator = validator;
}

@Override
public <T extends View> T use(Class<T> view) {
if(view.isAssignableFrom(Results.json()) && validator.hasErrors()) {
throw new IllegalStateException(
"There are validation errors and you forgot to specify where to go. Please add in your method "
+ "something like:\n"
+ "validator.onErrorUse(page()).of(AnyController.class).anyMethod();\n"
+ "or any view that you like.\n"
+ "If you didn't add any validation error, it is possible that a conversion error had happened.");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad indent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. thanks @lucascs . ;-)


responseCommitted = true;
return container.instanceFor(view);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import br.com.caelum.vraptor.View;
import br.com.caelum.vraptor.interceptor.TypeNameExtractor;
import br.com.caelum.vraptor.ioc.Container;
import br.com.caelum.vraptor.util.test.MockValidator;
import br.com.caelum.vraptor.view.DefaultHttpResultTest.RandomController;
import br.com.caelum.vraptor.view.LogicResult;
import br.com.caelum.vraptor.view.PageResult;
Expand All @@ -49,11 +50,13 @@ public class DefaultResultTest {

private Result result;
@Mock private TypeNameExtractor extractor;
private MockValidator validator;

@Before
public void setup() {
MockitoAnnotations.initMocks(this);
result = new DefaultResult(request, container, null, extractor);
validator = new MockValidator();
result = new DefaultResult(request, container, null, extractor, validator);
}

public static class MyView implements View {
Expand Down