Ben
Ben

Reputation: 10298

in JSF - How to rerender a component on button press. (The smart way?)

I have a simple HTMLCommandButton that I want to cause a rerender to another component. I know of a simple way to do that - add an ajax support object and have it run on "onclick" event and rerender.

<h:commandButton value="Submit" action="#{actions.submitToDB}">
  <a4j:support event="onclick" reRender="Button0" />
</h:commandButton>

I figured there has to be a smarter way to do this with the on* attributes of the HTML CommandButton but I'm not sure what to write to cause the rerender (Using this alleged method)

Thanks!

Upvotes: 1

Views: 11916

Answers (1)

Bozho
Bozho

Reputation: 597382

No, there isn't a smarter way in the common case. This is the way to do it. You will have to do the following

  • set type="button" on the button.
  • set the action on the <a4j:support> rather than on the button istself.

In this particular case (a button) a shortcut will be:

<a4j:commandButton value="Submit"
       action="#{actions.submitToDB}" reRender="Button0" />

Upvotes: 5

Related Questions