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

    Passing parameters to action class.


          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"









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



             <component id="blog-actions">

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

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


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

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








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


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



          <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> 





      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.

          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.

            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.




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

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

                    <#assign pageTitle="Hello World" /> 


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



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

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


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




            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 ?