How to bind form based actions like 'Save' to designated Java classes mentioned in xwork in Confluence
Asked by angela simmons:

Hi All,  
I have made some significant progress in my customization efforst thanks to your help and looking forward to move forward similarly.  
I have created the custom tab in the 'Advanced' tab and it now looks like this <http://imageshack.us/f/809/newpageg.png/> . I have been able to add a text field as well as a 'Save' button. I actually followed the 'Edit Space Details' option and took two of its form elements to achieve the output.  
This is how my VM looks now.

```
##requireResource("confluence.web.resources:space-admin")&lt;html&gt;&lt;head&gt;   &lt;title&gt;Freeway Project Creation&lt;/title&gt;   &lt;meta name="decorator" content="atl.general" /&gt;    &lt;/head&gt; &lt;content tag="key"&gt;$action.space.key&lt;/content&gt;&lt;body&gt;    #applyDecorator("root")    #decoratorParam("helper" $action.helper)    #decoratorParam("context" "space-administration")    #decoratorParam("mode" "view-space-administration")    #applyDecorator ("root")        #decoratorParam ("context" "spaceadminpanel")        #decoratorParam ("selection" "add-fpc-label-action-web-ui")        #decoratorParam ("title" $action.getText("action.name"))        #decoratorParam ("selectedTab" "admin")        #decoratorParam("helper" $action.helper)               &lt;div &gt;   			 &lt;table width="95%" border=0 cellspacing=0 cellpadding=5&gt;			   &lt;form name="editspace" method="POST" &gt;                       #bodytag( "TextField" "label='space-name'" "name='name'" "size=40" )            #param ("labelwidth" "100")            #param ("tdcolor" "f0f0f0")            #end                        &lt;tr&gt;                &lt;td colspan="2" align="center"&gt;                    #tag( "Submit" "name='confirm'" "value='update.name'" "theme='notable'" )                    #tag( "Submit" "name='cancel'" "value='cancel.name'" "theme='notable'" )                &lt;/td&gt;            &lt;/tr&gt;        &lt;/form&gt;    &lt;/table&gt;&lt;/div&gt;                      #end#end    &lt;/body&gt;&lt;/html&gt;
```

I would like to understand how this interaction with my JAVA class will result in the output like. For eg: I will enter the name in the text box for name and hit save and on a resulting page it must display the name entered.

As of now my designated java class looks like this.

```
package com.atlassian.myorg;import com.atlassian.confluence.core.ConfluenceActionSupport;import com.atlassian.confluence.pages.AbstractPage;import com.atlassian.confluence.pages.actions.PageAware;import com.opensymphony.xwork.Action;/** * The simplest action possible */public class FreewayProjectAction extends ConfluenceActionSupport {    @Override    public String execute() throws Exception    {        return Action.SUCCESS;    }}
```

So I have 3 questions:

1. The 'Edit Space Details' shows the following URL 'http://localhost:1990/confluence/spaces/doeditspace.action?key=LBTEST' when i mouse over the 'Save' button. I am assuming that its governing Java class is EditSpaceDetails. So is the doEdit() method (see here <http://imageshack.us/f/542/decompdoedit.png/>)inside that class that swings into action when we try to save the edit action of the space ? Can i get to see the xml that has this mapping specifically for this edit space details action? Is my assumptin correct ?

2. In order to have such a functionality i have mentioned earlier i.e. displaying the name entered in my custom page as detailed above what will be the changes required in my Java class.

3. In the page i have just customised there is the text box and the label is 'Name' . Should i use a different xml so that i can provide my custom label like "Project Name" ?

Please do kindly advice me on the same.

Thanks   
Angie


Answers:
author: JamesJ
body: 1. There are two ways of doing actions in confluence. One is one action class per action, in this you define an execute() method, and that gets executed. If you want another action for when you submit the form, you create a new class, eg SaveFreewayProjectAction, with an execute method. The other way is in the XML for for the action, define a method parameter, eg method="doEdit", and then for each of your actions (each one still has to be declared individual in the XML plugins file), you write a corresponding method. In this method I think you must not implement the execute() method yourself, each one has to have their own method.
2. If you define a setter for name (void setName(String name)) in your action class, then when the form gets submitted with a name parameter, it will be passed to the setter. You can then use that value when your action is executed. If you want to access that (or a preloaded) value from the template, define a getter (String getName()) that returns it, and then you can access it from the template using $action.name
3. If you don't want internationalisation, just put the name you want in the label. If you want internationalisation, read this: [https://confluence.atlassian.com/display/DISC/i18n+in+Confluence+Plugin+Development\</li\<\>\>](https://confluence.atlassian.com/display/DISC/i18n+in+Confluence+Plugin+Development%3C/li)

comments: author: angela simmons
body: Hi James,

Thanks for the support . As a first try of using my custom jars inside the execute, i Added few of my jars to the build path in my project . But stil i am getting class not found error when i run the build. The eclipse autosugest seems to easily identify the classes inside my jar. Is there a different way to import jars in a custom plugin ?


Tags: app

custom-field

velocity