Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to bind form based actions like 'Save' to designated Java classes mentioned in xwork in Confluence

angela simmons July 8, 2012

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")
<html>
<head>
   <title>Freeway Project Creation</title>
   <meta name="decorator" content="atl.general" />   
 </head>

 <content tag="key">$action.space.key</content>

<body>    

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

       
       <div >
   			 <table width="95%" border=0 cellspacing=0 cellpadding=5>
			   <form name="editspace" method="POST" >
           
            #bodytag( "TextField" "label='space-name'" "name='name'" "size=40" )
            #param ("labelwidth" "100")
            #param ("tdcolor" "f0f0f0")
            #end
            
            <tr>
                <td colspan="2" align="center">
                    #tag( "Submit" "name='confirm'" "value='update.name'" "theme='notable'" )
                    #tag( "Submit" "name='cancel'" "value='cancel.name'" "theme='notable'" )
                </td>
            </tr>

        </form>
    </table>
</div>
        
   
       
    #end
#end    
</body>
</html>

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

1 answer

1 vote
JamesJ July 9, 2012
  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<>>
angela simmons July 9, 2012

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 ?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events