-
Notifications
You must be signed in to change notification settings - Fork 951
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
Fordward renders 404 error when should not #11102
Comments
I don't think this has anything to do with a
I haven't looked into why that is happening, but I don't think it is related to your forward. |
Hi @jeffbrown thanks for your reply. Why is that form invalid? |
@maurociancio Apologies. You are 100% correct. I mis-read it. Sorry for the noise. |
Hi @jeffbrown, no problem! Is this a bug or am I misusing the API? |
Hi @maurociancio I think this is a valid bug. The issue is that during the forward method, the url to forward to is calculated as
It works. I'm working on a fix as we speak. |
Hey @ilopmar, thanks for your reply! |
Hi @maurociancio, can you please why you are doing a |
Hi @ilopmar! Of course, the example I provided was pretty small.
So, when the validation fails in doCreate() I forward to the create() action so I can show the form again and provide feedback to the user about the validation errors. If I use redirect I would lose the command object between requests. Of course, I could render the create view again instead of forwarding, but I'd have to copy-paste the code in create() or extract a new method to have the duplicate code. Is my example clear enough? |
Why do you "lose the command object between request". You can do something like:
Which is the same as you have in the |
I see your point, but: are the meanings of redirect and forward the same? I mean, when you forward() there no serialization of your command object. In the same request the command object is passed from one action to another. The user does not see the params. I could pass "private" parameters between the two actions, and the user would not notice. When you redirect() the command object has to be serialized in the query string, right? So I could potencially be leaking some private parameters between the two actions. So, they are similar but the semantics are different, right? |
Yes, you are right. When doing a redirect all the parameters are displayed on the browser and appended to the url query string.
So, if there is an error in the validation, instead of forwarding I render a view and I can pass any parameter I want. |
Hi @ilopmar! |
I'm still debugging this and tried a fix before but I broke other thing :-P |
BTW, in the mean time, if you don't want to change your code you can enable the default Url Mappings or create specific entries for the affected actions. |
Hi @ilopmar! Okay! Thanks! |
I haven't pushed anything yet so feel free to fork the repo and create your own branch. |
Haha, I could use some inspiration! |
Hi @maurociancio. I've been discussing this issue with @jameskleeh and this is finally not a bug per-se. |
Hi @ilopmar! Thanks for your reply! |
@maurociancio Because you can't change the method in a forward. The forward to an action will look up the url mapping for the action and forward to that URL. Since the URL is the same for both of your actions, the original action will be invoked because the action you've attempted to forward to only responds to GET and the original request is a POST. That will lead to a stackoverflow. |
POST /test-mapping -> forward determines URL for action get() -> dispatch to /test-mapping (still POST!) -> stackoverflow |
Haha, that makes sense now! Thanks for your time! |
Fix regression due to the fix of #11102
I've created a sample project showing the problem: https://github.com/maurociancio/grails-3-forward-issue .
Given the following controller:
And the following UrlMappings:
And the following get.gsp:
When the submit button is pressed, a 404 is issued in the server. I expected that post() action forwards to get() action and the same view is showed again.
Task List
Steps to Reproduce
Expected Behaviour
I expected the same view to be showed.
Actual Behaviour
404 is shown.
Environment Information
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
Example Application
The text was updated successfully, but these errors were encountered: