I have doubt regarding how to show facescontext messages in a dialog box. This uses primefaces 4.0, JSF.
I want to display a facescontext message in pop up dialog box (which appears on clicking a commandbutton in another dialog box).
Method 1 : Suppose the view file is like
<p:commandButton id=”btn” oncomplete=”dlg.show()”/>
<p:dialod id=”dlg_id” widgetVar=”dlg”>
<h:inputText id=”name”/>
<p:commandButton id=”btn1” actionListener=”someBean.someMethod()” oncomplete=”dlg1.show()”/>
</p:dialog>
<p:dialog id=”dlg1_id” widgetVar=”dlg1”>
<h:messages id=”error_msgs” value=”#{facesContext.messageList}”
</p:dialog>
BackingBean (someBean)
public void someMethod() {
RequestContext.getCurrentInstance().addCallBackParam(“facesMessageAvailable”,true);
FacesContext.getCurrentInstance().addMessage(“error_msgs”,new FacesMessage(…,”Name is Required”,…));
}
The above method shows the pop up box. But the value shown in the pop up box is like javax.beans.context@1ggh34ea Then I tried using UI component binding.
Method 2 :
View File
<p:commandButton id=”btn” oncomplete=”dlg.show()”/>
<p:dialog id=”dlg_id” widgetVar=”dlg”>
<h:inputText id=”name”/>
<p:commandButton id=”btn1” actionListener=”someBean.someMethod()” oncomplete=”dlg1.show()”/>
</p:dialog>
<p:dialog id=”dlg1_id” widgetVar=”dlg1”>
<h:outputText id=”msg” binding=”someBean.outText”/>
</p:dialog>
BackingBean (someBean)
private UIComponent outText;
//getter and setter of outText
public void someMethod() {
RequestContext.getCurrentInstance().addCallBackParam(“facesMessageAvailable”,true);
FacesContext.getCurrentInstance().addMessage(outText.getClientId() , new FacesMessage(…,”Name is Required”,…));
}
But this shows a blank empty pop up. Then I tried using JOptionPane. But it produces some logical errors.
I would appreciate any help. The syntax may be incorrect as i typed the code from my memory.