In the controller, I have created a listener that looks something like this:
public class FooController {
public void doSomething(AjaxBehaviorEvent evt) {
closeDialogFlag = true;
..
if(!isValid){
closeDialogFlag = false;
}
}
}
Here is my JSF button:
<h:commandButton value="Do something">
<f:ajax
listener="#{fooController.doSomething}"
execute=":editDialogForm:processTab" render="@this :editDialogForm:processTab :messageViewer:messageViewerPanel :results"
onevent="function(data){ if(data.status === 'success' && #{fooController.closeDialogFlag} ) { $('#migrationEditDialogModal').modal('hide'); } }"
/>
</h:commandButton>
However, the closeDialogFlag
does not work after the AJAX request is completed. This is because the value of #{fooController.closeDialogFlag}
is extracted when the page loads and is not updated after the AJAX request. I need to refresh the page to see the new value in the output code.
The question is:
How can I pass additional information to data
in onevent=function(data)
in my listener? (This solution is more appropriate for me as it will be useful in various cases) OR Is there any way to abort my request in my listener and force my AJAX request to return a status other than success
?
PS: I prefer not to use Primefaces, Richfaces, etc.
Edit:
Small correction.
If I add the attribute @this
to the f:ajax
tag's render
value, then my flag is successfully extracted as true
. However, after my AJAX request, my dialog does not hide using the JavaScript function.