5 Replies Latest reply on Jan 30, 2013 8:57 AM by sunilkcs

    Passing parameters to action class.

    sunilkcs

      Hi

          I have added a link to "blog-actions" and passing a parameter "blogid"  in that action class. How can i retrieve the parameter in my action class. This is my plugin.xml file

       

      <plugin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

              xsi:noNamespaceSchemaLocation="http://www.jivesoftware.com/schemas/clearspace/2_5/plugin.xsd">

          <name>jiveplugin</name>

          <description>jiveplugin</description>

          <author></author>

          <version>1.0.0</version>

          <minServerVersion>4.5</minServerVersion>

          <maxServerVersion>5.0.99</maxServerVersion>

         

          <!-- you will want to change your class name here! -->

          <class>SamplePlugin</class>

              <components> 

             <component id="blog-actions">

                 <tab id="blog-actions-tab">

                     <item id="createsr" name="Create SR">

                          <url>

                              <![CDATA[<@s.url action='createsr'>

                              <@s.param name='blog' value='${blog.ID?c}'/>

                              </@s.url>]]>

                          </url>

                     </item>

                 </tab>

             </component>

            </components>

       

      My struts.xml file which maps the action to java class.

       

      <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

              "http://struts.apache.org/dtds/struts-2.0.dtd">

      <struts> 

          <package name="example-actions" namespace="" extends="community-custom"> 

              <!-- Map the action name, sayhello, to the action class, SimpleAction. --> 

              <action name="createsr" class="com.example.clearspace.plugin.action.SimpleAction"> 

                  <!-- Specify the FTL file that should be used to present the data in the case of 

                       a "success" result (the default for an action class). --> 

                  <result name="success">/plugins/jiveplugin/resources/templates/simple-template.ftl</result> 

              </action> 

          </package> 

      </struts>

       

      how can i retrieve the passed 'blogid' (in the plugin.xml file) in my "SimpleAction" java class. Kindly help me. Thank You.

        • Re: Passing parameters to action class.
          manish0109

          You need to create setter and getter in your action class

           

          Create a variable in your action class as

          private String blogid;


          and create setter and getter functions.

          • Re: Passing parameters to action class.
            sunilkcs

            Hi Munish

                     I am able to retrieve the blogid  in my action class. I added few more lines of code in my "getMessage" function in my Java Action class. This is what referenced from my template file. Please see the template file.

             

            <html> 

                <head> 

                     <!-- Create a FreeMarker variable for the page title bar text, then 

                          use that variable in the <title> element. --> 

                    <#assign pageTitle="Hello World" /> 

                    <title>${pageTitle}</title> 

                    <content tag="pagetitle">${pageTitle}</content> 

                </head> 

                <body> 

                     <!-- Have the message appear a little down on the page and 

                          in the center, so it's easier to find. --> 

                     <br/> 

                    <p align="center">${message}</p> 

                </body> 

            </html>

             

            I am getting  this error

             

            Expression message is undefined on line 13, column 29 in plugins/jiveplugin/resources/templates/simple-template.ftl.

            The problematic instruction:

            ----------

            ==> ${message} [on line 13, column 27 in plugins/jiveplugin/resources/templates/simple-template.ftl]

            ----------

             

            Java backtrace for programmers:

            ----------

            freemarker.core.InvalidReferenceException: Expression message is undefined on line 13, column 29 in plugins/jiveplugin/resources/templates/simple-template.ftl.

                    at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)

                    at freemarker.core.Expression.getStringValue(Expression.java:118)

                    at freemarker.core.Expression.getStringValue(Expression.java:93)

                    at freemarker.core.DollarVariable.accept(DollarVariable.java:76)

                    at freemarker.core.Environment.visit(Environment.java:213)

                    at freemarker.core.MixedContent.accept(MixedContent.java:92)

                    at freemarker.core.Environment.visit(Environment.java:213)

                    at freemarker.core.Environment.process(Environment.java:193)

                    at com.jivesoftware.community.web.struts.FreemarkerResult.doExecute(FreemarkerResult.java:126)


            If i remove the additional lines of code added in "getMessage" function. It works perfectly. If i add some more line of code (Which basicallly access API's from another application), I am getting above error. No other changes made... What could be the reason here ?