JSF commandbutton not being called when adding primefaces ajax - jsf

I am facing an issue when trying to add javascript function to be called after the command button is called but I am only getting the javascript fuction "forGo()" being called but not the function register located in the managed bean when I remove the p:ajax code the function is executed succesfully but I need the forGo function to be executed too, I wrote this code two years ago and it was working fine, any advice would help, thanks.
<p:commandButton value="Register" actionListener="#{ClientMB.Register()}" >
<p:ajax event="click" oncomplete="forGo()"></p:ajax>
</p:commandButton></h:form>

I would suggest to remove the <p:ajax> and just use the <p:commandButton> oncomplete attribute directly:
<p:commandButton value="Register" actionListener="#{ClientMB.Register()}" oncomplete="forGo()" />

Related

primefaces p:inputSwitch not work in dialog while use update the dialog

I am doing a on-off with p:inputSwitch, it's in a dialog. When an ajax call inside a form happens in combination with an update on the inputSwitch, the inputSwitch behaves strange and always resets its state. Here is a simple reproducible example (without the need of a backing bean):
<h:form id="buttonForm">
<p:commandButton value="button" update="switch" oncomplete="PF('switchDialog').show();" />
<p:dialog widgetVar="switchDialog">
<p:inputSwitch id="switch" />
</p:dialog>
</h:form>
Interesting observations:
When you remove the h:form the problem is gone
When you remove the update parameter it works
When the p:inputSwitch is outside of the p:dialog it also works
Sorry for this zombie post but i've found a solution that can help.
Add in your
<p:dialog widgetVar="switchDialog" dynamic="true">
Regards

p:dialog form submit loses action method after RequestContext update

I have a small form inside my p:dialog:
<p:dialog id="commentDialog" header="#{managedBean.dialogHeader}" widgetVar="commentDialog" modal="true" resizable="true" height="auto">
<h:form>
<h:outputLabel for="comment" value="Comment:"/>
<p:inputTextarea id="comment" title="Comment"
rows="6" cols="33"
value="#{managedBean.comment}"
required="true"/>
<h:commandButton value="Submit" action="#{managedBean.dialogFormSubmit}"/>
</h:form>
</p:dialog>
Can you tell why, when I hit the Submit button, the dialog does get closed but the dialogFormSubmit() in the managed bean does not get invoked?
I also tried changing to p:commandButton thinking the functionality required the PrimeFaces variant of the h:commandButton but got the same.
The question is similar to this and I tried to do the same but couldn't make it work and also this one which doesn't really seem to have a workable answer.
UPDATE:
The dialog was being shown from the managed bean but was also updated (the solution for which I got here) prior to showing by using the RequestContext API in order to refresh the header:
RequestContext context = RequestContext.getCurrentInstance();
context.update("commentDialog");
context.execute("PF('commentDialog').show();");
I have come to realize that this malfunction occurs only when I update the dialog (middle line above). When I actually don't (which is not critical for the dialog functionality but the header appears blank), the submit action works fine. So the context update seems to be what's messing it up and I don't know how to get both the update while retaining the submit functionality. Could it be a bug in RequestContext.update()?

p:dialog not appearing after commandButton oncomplete

I am facing a strange issue and I am not able to find the cause.
I have a dataGrid in which I placed a commandButton.
<p:dataGrid paginator="true"
value="#{bean.searchedSystem}" var="searchedSystemObj"
columns="1" rows="6"
WidgetVar="CadModel" pageLinks="5" filteredValue="" >
<p:commandButton value="More Details..."
action="#{bean.viewMoreDetails(searchedSystemObj)}"
oncompleted="PF('testDialog').show()"/>
On action the bean is called, but it doesn't seem like the oncomplete is getting invoked.
<p:dialog header="Modal Dialog" widgetVar="testDialog"
modal="true" height="600" width="900">
All these are in a single form.
Any idea why ?
Solved:
I have solved this issue. Thank you guys for helping me.
The problem was due to the "processing image..."(like a please wait while processing stuff).. It was not processed properly for each action. So i fixed it and then the dialog box started to appear.
My first idea is that the attribute is oncomplete and not oncompleted.
Also, you have to take care of lowercase/uppercase problems, as JSF is XML, which is case-sensitive. I see a WidgetVar in your code but the correct attribute is widgetVar.
All these are in a single form.
Then my second idea is to put a <h:form> inside the <p:dialog> and make sure you don't nest forms.
See https://stackoverflow.com/a/10579708/1528942 for a rational.

Primeface´s remoteCommand - there is a way to execute once?

Primefaces 3.5 JSF 2.1
I´m using p:remoteCommand to execute async commands and update my view after page loading but looks that in the ends of each iteration it execute again and so on...
Is this behaviour correct?
How to execute only once the p:remoteCommand?
update
I have checked that my remoteCommand was out of the update panel, so thank you for the answers but it was already OK. How I solve my problem:
I dont know why but using the onloadScript from Omnifaces (http://showcase.omnifaces.org/components/onloadScript) to call the remoteCommand function it is called many times, but using $(document).ready ... just once. So, I change it and got it working right now.
If you end up in an infinite loop like behaviour, you are likely updating a parent component to your <p:remoteCommand>.
<h:form id="myform">
<p:remoteCommand update="myform" actionListener="#{remoteCommandView.execute}" />
...
</h:form>
Put it outside/next to the component you wish to update and things should be fine.
<h:form id="newform">
<p:remoteCommand update="myform" actionListener="#{remoteCommandView.execute}" />
</h:form>
<h:form id="myform">
...
</h:form>
Use p:remoteCommand in separate form.
Use process="#this" and partialSubmit="true", just to be on safer side.

ui:repeat with a list sending right object to a p:dialog

I currently have a giant ui:repeat. Within this ui:repeat, some of the repeated objects have a url to a popup image associated with them. When someone clicks display under that particular object, I need the url to popup in a p:dialog.
<ui:repeat var="thing" value="#{bean.thingList}">
<p:commandLink value="details" onclick="miniImage.show();"
update=":#{p:component('chart')}"
action="#{bean.setCurrentImg(thing.imageUrl)}"
rendered="#{thing.includeImage}">
</p:commandLink>
</ui:repeat>
and at the bottom of the page:
<p:dialog id="chart" widgetVar="miniImage" >
<h:graphicImage value="#{bean.currentImg}"/>
</p:dialog>
And in the backing bean I tried using a simple setter and getter for currentImg.
I am a bit confused on this now and would like to accomplish this without having to submit the entire form as well. Any help is greatly appreciated.
If you're using PrimeFaces 3.3 or newer, you could just add partialSubmit="true" to the command component. You can then control the to-be-processed components in process attribute. In this particular case, just the current component (the command component itself) is sufficient, thus so process="#this":
<p:commandLink ... process="#this" partialSubmit="true" />
This way only the request parameters which are really necessary for the process will be sent.
Unrelated to the concrete problem, I suggest to use oncomplete instead of onclick to open the dialog. Otherwise the dialog is opened before update takes place and may cause poor user experience as the enduser would see the image instantly changing.

Resources