Java 在弹出窗口中显示Faceson文本消息以验证对话框中的输入
我怀疑如何在对话框中显示facescontext消息。 这使用了PrimeFaces4.0和JSF 我想在弹出对话框中显示facescontext消息(在另一个对话框中单击命令按钮时显示) 方法1: 假设视图文件如下Java 在弹出窗口中显示Faceson文本消息以验证对话框中的输入,java,jsf,primefaces,Java,Jsf,Primefaces,我怀疑如何在对话框中显示facescontext消息。 这使用了PrimeFaces4.0和JSF 我想在弹出对话框中显示facescontext消息(在另一个对话框中单击命令按钮时显示) 方法1: 假设视图文件如下 <p:commandButton id=”btn” oncomplete=”dlg.show()”/> <p:dialod id=”dlg_id” widgetVar=”dlg”> <h:inputText id=”name”/>
<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>
上面的方法显示了弹出框。但是弹出框中显示的值类似于javax.beans。context@1ggh34ea
然后我尝试使用UI组件绑定
方法2:
<h:form>
<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()" update="dlg1_id"/>
</p:dialog>
<p:dialog id="dlg1_id" widgetVar="dlg1">
<h:message for="j_idt5"/>
</p:dialog>
</h:form>
public void someMethod(){
RequestContext.getCurrentInstance().addCallbackParam("facesMessageAvailable",true);
FacesContext.getCurrentInstance().addMessage("j_idt5",new FacesMessage("Name is Required"));
}
查看文件
<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>
但这会显示一个空白的弹出窗口。
然后我尝试使用JOptionPane。但它会产生一些逻辑错误
我将感谢任何帮助。
在我记忆中键入代码时,语法可能不正确。我尝试了你的方法1,发现有一些错误: 使用
1.您应该指定
的update
属性2.不需要指定
的值=“#{facesContext.messageList}”
(也没有这样的属性)
因此,完成这些操作后,您的代码应该如下所示:
<h:form>
<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()" update="dlg1_id"/>
</p:dialog>
<p:dialog id="dlg1_id" widgetVar="dlg1">
<h:messages id="error_msgs"/>
</p:dialog>
</h:form>
支持Bean:
<h:form>
<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()" update="dlg1_id"/>
</p:dialog>
<p:dialog id="dlg1_id" widgetVar="dlg1">
<h:message for="j_idt5"/>
</p:dialog>
</h:form>
public void someMethod(){
RequestContext.getCurrentInstance().addCallbackParam("facesMessageAvailable",true);
FacesContext.getCurrentInstance().addMessage("j_idt5",new FacesMessage("Name is Required"));
}
请注意,j_idt5
是
我怎样才能知道客户id?只需在浏览器中的页面上单击鼠标右键并查看页面源代码,查看您感兴趣的组件,您就会找到客户端id