Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在弹出窗口中显示Faceson文本消息以验证对话框中的输入_Java_Jsf_Primefaces - Fatal编程技术网

Java 在弹出窗口中显示Faceson文本消息以验证对话框中的输入

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”/>

我怀疑如何在对话框中显示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=”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