-
Notifications
You must be signed in to change notification settings - Fork 7
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
Specify overwrite mechanism for form methods #72
Conversation
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.
LGTM
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.
@erdlet Thank you very much for working on this. I would really love to see this in the spec.
However, I want to share some thoughts. To be honest, I'm not completely sure if we really need this SPI interface which people can implement to provide custom behavior. Isn't the default implementation everything people actually require in real work projects?
When I thought about this feature before, I was actually thinking about just providing:
- A configuration parameter which enables or disables the form method override feature-
- A configuration parameter to customize the name of the request parameter which contains the HTTP verb.
And that's all. Isn't this sufficient for 99% of all use cases?
And if people really want to have some kind of fancy custom behavior, they can actually implement it with a standard JAX-RS ContainerRequestFilter
, which has just a few lines of code. Even the default mechanism which MVC implementations provide boils down to something like this:
@Provider
@PreMatching
public class MethodContainerRequestFilter implements ContainerRequestFilter {
@Override
public void filter( ContainerRequestContext requestContext ) throws IOException {
String method = requestContext.getHeaderString( "X-Method" );
if( method != null ) {
requestContext.setMethod( method );
}
}
}
So I wonder if this SPI isn't an overkill for this simple feature?
@eclipse-ee4j/ee4j-mvc-committers Any other thoughts?
/** | ||
* The name of the hidden form input to get the targeted HTTP method. | ||
*/ | ||
String HIDDEN_FIELD_NAME = "_method"; |
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.
Two comments:
- Does anyone know if there is some kind of "de-facto standard" for the name of this parameter? AFAIK other frameworks support this mechanism as well and if there is some kind of standard name, it would be cool to use it.
- Maybe we should allow to customize the name of the form field via some configuration parameter?
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.
All frameworks I know use _method
(especially Spring), so this name should be the de-facto
standard. I added a possibility to overwrite this name in my new draft.
|
||
Jakarta MVC defines the term _form method overwrite_ as mechanism being responsible for changing the HTTP request's method to something different than `GET` or `POST`. | ||
|
||
The _form method overwrite_ MUST happend exactly once per request as described in <form_method_overwrite_resolving_algorithm>> before the `Controller` is resolved. |
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.
Is there a <
missing?
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.
Yes. Thanks for that catch :)
Thanks for your feedback @chkal. After thinking a few days about that proposal I came to the same conclusion that the SPI would be an overkill. So I think I'll change the proposal so that only the current default mechanism is required as well as the configuration parameters. |
+1 from my side. @eclipse-ee4j/ee4j-mvc-committers It would be great to hear other thoughts as well. |
So if I understand correctly, we can have a form which sends a Will there be TCK tests for this? |
Thanks @jelemux for your feedback!
Absolutely correct 👍
Yes, I just want to have a final draft for this before I start to work on the tests to avoid double work in case of changes. I plan to test the behavior of the config options and usage of a different hidden field name. Think it will sum up to three or four tests. |
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.
I've finally found some time for reviewing this. Sorry for the delay.
I added quite some comments. But mostly minor stuff. I also added suggestions to simplify the process of applying them if we decide to change the corresponding parts.
Hi all, I'm afraid there won't be more feedback. So if this PR is OK for the reviewers, it would be great when @chkal or @ivargrimstad merge it. After that I'll implement the TCK tests and adapt Krazo core. |
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.
I added a few more comments. I also included proposed changes for all my comments to make it easier to apply them if we go with them.
Sorry for the delay in my review and for even more comments. But I guess it would be preferable to have it polished before merging it. :-)
@chkal thanks for the feedback. I hope the spec chapter is fine now :) |
Awesome! Thanks a lot for applying the changes. One last thing. I think the new chapter is still missing in the |
Thanks @chkal, I really missed to add the new chapter 👍 |
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.
Awesome! Thanks!
@ivargrimstad @jelemux Could you check the PR again and approve? Thanks!
@ivargrimstad @jelemux Ah, sorry. Looks like your approval is still valid. Never mind. :-) |
Hi all,
I just had a little bit of time to begin with the specification of HTML form method overwrites. We already have this mechanism in Krazo, so I used the implementation there as inspiration for the default implementation in the spec. As this is my first addition to the spec, I'm pretty sure there are a lot of things I can do better.
Please let me know what you think about this draft @eclipse-ee4j/ee4j-mvc-committers and anyone else interested.