9 Replies Latest reply on Apr 30, 2007 12:48 PM by fredf

    I can't instantiate the InstanceImpl class.

    fredf

      I have a portal with a two pages. On each page I have a window which shows a portlet. I want to use two different instances of the portlet for the windows (I have to identify each instance to populate it by specific data).
      I could define these two instances in the portlet-instances.xml but I need to do this in runtime, programmatically with the Portal API. How can I create a new Instance? Eclipse tells me I cant instantiate instances of InstanceImpl.

      Also, can I use this InstanceImpl instance's name as an attribute to setInstanceRef(String instance)?

        • 1. Re: I can't instantiate the InstanceImpl class.
          fredf

          I am using portal 2.4 and the class is not abstract.

          • 2. Re: I can't instantiate the InstanceImpl class.
            fredf

            I fixed it by putting the correct jar-fil (2.4, not 2.6) as external jar in eclipse.
            But now I can't call the setInstanceId on my instance? According to javadoc the method should exist but the compiler does not recognize it. Why?
            I provide the correct jar in my lib folder for javac.

            • 3. Re: I can't instantiate the InstanceImpl class.

              It is not a public API and it is therefore subject to changes (improvements).

              Nevertheless instances are container managed object managed by the InstanceContainer. You need to inject it in your PortletContext.

              • 4. Re: I can't instantiate the InstanceImpl class.
                fredf

                hello.

                I think I have solved it by doing this:

                 try{
                 w = page.createWindow("DocumentCell");
                 } catch ( Exception ex ) {
                 ex.printStackTrace();
                 }
                 InstanceImpl inst = new InstanceImpl();
                 String instanceId = "DocumentCell01";
                 inst.setInstanceId(instanceId);
                 inst.setPortletRef("DocumentPortlet");
                 w.setInstanceRef(instanceId);

                Where page is an instance of org.jboss.portal.core.model.portal.Page
                This way I create an instance and reference it by the window. Or have I missed something?



                • 5. Re: I can't instantiate the InstanceImpl class.
                  fredf

                  Forget my last reply. I fetched the InstanceContaner just as you suggested. Then I don't need to instantiate the InstanceImpl.

                  • 6. Re: I can't instantiate the InstanceImpl class.
                    fredf

                    I get a strange error when I try to create an Instance via the instancecontainer.

                    19:29:49,197 ERROR [STDERR] java.lang.IllegalArgumentException: Bad portlet id format AboutPortlet
                    19:29:49,200 ERROR [STDERR] at org.jboss.portal.federation.impl.FederatingPortletInvokerService.getFederatedPortletInvokerFor(FederatingPortletInvokerSer
                    vice.java:203)
                    19:29:49,201 ERROR [STDERR] at org.jboss.portal.federation.impl.FederatingPortletInvokerService.getPortlet(FederatingPortletInvokerService.java:137)
                    19:29:49,201 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor242.invoke(Unknown Source)
                    19:29:49,201 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    19:29:49,201 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                    19:29:49,201 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                    19:29:49,201 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                    19:29:49,201 ERROR [STDERR] at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                    19:29:49,201 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                    19:29:49,201 ERROR [STDERR] at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                    19:29:49,201 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                    19:29:49,201 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                    19:29:49,202 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                    19:29:49,202 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                    19:29:49,202 ERROR [STDERR] at $Proxy68.getPortlet(Unknown Source)
                    19:29:49,202 ERROR [STDERR] at org.jboss.portal.portlet.test.TestPortletInvoker.getPortlet(TestPortletInvoker.java:114)
                    19:29:49,202 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor241.invoke(Unknown Source)
                    19:29:49,202 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                    19:29:49,202 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:585)
                    19:29:49,202 ERROR [STDERR] at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
                    19:29:49,202 ERROR [STDERR] at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
                    19:29:49,202 ERROR [STDERR] at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
                    19:29:49,202 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                    19:29:49,202 ERROR [STDERR] at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
                    19:29:49,203 ERROR [STDERR] at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
                    19:29:49,203 ERROR [STDERR] at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
                    19:29:49,203 ERROR [STDERR] at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
                    19:29:49,203 ERROR [STDERR] at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
                    19:29:49,203 ERROR [STDERR] at $Proxy50.getPortlet(Unknown Source)
                    19:29:49,203 ERROR [STDERR] at org.jboss.portal.core.impl.model.instance.PersistentInstanceContainer.org$jboss$portal$core$impl$model$instance$Persistent
                    InstanceContainer$createInstance$aop(PersistentInstanceContainer.java:231)
                    19:29:49,203 ERROR [STDERR] at org.jboss.portal.core.impl.model.instance.PersistentInstanceContainer$createInstance_N891474739524950312.invokeNext(Persis
                    tentInstanceContainer$createInstance_N891474739524950312.java)
                    19:29:49,203 ERROR [STDERR] at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
                    19:29:49,203 ERROR [STDERR] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
                    19:29:49,203 ERROR [STDERR] at org.jboss.portal.core.impl.model.instance.PersistentInstanceContainer$createInstance_N891474739524950312.invokeNext(Persis
                    tentInstanceContainer$createInstance_N891474739524950312.java)
                    19:29:49,203 ERROR [STDERR] at org.jboss.portal.core.impl.model.instance.PersistentInstanceContainer.createInstance(PersistentInstanceContainer.java)
                    19:29:49,203 ERROR [STDERR] at org.jboss.portal.core.impl.model.instance.PersistentInstanceContainer.org$jboss$portal$core$impl$model$instance$Persistent
                    InstanceContainer$createInstance$aop(PersistentInstanceContainer.java:217)
                    19:29:49,204 ERROR [STDERR] at org.jboss.portal.core.impl.model.instance.PersistentInstanceContainer$createInstance_N8606718515158336098.invokeNext(Persi
                    stentInstanceContainer$createInstance_N8606718515158336098.java)
                    .
                    .
                    .
                    



                    this is the portlet definition in portlet.xml

                     <portlet>
                     <portlet-name>AboutPortlet</portlet-name>
                     <init-param>
                     <name>default-view</name>
                     <value>/about.jsp</value>
                     </init-param>
                     <portlet-class>org.apache.myfaces.portlet.MyFacesGenericPortlet</portlet-class>
                     <supports>
                     <mime-type>text/html</mime-type>
                     <portlet-mode>VIEW</portlet-mode>
                     </supports>
                     <portlet-info>
                     <title></title>
                     </portlet-info>
                     </portlet>


                    Window w = null;
                    String instanceId = "aboutinstance0001";
                    String portletRef = "AboutPortlet";
                    try{
                     w = page.createWindow("AboutPortletWindow");
                     instancecontainer.createInstance(instanceId, portletRef);
                    } catch ( Exception ex ) {
                     ex.printStackTrace();
                    }
                    w.setInstanceRef(instanceId);


                    Shouldn't this work? As long as I define the portlet in the portlet.xml I can reference it when I create the portletwindow and portletinstance through the API, right?

                    • 7. [SOLVED]
                      fredf

                      I fixed the problem by referencing the portlet with a correct path. I had to use 'local.web-app.portletreferencename' and not just 'portletreferencename'


                      /Fredrik

                      • 8. Re: [SOLVED]

                        A more correct way would be to browse the portlets offered by the PortletInvoker and recognize your portlet using the display name and use as reference the string returned by Portlet.getContext().getId()

                        "FredF" wrote:
                        I fixed the problem by referencing the portlet with a correct path. I had to use 'local.web-app.portletreferencename' and not just 'portletreferencename'


                        /Fredrik


                        • 9. Re: I can't instantiate the InstanceImpl class.
                          fredf

                          How can I get a reference to a portletinvocer object? I have a facesContext. Can find it in there?