I am developing a plugin that has a web-item connected to an xwork module, which displays a velocity template with a form, as such:
<div>
<form id="form" class="aui" method="post" action="#">
<fieldset>
<button type="button" onClick="fetchAllPagesTitlesOnClick()" style="margin: 2vh auto; display: block;">Get All Pages</button>
<div style="display: block;"></div>
<label for="pageTiles" style="margin: 2vh 2vw;">Select Page Title:</label>
<select name="pageTitles" id="pageTitleSel" style="margin: 2vh auto;" onchange="fetchVersionsOfPage()"></select>
<button type="button" onClick="fetchPageVersionsOnClick()" style="margin: 2vh auto; display: block;">Get All Versions</button>
<label for="pageVersion1" style="margin: 2vh 2vw;">Select Page Version:</label>
<select name="pageVersion1" style="margin: 2vh auto;" id="pageVersionSel1" onChange="fetchPageVersionContent(1)"></select>
<div style="display: block;"></div>
<label for="pageVersion2" style="margin: 2vh 2vw;">Select Page Version:</label>
<select name="pageVersion2" style="margin: 2vh auto;" id="pageVersionSel2" onChange="fetchPageVersionContent(2)"></select>
<div style="display: block;"></div>
<button type="submit" form="form" value="Submit" style="margin: 2vh auto; display: block;">Submit</button>
</fieldset>
</form>
</div>
My question is: how do I post the selected values onto another velocity template?
HI
I believe you should define an xwork action (in your plugin) and post to this action (which in turn does what you need and render the "other" template).
https://developer.atlassian.com/server/confluence/adding-a-custom-action-to-confluence/
Alex
Hi Alex, thanks for replying. I did what you said and created another xwork action, as such:
<xwork name="test-xwork" key="test-xwork">
<description key="test-xwork.desc">#</description>
<package name="test" extends="default" namespace="/test">
<default-interceptor-ref name="validatingStack"/>
<action name="test-xwork-action" class="com.example.plugin.AnotherAction">
<result name="success" type="velocity">/velocity/result.vm</result>
</action>
</package>
</xwork>
and add action="/test/test-xwork-action" into the form tag.
But when I submitted the form, Http status 404 came up. What did I do wrong?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could be multiple reasons
Alex
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the reply, Alex. The action class extends ConfluenceActionSupport
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The actions are called via .action
/test/test-xwork-action.action
And you probably need to have a context path in front (for example if Confluence is run in /wiki or /confluence web context)
${req.contextPath}/test/test-xwork-action.action
404 may also be thrown when the template to render cannot be found ( make sure the path is correct - /velocity/result.vm)
Alex
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Alex, your solution works. Thanks so much! One last question, how do I access the selected values from the first velocity template (the one with the form) from the second velocity template?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The best way is to define a parameter in your action with the same name as the parameter in the form (select or input) and create getters/setters
this way the parameter will be automatically populated from form (request) to action
action classes in Confluence/xwork are thread safe (new instance is created for each request)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
But how will I be able to get the parameter value from the Java action class to the template?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Basically, the same way... defining the field in your class and having getters to get it's value
Assuming the field name is "myfield" and you have defined a getter:
public String getMyfield() {
return myfield;
}
In this case you can access it in the Velocity template via ${myfield}
Alex
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.