views:

1183

answers:

3

Hello,

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.

+4  A: 

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.

BalusC
+1  A: 

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.

Naganalf
To be honest, I was thinking of two things at once, and would have edited the question having tried it except the end of my working day came and I was out the door. +1 for your observation..
Mark Lewis
A: 

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> ?

Max tay