Slice icon indicating copy to clipboard operation
Slice copied to clipboard

Feature/injectable request params

Open royteeuwen opened this issue 8 years ago • 3 comments

Hey guys,

I have build this PR onto #119 , so please review that one first.

What I did in this one is go further on the request annotations, I have also added a RequestParameter annotation, where you can inject your request parameters in your slice model. Secondly I have also made it possible to actually adapt a request itself to the slice resource, where you could then achieve the following result(s):

Mapping to a servlet

@Component(
        service = Servlet.class,
        property = {
                "sling.servlet.paths=/bin/my-servlet"
        }
)
public class MyServlet extends SlingAllMethodsServlet {

    @Override
    protected void doGet(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response) throws ServletException, IOException {
        MyServletModel myServletModel = request.adaptTo(MyServletModel.class);
    }
}

@SliceResource
public class MyServletModel {

    @RequestParameter
    private String parameterOne;

    @RequestParameter
    private List<String> parametersTwo;

}

Mapping to a resource type

@Component(
        service = Servlet.class,
        property = {
                "sling.servlet.resourceTypes=slice-project/components/page/content",
                "sling.servlet.selectors=myselector"
        }
)
public class MyServlet extends SlingAllMethodsServlet {

    @Override
    protected void doGet(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response) throws ServletException, IOException {
        MyPageModel myServletModel = request.adaptTo(MyPageModel.class);
    }
}

@SliceResource
public class MyPageModel {

    @RequestParameter
    private String parameter;

    @JcrProperty
    private String title;

}

royteeuwen avatar Oct 13 '17 19:10 royteeuwen

Coverage Status

Coverage decreased (-1.4%) to 65.506% when pulling cab9f7aa60bf95a46bd419e73997275d35908437 on royteeuwen:feature/injectable-request-params into 382453cdaee33417a7cdf2a0eaee13ea6b2091fa on Cognifide:master.

coveralls avatar Oct 13 '17 19:10 coveralls

This a very nice feature! I'll review the code shortly, but having a quick glance it looks good too. Meanwhile, could you please create corresponding tickets in jira? This would be helpful. Cheers

mmajchrzak avatar Oct 17 '17 13:10 mmajchrzak

Done ;)

On 17 Oct 2017, at 15:26, Maciej Majchrzak [email protected] wrote:

This a very nice feature! I'll review the code shortly, but having a quick glance it looks good too. Meanwhile, could you please create corresponding tickets in jira? This would be helpful. Cheers

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Cognifide/Slice/pull/120#issuecomment-337230474, or mute the thread https://github.com/notifications/unsubscribe-auth/AEvNTmyYocFlOJQa3naa-r4Ixir4uCQKks5stKr4gaJpZM4P47ry.

royteeuwen avatar Oct 17 '17 14:10 royteeuwen