How to invoke xwork action in plugin and stay in context of wiki page

I have a plugin that has an HTML form (on a velocity template) that submits to an xwork action for the plugin.
I tried to get the form to post and have the Confluence page render with the macro in context on the page with the results of the action processed but I can’t get that to work.
I’m using an absolute URL for the form action and that opens a new tab/page and renders the results of the action (via the velocity template) out of context from the Confluence page the macro lives on:

<form id="foo_form" action="$req.contextPath/plugins/foo/process-form.action" method="POST" name="fooForm">

I suppose I could implement REST endpoints to do what I need instead of the xwork action but I’m refactoring an existing plugin that used to post a form back to the enclosing page and I want to take the simplest path for now.

The form submittal back to the page (using the vewpage.action of Confluence) worked fine in old versions of Confluence but is a HTTP 405 in Confluence 7+ (probably a security change).

The old form was like this:

<form id="foo_form" action="${req.contextPath}/pages/viewpage.action" method="POST" name="fooForm">
  <input type="hidden" name="pageId" value="${pageId}"/>


1 Like

There is a difference between old Confluence (testing w/ 5.9.8) vs new Confluence (7.3.1) w.r.t. handling requests for xwork actions.

Old Confluence is much more permissive and allows you to post back to Confluence using ANY action. You can post back to foo.action and not have a foo action and it renders the Confluence page and invokes your macro’s execute() method. You can write a macro that processes any form submitted to foo.action.

That’s probably a loophole that has been closed, but our macro had depended on being able to post back to Confluence’s viewpage.action and process it’s form and that is now a HTTP 405.

New Confluence gives a HTTP 405 response for a post to some non-existent foo.action (sounds good to me) but it also does it for a form that is posted back to the viewpage.action (that broke this macro).

I’m looking for some way for a macro to process a form upon submittal, using an xwork action… but I want the macro to be rendered in the context of the Confluence wiki when the response is processed. I can invoke the action from a macro that is on a wiki page and the response is rendered outside of its wiki context but it needs to stay on the wiki page.