【问题标题】:p:commandButton not triggering actionlistenerp:commandButton 没有触发 actionlistener
【发布时间】:2012-08-06 14:00:33
【问题描述】:

好的,我已阅读有关此问题的所有帖子,但找不到。我的情况非常简单——我所做的就是使用 Primefaces 3.3.1 和 JSF 2.1 来呈现登录页面。代码如下:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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"
    xmlns:pe="http://primefaces.org/ui/extensions"
    xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>ACME Systems - Home Page</title>
    <style>
    .noBorders tr, .noBorders td {
    background: none !important;
    border: none !important;
}

    </style>
</h:head>
<h:body>
    <p:panel id="mainPanel"
        style="height: 106px; height: auto !important; margin: 0 auto; min-height: 106px; position: relative; width: 960px; z-index: 100;">
        <h:form id="loginForm">
            <p:panel header="Secure Login"
                style="padding-bottom: 40px; width: 380px;">
                <p:panelGrid columns="2" styleClass="noBorders">
                    <h:outputText value="Username:" />
                    <p:inputText id="username" required="true"
                        requiredMessage="Username is required." title="Username"
                        value="#{LoginBean.username}" />

                    <h:outputText value="Password:" />
                    <p:password id="password" required="true"
                        requiredMessage="Password is required"
                        value="#{LoginBean.password}" />
                </p:panelGrid>
                <p:commandButton id="loginButton" value="Login"
                    actionListener="#{LoginBean.login}"
                    style="margin-top: 5px; float: right;" />
            </p:panel>
        </h:form>
    </p:panel>
</h:body>
</html>

命令按钮上的动作侦听器未触发。如果我将其更改为 h:commandbutton 一切都很好。我宁愿只使用 primefaces 标签,因为它使用主题。如果我使用 h: 那么我需要获取 css。有任何想法吗?另一件事是,如果我在 primefaces 按钮之前放置一个 h:commandbutton 并使用它来执行初始触发,则 primefaces 按钮从那时起就可以工作:P Go figure!

【问题讨论】:

  • 我以某种方式修复它。我在命令按钮中添加了一个 update= 并将其设置为外部面板。我还在输入字段中添加了标签属性。是添加更新属性修复它还是添加一个 id 到外部面板?奇怪。
  • 您确实在执行操作后并没有更新 UI,因此最终用户根本不会得到任何反馈(除非操作方法使用 ExternalContext#redirect() 或 NavigationHandler#handleNavigation())。您究竟是如何确认动作侦听器没有触发的?您是否在实际方法上放置了调试断点或在其中添加了记录器?还是您只是根据没有查看 HTTP 流量和代码执行情况而得出结论,认为您没有收到任何 UI 反馈?
  • 我确实添加了一个记录器,但什么也没出现。那时我知道我通过 primefaces 组件做错了什么。也许是他们的展示示例有时使用 h 标签而不是他们自己的原因。就我而言,我想将所有内容都保留在主题中,否则我会使用 h 标签。

标签: jsf-2 primefaces


【解决方案1】:

既然我修好了,就要把它关掉。也许将来有人可以使用此信息。我会确保您阅读代码示例 Primefaces(或任何框架)并使用它们的确切代码,直到您觉得自己掌握了它。使用 JSF 6 年了,还是没有像 BalusC 一样搞清楚一切:-)

【讨论】:

    猜你喜欢
    • 2015-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-18
    • 2012-01-06
    • 2014-12-26
    • 1970-01-01
    相关资源
    最近更新 更多