13 Replies Latest reply on Aug 1, 2007 6:50 PM by Shanmugaraja Chellappen

    Unable to Access a preference values from portlet-instances.

    Shanmugaraja Chellappen Newbie

      I have a portlet, I have defined portlet preference in portlet.xml and portlet-instances.xml, How ever I am unable to access the preference value set in the portlet-instance.xml. While Deploying the war file i am getting the following error.

      Any help is highly appreciated.


      13:14:54,305 INFO [PortletAppDeployment] Parsing /CMSRenderer/jboss-portlet.xml
      13:14:54,335 INFO [PortletAppDeployment] These instances have been found in -object.xml, you should put them in the file C:\bgnew\jboss-4.2.0.GA\server\portal\.\tmp\deploy\tmp21190CMSRenderer-exp.war\WEB-INF/portlet-instances.xml
      13:14:54,335 INFO [PortletAppDeployment] <?xml version="1.0" encoding="utf-8" standalone="yes"?>



      <instance-id>cmsrenderInstance</instance-id>
      <portlet-ref>CMSRender</portlet-ref>




      13:14:54,705 INFO [TomcatDeployer] deploy, ctxPath=/download, warUrl=.../tmp/deploy/tmp21191download-exp.war/
      13:14:55,316 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/
      13:14:55,927 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8180
      13:14:55,977 INFO [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8109


        • 1. Re: Unable to Access a preference values from portlet-instan
          Peter Johnson Master

          Any preferences you set in portlet-instances.xml you must also define in portal.xml because the preference in portlet-instances.xml only override existing preferences in portal.xml.

          The INFO messages you posted seems to have more to do with how the portlet instances are defined, not with preferences per-se.

          • 2. Re: Unable to Access a preference values from portlet-instan
            Shanmugaraja Chellappen Newbie

            Peter, thanks a lot for you immediate response.

            Do you mean the preference to be deified in -object.xml or portal.xml, if so in portal.xml where could i find the portal.xml. If you could throw some more light, it would be great.



            • 3. Re: Unable to Access a preference values from portlet-instan
              Peter Johnson Master

              Sorry, typo, meant to type 'portlet.xml', not 'portal.xml'.

              • 4. Re: Unable to Access a preference values from portlet-instan
                Shanmugaraja Chellappen Newbie

                Thanks a lot peter for you Immediate Response,

                I am able to access the preference value from the portlet.xml.

                However I am not able to access the value I set in the portlet-instances.xml for the same preference. The values of the preference are set to be different in portlet.xml and portlet-instances.xml, the name is same in both the xml files. I would like to get the value set in the portlet-instances.xml file. if you could help me it would be great. Thanks a lot

                • 5. Re: Unable to Access a preference values from portlet-instan
                  Peter Johnson Master

                  From what you describe, this should work - you should be getting the value of the preference as defined in portlet-instances.xml.

                  Please post your portlet.xml, portlet-instances.xml, *-object.xml and the code from your portlet that accesses the preference. You don't have to post the entire files, just enough to show one of the preferences you are having an issue with and how the portlet instance and portlet window(object) are defined.

                  • 6. Re: Unable to Access a preference values from portlet-instan
                    Shanmugaraja Chellappen Newbie

                    Thanks a lot for you time and help. Please find below the xml file and the code. I am using jboss 4.2.0 GA and portal 2.6

                    Note: Some of the Element Names are Stripped in the display. I do not know why



                    portlet.xml
                    ============================================
                    <portlet-app version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="http://java.sun.com/xml/ns/portlet"
                    xmlns="http://java.sun.com/xml/ns/portlet">

                    CMS Render Portlet
                    <portlet-name>CMSRender</portlet-name>
                    <display-name>CMS Render Portlet</display-name>
                    <portlet-class>com.portlet.PlainRenderPortlet</portlet-class>
                    <portlet-info>
                    CMS Renderer Title
                    </portlet-info>

                    <mime-type>text/html</mime-type>
                    <portlet-mode>VIEW</portlet-mode>
                    <portlet-mode>EDIT_CONTENT</portlet-mode>

                    <portlet-preferences>

                    path
                    /Company Home/highlights/sales.html

                    </portlet-preferences>

                    </portlet-app>


                    portlet-instances.xml
                    ================================================
                    <?xml version="1.0" standalone="yes"?>
                    <!DOCTYPE deployments PUBLIC
                    "-//JBoss Portal//DTD Portlet Instances 2.6//EN"
                    "http://www.jboss.org/portal/dtd/portlet-instances_2_6.dtd">



                    <instance-id>cmsrenderInstance</instance-id>
                    <portlet-ref>CMSRender</portlet-ref>


                    path
                    /Company Home/highlights/Manager.tml






                    -object.xml
                    ================================================
                    <?xml version="1.0" encoding="UTF-8"?>
                    <!DOCTYPE deployments PUBLIC
                    "-//JBoss Portal//DTD Portal Object 2.6//EN"
                    "http://www.jboss.org/portal/dtd/dtd/portal-object_2_6.dtd">


                    <parent-ref>default</parent-ref>
                    <if-exists>overwrite</if-exists>

                    <instance-name>cmsrenderInstance</instance-name>
                    <component-ref>CMSRenderer.CMSRender</component-ref>



                    <parent-ref>default</parent-ref>
                    <if-exists>overwrite</if-exists>

                    <page-name>CMSRenderPage</page-name>

                    <window-name>cmsrenderWindow</window-name>
                    <instance-ref>cmsrenderInstance</instance-ref>
                    true
                    center
                    0





                    Portlet Code:

                    protected void doView(RenderRequest rReq, RenderResponse rRes) throws PortletException, PortletSecurityException, IOException{
                    rRes.setContentType("text/html");
                    PrintWriter writer = rRes.getWriter();
                    try{
                    String path=rReq.getPreferences().getValue("path", "/Company Home/highlights/default.html");
                    System.out.println("Path:"+path);
                    /*
                    I am doing my stuff here after getting the path from the peference.

                    */
                    writer.println(getHtml());
                    }
                    catch(Exception e){
                    e.printStackTrace();
                    }
                    }

                    • 7. Re: Unable to Access a preference values from portlet-instan
                      Peter Johnson Master

                      When posting XML text, bracket the text with [ code ]...[ /code ] brackets (without the spaces). One way to do this is to select the XML text and click the 'Code' button. (By the way, one can still see the full XML by clicking the 'View Source' button on the browser.)

                      What you have is not that much different from what I have, and I don't see anything obvious that is wrong. I will try to adapt my portlet to your XML files and see how it goes. I'll let you know the results.

                      • 8. Re: Unable to Access a preference values from portlet-instan
                        Peter Johnson Master

                        I tried this. It worked for me. What I got was the preference as stored in the portlet-instances.xml file. If you like, I can post all of my files.

                        • 9. Re: Unable to Access a preference values from portlet-instan
                          Shanmugaraja Chellappen Newbie

                          Peter Thank you so much for your try. Could you please post all your files it would be definitely helpful.

                          • 10. Re: Unable to Access a preference values from portlet-instan
                            Peter Johnson Master

                            Here are the files.

                            I used JBoss AS 4.0.2.GA and Portal 2.6.0.

                            package com.portlet;
                            import java.io.*;
                            import javax.portlet.*;
                            public class PlainRenderPortlet extends GenericPortlet {
                             @Override
                             protected void doView(RenderRequest request, RenderResponse response)
                             throws PortletException,IOException {
                             response.setContentType("text/html");
                             PrintWriter writer = response.getWriter();
                             try {
                             String path = request.getPreferences().getValue("path", "**default**");
                             writer.format("<h2>path=\"%s\"</h2>", path);
                             } catch (Exception e) {
                             e.printStackTrace();
                             }
                             }
                            }


                            portlet.xml:

                            <?xml version="1.0" encoding="UTF-8"?>
                            <portlet-app
                             version="1.0"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xsi:schemaLocation=
                             "http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
                             xmlns="http://java.sun.com/xml/ns/portlet"
                             >
                             <portlet>
                             <description>CMS Render Portlet</description>
                             <portlet-name>CMSRender</portlet-name>
                             <display-name>CMS Render Portlet</display-name>
                             <portlet-class>com.portlet.PlainRenderPortlet</portlet-class>
                             <portlet-info>
                             <title>CMS Render Title</title>
                             </portlet-info>
                             <supports>
                             <mime-type>text/html</mime-type>
                             <portlet-mode>VIEW</portlet-mode>
                             <portlet-mode>EDIT_CONTENT</portlet-mode>
                             </supports>
                             <portlet-preferences>
                             <preference>
                             <name>path</name>
                             <value>/Company Home/highlights/sales.html</value>
                             </preference>
                             </portlet-preferences>
                             </portlet>
                            </portlet-app>


                            portlet-instances.xml:

                            <?xml version="1.0" standalone="yes"?>
                            <!DOCTYPE deployments PUBLIC
                             "-//JBoss Portal//DTD Portlet Instances 2.6//EN"
                             "http://www.jboss.org/portal/dtd/portlet-instances_2_6.dtd">
                            <deployments>
                             <deployment>
                             <instance>
                             <instance-id>cmsrenderInstance</instance-id>
                             <portlet-ref>CMSRender</portlet-ref>
                             <preferences>
                             <preference>
                             <name>path</name>
                             <value>/Company Home/highlights/Manager.tml</value>
                             </preference>
                             </preferences>
                             </instance>
                             </deployment>
                            </deployments>


                            render-object.xml:

                            <?xml version="1.0" encoding="UTF-8" ?>
                            <!DOCTYPE deployments PUBLIC
                             "-//JBoss Portal//DTD Portal Object 2.6//EN"
                             "http://www.jboss.org/portal/dtd/dtd/portal-object_2_6.dtd">
                            <deployments>
                             <deployment>
                             <parent-ref>default</parent-ref>
                             <if-exists>overwrite</if-exists>
                             <instance>
                             <instance-name>cmsrenderInstance</instance-name>
                             <component-ref>CMSRenderer.CMSRender</component-ref>
                             </instance>
                             </deployment>
                             <deployment>
                             <parent-ref>default</parent-ref>
                             <if-exists>overwrite</if-exists>
                             <page>
                             <page-name>CMSRenderPage</page-name>
                             <window>
                             <window-name>cmsrenderWindow</window-name>
                             <instance-ref>cmsrenderInstance</instance-ref>
                             <default>true</default>
                             <region>center</region>
                             <height>0</height>
                             </window>
                             </page>
                             </deployment>
                            </deployments>


                            web.xml:

                            <?xml version="1.0" encoding="UTF-8"?>
                            <web-app
                             xmlns="http://java.sun.com/xml/ns/j2ee"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
                             http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
                             version="2.4">
                            </web-app>


                            jboss-app.xml:

                            <jboss-app>
                             <app-name>render</app-name>
                            </jboss-app>




                            • 11. Re: Unable to Access a preference values from portlet-instan
                              Shanmugaraja Chellappen Newbie

                              Hi Peter, First I would like to appreciate you for your time and help.

                              I used the same code you have posted.

                              I have made only two changes one is in the portlet.xml - the package
                              of the portlet.

                              <portlet-class>com.uni.portal.portlet.PlainRenderPortlet</portlet-class>


                              another one in the render-object.xml -

                              <component-ref>render.CMSRender</component-ref>


                              Before deploying i cleaned the database and deployed the war. Still the value from the portlet.xml is getting reflected. It is strange that the value from the portlet-instances.xml is not getting overridden.

                              Is there any other setting i need do to solve the issue. Any help is appreciated


                              • 12. Re: Unable to Access a preference values from portlet-instan
                                Peter Johnson Master

                                There is no other setting. I also used a clean install of AS and Portal, with a new database. One thing I did do, though, is bring up the AS first and then I deployed the WAR file containing my portlet. When I accessed the CMSRenderPage, I saw the text "path=/Company Home/highlights/Manager.tml".

                                • 13. Re: Unable to Access a preference values from portlet-instan
                                  Shanmugaraja Chellappen Newbie

                                  Hi Peter, Thanks a lot for you help

                                  It is working for me now. I removed the following from the render-obejct.xml

                                  <deployment>
                                   <parent-ref>default</parent-ref>
                                   <if-exists>overwrite</if-exists>
                                   <instance>
                                   <instance-name>cmsrenderInstance</instance-name>
                                   <component-ref>render.CMSRender</component-ref>
                                   </instance>
                                   </deployment>