I'm trying to implement a JSF page in which the user should insert some data. In particular, when pressing a button a dialog box should appear asking for user input. The main problem is that the execution of the backing bean should be stopped waiting for a user response.
A toy example is the following.
JSF page:
<h:form id="label">
<p:dialog header="User input" widgetVar="dlg2"
visible="true" modal="false"
resizable="false" height="100" width="300">
<br />
<h:inputText value="#{userInputMB.userInput}"></h:inputText>
</p:dialog>
<p:commandButton action="#{userInputMB.pressButton}"></p:commandButton>
</h:form>
UserInputMB:
package jsfpackage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class UserInputMB {
private String userInput;
private boolean visualizeDialog = false;
public UserInputMB() {
}
public void pressButton() {
System.out.println("Executing the pressButton method..");
//here I need to visualize the dialog and wait for the user input
System.out.println(userInput);
}
public String getUserInput() {
return userInput;
}
public void setUserInput(String userInput) {
this.userInput = userInput;
}
public boolean isVisualizeDialog() {
return visualizeDialog;
}
public void setVisualizeDialog(boolean visualizeDialog) {
this.visualizeDialog = visualizeDialog;
}
}
In this example, when pressing the button, the pressButton method should visualize the dialog box and wait for the user input and then continue the execution.
I also found this similar question on stackoverflow: Synchronous dialog invocation from managed bean
but my situation is quite different. I'm forced to implement this kind of behavior. Thanks in advance!