-
Notifications
You must be signed in to change notification settings - Fork 328
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
Conversation
@@ -27,6 +27,7 @@ | |||
import javax.inject.Inject; | |||
import javax.servlet.http.HttpServletRequest; | |||
|
|||
import org.jboss.weld.exceptions.IllegalStateException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use java.lang.IllegalStateException
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really. Thanks. :-)
+ "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."); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad indent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. thanks @lucascs . ;-)
What is the problem the controller is causing? if it's returning a 500 with the message you configured, it's the expected behavior |
The only problem that I saw, is that when using something like: @Post("/add")
public void add(Usuario usuario) {
validator.addIf(Strings.isNullOrEmpty(usuario.getLogin()), new SimpleMessage("Login", "Login inválido."));
result.redirectTo(this).index();
} The error is only this exception: https://github.com/caelum/vraptor4/blob/master/vraptor-core/src/main/java/br/com/caelum/vraptor/observer/ExecuteMethod.java#L98 But with the approach of this PR and using something like
|
is there any caused by or root cause for this exception? |
No. I tested the @csokol's solution, and solved this problem... |
@lucascs do you think that we need check just for |
I'd rather throw the exception as soon as possible. so for all |
go ahead... write some unit tests for it maybe you can remove the exception thrown on ExecuteMethodObserver also. |
If I remove the exception thrown on |
Making some tests, now the problem is because So, I can't just add this check on method I'll do another tests and take a look about how I can fix the problem, but if do you have some suggestions, I think you. rs |
I mean this exception, that is the same you've thrown: maybe we should move this whole if to result#use: can you do it please and test if it works? |
Yes, I can. 😃 |
about the cyclic problem, we can fix it by clearing validation#errors here: before returning the Not sure if I like the solution though... What do you think? @garcia-jj @Turini |
Maybe a solution for the cyclin problem, if do you agree, I can do it. @lucascs @garcia-jj @Turini Moving the check for validation erros to So we still need the PR #729. |
I'm from mobile, so I didn't look at all code. But about cyclic problem you can just |
@Turini sorry if I didn't understand your point and as you said you're from mobile and didn't look at all code. I think when @lucascs said about cyclic problem is because Can we resolve this with Thanks a lot. 😃 |
hum, now I see. In this case |
@garcia-jj do you agree too ? If so, can I implement it ? @lucascs @Turini @garcia-jj Thanks. :-) |
Done. What do you think ? @lucascs @Turini @garcia-jj I did some tests with a POC and worked fine. |
@Turini,
May you explain me ? Thanks a lot. |
This is really simple. Normal scoped beans are "lazy injected". When you inject such bean it will be just a proxy object, the real instance will be called only at the moment when you performed your first action. CDI impl takes care of it, you don't need to use Instance<?> for this specific case. (sorry about the short answer, I'm from mobile right now) |
This kind of feature in CDI it's interesting but it's weird if you think in As @Turini said, CDI just handles circular reference when at least one of The container is required to support circularities in the bean dependency
On Fri, Aug 29, 2014 at 6:55 AM, Rodrigo Turini notifications@github.com
Rafael Ponte |
I agree about avoiding it, but to use |
Hi @Turini, Why not put assertAbsenceOfErrors On Fri, Aug 29, 2014 at 8:34 AM, Rodrigo Turini notifications@github.com
Rafael Ponte |
extracting |
Turini, What I mean is that the place of assertAbsenceOfErrors method seems like On Fri, Aug 29, 2014 at 8:59 AM, Rodrigo Turini notifications@github.com
Rafael Ponte |
Hi @renanigt, As you can see, DefaultResult and ExecuteMethod use Messages only to What do you think? On Fri, Aug 29, 2014 at 9:09 AM, Renan Montenegro notifications@github.com
Rafael Ponte |
@rponte makes sense for me. I agree with you. What do tou think @lucascs @Turini @garcia-jj ? |
Humm.. I see now, Validator uses Result too so we end up with another On Fri, Aug 29, 2014 at 9:14 AM, Rafael Ponte rponte@gmail.com wrote:
Rafael Ponte |
@rponte True, I didn't see that. |
Well, dealing with circular dependency it's not so easy as we thought :-) On Fri, Aug 29, 2014 at 9:19 AM, Renan Montenegro notifications@github.com
Rafael Ponte |
I think the best solution is extract the @Turini if we extract it to a new bean, |
Wrong @renan? |
I think so. 😃 |
} catch (ValidationException e) { | ||
log.debug("Some validation errors occured: {}", e.getErrors()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need validator here.
you already have the errors (getErrors()
), just use it.
and remove validator dependency.
no more cyclic dependency ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can change this whole if on line 123 to:
log.debug("Some validation errors occured: {}", getErrors());
slf4j already does the if internally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lucascs what about validator.onErrorUse(nothing());
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True @lucascs, now I see your point. 😃
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's from the time we didn't have validator.getErrors()
method, so we had to catch the exception to be able to get the errors. VRaptor 3 inheritance ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @lucascs. 😃
Done. What do you think ? @lucascs @Turini @garcia-jj @rponte |
@@ -238,7 +248,7 @@ public void shouldDelegateToStatusOnPermanentlyRedirectToControllerInstance() th | |||
result.permanentlyRedirectTo(new RandomController()); | |||
|
|||
verify(status).movedPermanentlyTo(RandomController.class); | |||
|
|||
verify(messages).assertAbsenceOfErrors(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leave this verify only for the method which is checking this behavior. No need to repeat it on all.
Done @lucascs ! |
For @lucascs this issue can be merged. What do you think ? @Turini @garcia-jj |
sounds nice, thanks |
Fixing problem: validation errors ignored on redirects. Closes #476
In conversation on Issue #476, @lucascs asked me to send this PR to start the bug fix.
Here the gist with the problematic controller as he asked me: Problematic Controller