volvox
volvox

Reputation: 3060

How to use RichFaces a4j:commandButton not using submit

I have an a4j:commandButton which looks like this

    <a4j:commandButton id="stopBtn" type="button" reRender="lastOp"
  action="#{MyBacking.stop}" value="Stop" />
 </a4j:commandButton>

When the app is deployed, and the button clicked, the stop() method is not being called. All the a4j:commandButton examples refer to forms, but this button is not in a form - it's a button the user is going to use to cause the server to run some back-end logic. At the moment, the method is

    public void stopNode() {
 logger.info("STOPPING");
 setLastOp("Stopped.");
}

Other methods which don't use this type of button are updating the lastOp field, but I'm not seeing anything on the console with this one. Am I right to cast this as a button? Should I put this in a h:form tag?

The firebug console says:

this._form is null

which I don't understand.

Any help well appreciated.

Upvotes: 2

Views: 20538

Answers (4)

Max Katz
Max Katz

Reputation: 1582

If for some reason you don't want to place the button inside a form, you can do something like this:

<a4j:commandButton onclick="fireAjax()"/>

<h:form>
   <a4j:jsFunction name="fireAjax" action=".."/>
</h:form>

Upvotes: 1

Max tay
Max tay

Reputation: 19

Look at your code:

<a4j:commandButton id="stopBtn" type="button" reRender="lastOp" action="#{MyBacking.stop}" value="Stop" /> 

You finished <a4j:commandButton with />, why need that orphan </a4j:commandButton> ?

Upvotes: 1

Naganalf
Naganalf

Reputation: 1101

Yes, wrap it in a form. I'm sure BalusC will post a detailed explanation while I'm typing my answer. (yup, there it is)

I have to ask why you didn't just try a form first, before posting here.

Upvotes: 2

BalusC
BalusC

Reputation: 1109865

UICommand components ought to be placed inside an UIForm component. So, your guess

Should I put this in a h:form tag?

is entirely correct :) This because they fire a POST request and the only (normal) way for that is using a HTML <form> element whose method attribute is set to "post". Firebug also says that a parent form element is been expected, but it resolved to null and thus no actions can be taken place.

Only "plain vanilla" links like h:outputLink and consorts doesn't need a form, because they just fires a GET request.

Upvotes: 7

Related Questions