1

I want to render the JSP after the the processAction() method has been called out of an other method. I am using Liferay 6.2 and JBoss 7.1.1.

That's the method that have to call the processAction() and the doView() method:

@Override
    public void update(Observable arg0, Object arg1) {
        if(actualSite.equals("/views/measurement.jsp")) {
            this.x = (String) arg1;
            try {
                this.processAction(aRequest, aResponse); //works
                this.doView(rRequest, rResponse); //doesn't work
            } catch (IOException e) {
                e.printStackTrace();
            } catch (PortletException e) {
                e.printStackTrace();
            }
        }
    }

It works fine for processAction(), but for doView() I get this error:

[org.apache.jasper.runtime.JspFactoryImpl] (Thread-108) Exception initializing page context: java.lang.IllegalStateException: Page needs a session and none is available at org.apache.jasper.runtime.PageContextImpl._initialize(PageContextImpl.java:148) [jbossweb-7.0.13.Final.jar:] at org.apache.jasper.runtime.PageContextImpl.initialize(PageContextImpl.java:124) [jbossweb-7.0.13.Final.jar:] at org.apache.jasper.runtime.JspFactoryImpl.internalGetPageContext(JspFactoryImpl.java:106) [jbossweb-7.0.13.Final.jar:] at org.apache.jasper.runtime.JspFactoryImpl.getPageContext(JspFactoryImpl.java:62) [jbossweb-7.0.13.Final.jar:] at org.apache.jsp.views.measurement_jsp._jspService(measurement_jsp.java:52) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) [jbossweb-7.0.13.Final.jar:] at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) [jbossweb-7.0.13.Final.jar:] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [jbossweb-7.0.13.Final.jar:] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) [jbossweb-7.0.13.Final.jar:] at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116) [portal-service.jar:] at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:96) [portal-service.jar:] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:840) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:720) [jbossweb-7.0.13.Final.jar:] at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:657) [jbossweb-7.0.13.Final.jar:] at com.liferay.portlet.PortletRequestDispatcherImpl.dispatch(PortletRequestDispatcherImpl.java:331) at com.liferay.portlet.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:112) at com.liferay.util.bridges.mvc.MVCPortlet.include(MVCPortlet.java:371) [util-bridges.jar:] at com.liferay.util.bridges.mvc.MVCPortlet.include(MVCPortlet.java:387) [util-bridges.jar:] at de.pax.qm.measurement.Controller.doView(Controller.java:74) [classes:] at de.pax.qm.measurement.Controller.update(Controller.java:83) [classes:] at java.util.Observable.notifyObservers(Observable.java:142) [rt.jar:1.6.0_45]

I look forward for your advice.

2
  • 2
    Why do you want to use the processAction and doView method like this? These are life-cycle methods and not meant to be used this way.
    – Prakash K
    Sep 15, 2014 at 12:33
  • At normal, a button or something else renders a page or calls the processAction method. But here, I need to do it from the other way: The page have to display informations immediately, that comes to an undefined time. So I need to render the page when data is received by my MVCPortlet class.
    – jcomouth
    Sep 15, 2014 at 12:48

1 Answer 1

2

You can change the state of a portlet in the action phase, that is typically handled by the processAction method (or, for the many frameworks, an equivalent method). If you just arbitrarily call the method from a different phase (or from outside of the whole lifecycle at all), you - by definition - aren't in the action phase. Thus you can't change the state. And that's what this error message is about.

That's not to say that you can't get it to work, but it'll be a fully proprietary solution, far away from any best practices. Thus, I recommend to rethink what you actually want to achieve (from a business perspective) and come up with a proper architecture that stays within the boundary of the technology you chose.

Note, that no browser will redisplay your portlet just because something changed in the background. You'll have to trigger a reload yourself - either through ajax for a single portlet, or as a full page reload. How do you know if this is due? Well, you'll poll anyway, and you can easily use that poll phase to check if something changed in the backend/business logic. Think of the portlet as the UI to your business logic (that will change). But don't mess with the lifecycle of your UI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.