Skip to main content

[jsr362-experts:] Portlet 3.0 Ajax and CDI @RequestScoped

  • From: Neil Griffin < >
  • To:
  • Subject: [jsr362-experts:] Portlet 3.0 Ajax and CDI @RequestScoped
  • Date: Tue, 4 Feb 2014 10:01:07 -0500

Hi Scott,

Thank you for all of the individual emails you sent in response to the 
Portlet 3.0 Ajax Proposal (Alternate) document. You made many excellent 
points, and I look forward to discussing the details verbally and/or by email.

For today's phone call, I think it would be of great benefit to discuss a 
closely related issue: Portlet 3.0 alignment with CDI. Whatever solution we 
arrive at for Ajax, it needs to take CDI into consideration.

Consider the following two classes:

        import javax.inject.Inject; 
        public class MyPortlet extends GenericPortlet {

                @Inject PortletBean portletBean;

                protected void processAction(ActionRequest request, 
ActionResponse response) {
                        portletBean.setFoo("1234");
                }

                protected void doView(RenderRequest request, RenderResponse 
response) {
                        Writer writer = response.getWriter();
                        writer.write("<span>");
                        writer.write(portletBean.getFoo());
                        writer.write("</span>");
                }
        }

        import javax.enterprise.context.RequestScoped;
        import javax.inject.Named;
        @Named
        @RequestScoped
        public class PortletBean {

                private String foo;

                public String getFoo() {
                        return foo;
                }

                public void setFoo(String foo) {
                        this.foo = foo;
                }

        }

Here is the problem we need to solve -- with Portlet 2.0, the rendered markup 
is:

        <span>null</span>

This is because CDI creates an instance PortletBean for each individual 
HttpServletRequest: 1) During the ActionRequest/EventRequest and 2) During 
the RenderRequest.

In order to remedy this, Mike Freedman proposed a new CDI annotation that 
would be provided by the Portlet 3.0 API:

@PortletLifecycleScoped - Custom CDI scope that spans from the 
ACTION_PHASE/EVENT_PHASE into the RENDER_PHASE of the portlet lifecycle.

(Mike also proposed @PortletRedisplayScoped, but that is a different use-case 
we should probably discuss separately).


Best Regards,

Neil



[jsr362-experts:] Portlet 3.0 Ajax and CDI @RequestScoped

Neil Griffin 02/04/2014

[jsr362-experts:] Re: Portlet 3.0 Ajax and CDI @RequestScoped

Martin Scott Nicklous 02/04/2014
 
 
Close
loading
Please Confirm
Close