3

I have a p:command button as shown below.

<p:commandButton id="settings" ajax="false" onComplete="window.alert('sometext');"      value="#{messages.settings}"
styleClass="cancelButton" style="font-family: sans-serif, Arial, Helvetica, Geneva; font-size: 10pt; width: 90px;" /></td>

I want this button to run a java-script onComplete or onClick but I can not get any of them to work. I actually want it to open a popup but here I have tried with an easier script to just do an alert. But this does not work either. Nothing happens at all.

Can anyone help me?

1 Answer 1

7

First : there is no capitals in onxxx (where xxx is start / complete / success)

Since you set ajax="false" your button won't do any ajax , which means that onstart / oncomplete / onsuccess won't be triggered at all

Use onclick="alert('wow')"

If you will remove the ajax="false" you will be able to use oncomplete="alert('wow')"

Sign up to request clarification or add additional context in comments.

4 Comments

The ajax=false is just a paste error from me. I actually have it removed in my xhtml page. So even if I change oncomplete to lower-case and remove ajax=false it still does not work.
is it inside h:form ? show more code , how about onclick="alert('wow')" does it work?
Yes I have, I however found <ui:composition> in the code and I do not think that this should be there? When remove that it seems like it is working better, havent got the alert yet thou. I'm in the middle of migrating some very old xhtml to jsf2 and primefaces so there is some more stuff in the way.
I have fixed the new problems that I got when I removed the ui:composition now. However I'm back where I started with no alert showing. In my xhtml I have <h:head> and <h:body> and <h:form> form and body are the ones around my p:commandbutton. And I have the 4 needed xmlns found at primefaces.org/gettingStarted.html. Any new idea how to fix it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.