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

Specify overwrite mechanism for form methods #72

Merged
merged 2 commits into from
Mar 1, 2022
Merged

Specify overwrite mechanism for form methods #72

merged 2 commits into from
Mar 1, 2022

Conversation

erdlet
Copy link
Contributor

@erdlet erdlet commented Jan 4, 2022

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.

@erdlet erdlet added this to the 2.1 milestone Jan 4, 2022
@erdlet erdlet self-assigned this Jan 4, 2022
Copy link
Member

@ivargrimstad ivargrimstad left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@chkal chkal left a 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";
Copy link
Contributor

Choose a reason for hiding this comment

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

Two comments:

  1. 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.
  2. Maybe we should allow to customize the name of the form field via some configuration parameter?

Copy link
Contributor Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a < missing?

Copy link
Contributor Author

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 :)

@erdlet
Copy link
Contributor Author

erdlet commented Jan 9, 2022

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.

@chkal
Copy link
Contributor

chkal commented Jan 9, 2022

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.

@erdlet
Copy link
Contributor Author

erdlet commented Jan 16, 2022

Hi @eclipse-ee4j/ee4j-mvc-committers,

I changed the proposal according to my and @chkal's thoughts. I think this draft is enough to start and will cover 99% of the common use-cases. Would be great to get some feedback.

@jelemux Maybe you want to give some feedback too?

@jelemux
Copy link

jelemux commented Jan 19, 2022

So if I understand correctly, we can have a form which sends a POST but because of the hidden input MVC interprets it for example like a PATCH. Therefore a form like that could call a controller with a @PATCH method. Is this correct?
If so, this looks good to me.

Will there be TCK tests for this?

@erdlet
Copy link
Contributor Author

erdlet commented Jan 19, 2022

Thanks @jelemux for your feedback!

So if I understand correctly, we can have a form which sends a POST but because of the hidden input MVC interprets it for example like a PATCH. Therefore a form like that could call a controller with a @patch method. Is this correct?

Absolutely correct 👍

Will there be TCK tests for this?

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.

Copy link
Contributor

@chkal chkal left a 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.

@erdlet
Copy link
Contributor Author

erdlet commented Feb 15, 2022

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.

Copy link
Contributor

@chkal chkal left a 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. :-)

@erdlet
Copy link
Contributor Author

erdlet commented Feb 21, 2022

@chkal thanks for the feedback. I hope the spec chapter is fine now :)

@chkal
Copy link
Contributor

chkal commented Feb 27, 2022

Awesome! Thanks a lot for applying the changes.

One last thing. I think the new chapter is still missing in the mvc-spec.asciidoc file and therefore not included in the resulting PDF, or am I missing something. Sorry, just noticed this while looking at all the changes in the PR.

@erdlet
Copy link
Contributor Author

erdlet commented Feb 27, 2022

Thanks @chkal, I really missed to add the new chapter 👍

Copy link
Contributor

@chkal chkal left a 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!

@chkal
Copy link
Contributor

chkal commented Feb 27, 2022

@ivargrimstad @jelemux Ah, sorry. Looks like your approval is still valid. Never mind. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants