【问题标题】:No navigation happens when using a p:commandButton使用 p:commandButton 时不会发生导航
【发布时间】:2014-03-18 16:48:01
【问题描述】:

这是一个 Facelets 文件,用于获取名字和姓氏,然后将转到另一个 Facelets 文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <h:head><title>User Form</title></h:head>

    <h:body>
    <h:form>
        <h:panelGrid columns="2">
            <p:graphicImage value="resources/images/image.jpg" width="50%"/>

            <p:panelGrid columns="2" width="50%">
                <f:facet name="header">
                    User Form
                </f:facet>
                <h:outputLabel for="firstname" value="Firstname: *"/>
                <p:inputText id="firstname" value="" label="Firstname"/>

                <h:outputLabel for="surname" value="Surname: *"/>
                <p:inputText id="surname" value="" required="true" label="Surname"/>

                <f:facet name="footer">
                    <p:commandButton type="button" value="Save" icon="ui-icon-check" style="margin:0" action="construction"/>
                </f:facet>
            </p:panelGrid>
        </h:panelGrid>
    </h:form>
</h:body>
</html>

当我按下“保存”按钮时,我预计会转到construction.xhtml,但没有任何反应。这是如何引起的,我该如何解决?

【问题讨论】:

  • 这是实际代码吗?因为a)您使用commandButton 进行导航,b)您的inputTexts 没有支持值。也就是说,尝试使用h:commandButton&lt;p:commandButton ajax="false"&gt;,如here 所述。
  • 感谢@mabi,当用户按住保存按钮时,under Construction 页面必须出现,因为正如你所说,它并不完整,它只是这个程序的开始
  • 你到底为什么使用type="button"
  • 你确定吗?您熟悉基本的 HTML 和 HTTP 吗?您是否检查过 HTTP 流量监视器和服务器日志?当您删除它时,它应该开始触发 ajax 请求,而不是什么都不做。该 ajax 请求是否会反过来触发导航只是第二个问题。你有一个带有required="true" 的输入,没有任何面孔消息处理程序。
  • 最后,一个例外!一个好的例外本身已经是一个完整的答案。但是,根据到目前为止发布的代码,我无法解释这一点;您没有运行问题中显示的代码。

标签: jsf jsf-2 primefaces


【解决方案1】:

当您使用commandButton 时,您必须执行以下操作:

<p:commandButton  value="Save" icon="ui-icon-check" style="margin:0" action="#{someBean.navigate}"/>

表示必须使用managed bean

在您的情况下,您必须使用 button 而不是 commandButton

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-15
    • 1970-01-01
    • 2016-06-17
    • 1970-01-01
    • 2018-07-02
    • 2016-05-11
    • 2020-03-07
    • 2021-10-11
    相关资源
    最近更新 更多