Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4366

Action methods should accept arguments like @QueryParam, @FormParam, @PathParam and specific request methods GET, PUT, POST etc

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • 7.1.0
    • Core Actions

    Description

      Struts2 action methods should accept arguments just like JAX-RS specs. Also certain method types should be allowed only like GET, PUT, POST, DELTE.
      Inspiration might be taken from struts-json plugin @SMDMthod but that is not a real action method.

      If there are multiple action methods in a Action class then it becomes less obvious which variables are used for a particular action method.

      Ex.

          @ActionPath("/books/{id}")
          public String showAction(@PathParam("id") String id,
                                                  @QueryParam("name") String name) {
      		...
      		return "success";
          }
      

      Also flexible return types as defined in JAX-RS would be great or atleast

      Result.json(myObject).includeActionErrors().includeActionMessages().done();
      Result.string(myString).done();
      Result.create("json").from(myObject).param("includeActionErrors,includeActionMessages").done();
      

      The action method return type can be to denote builder like result. The closest in struts I can see is HttpHeaderResult. But this does not allow arbritrary string result and let the end user create the string as json or plain text.

         @Action
         public Result showAction(...){}
      

      Inspiration can be taken from struts2-json-plugin#SMDMethod and https://github.com/bastengao/struts2-freeroute

      Attachments

        Activity

          People

            Unassigned Unassigned
            samarjit samarjit samanta
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: