问题
Is there a way to use PrimeFaces RequestContext
to call a dialog defined in the JSF from a managed bean, which has a form, but synchronously, meaning that the managed bean wait its thread execution until the user submits the form?
Currently, I am successfully invoking a dialog from my managed bean but the call is asynchronous, meaning the dialog is popped open but the managed bean thread continues on without waiting for the user to supply the needed additional data via the dialog.
So, in my JSF, I have the dialog defined as follows:
<p:dialog header="My Dialog" widgetVar="myDialog" modal="false" height="100">
<h:form>
<h:outputLabel for="inputData" value="Input Data:"/>
<p:inputText id="inputData" title="Input Data"
maxlength="16" required="true" ... >
</p:inputText>
<h:commandButton value="Submit"/>
</h:form>
</p:dialog>
In my managed bean, I call the dialog conditionally if some criteria is met:
...
if(noteReqd) {
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.execute("PF('myDialog').show();");
//here I want the managed bean to stop until the user supplies the extra data needed
//but it just proceeds downstream without the data the user enters
}
...
RELATED:
Prompting overlay for extra data by managed bean
Calling a JavaScript function from managed bean
回答1:
No it's not possible. The Primfaces's RequestContext can only do his job then the JSF lifecycle continues and sends the javascript information (PF('myDialog').show();
, e.g., what to do) back to the client (browser).
A solution would be change your logic in some way.
- user supplies some data
- check if data was enough
- if not, reopen the same form (or another one)
- do step 2 + 3 until enough data is supplied
- continue with your logic
来源:https://stackoverflow.com/questions/31195729/synchronous-dialog-invocation-from-managed-bean