【问题标题】:Primefaces command button action is not called for the second timePrimefaces 命令按钮动作没有被第二次调用
【发布时间】:2013-06-10 16:09:48
【问题描述】:

我已将 spring 与 JSF 集成,但我面临一个奇怪的行为:

  1. 我点击了命令按钮,托管 bean 中的操作方法被成功点击(我在下面的示例中删除了它)。
  2. Ajax 更新完美运行,表单也更新了。
  3. 我点击了另一个按钮,现在托管 bean 中的操作方法没有被点击。
  4. 面板恢复到初始视图并冻结在该视图上。
  5. 我无法更新表单,除非我刷新页面并重复这些步骤。

DealerInfo.xhtml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<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:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

<ui:composition template="/WEB-INF/templates/default.xhtml">
    <ui:define name="content">
        <h:form id="toolBarForm">
            <p:toolbar style="margin-bottom:5px;">
                <p:toolbarGroup align="right">
                    <p:commandButton value="Add"
                        update=":toolBarForm" icon="ui-icon-plusthick" />
                    </p:toolbarGroup>
                </p:toolbar>
            <p:messages id="dealerInfoMessages" />
            <ui:include src="/pages/dealers/DealerMainInfo.xhtml" />
        </h:form>
    </ui:define>
</ui:composition>
</html>

pages/dealers/DealerMainInfo.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<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:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

<ui:composition>
    <p:panel id="dealerMainInfoPanel" header="Dealer Main Info"
        style="margin-bottom:5px;">
        <h:panelGrid columns="2">
            <p:outputLabel for="dealerCode" value="Dealer Code" />
            <p:inputText id="dealerCode" required="true"
                value="#{dealerMainInfoBO.dealerCode}" style="width:200px;" />

            <p:outputLabel for="dealerName" value="Dealer Name" />
            <p:inputText id="dealerName" required="true"
                value="#{dealerMainInfoBO.dealerName}" style="width:200px;" />
        </h:panelGrid>
    </p:panel>
</ui:composition>
</html>

更新: 我创建了一个非常简单的单页,我注意到当我删除 &lt;h:head&gt;&lt;/h:head&gt; 标签时,ajax 就像没有花哨的 primefaces UI 的魅力 BUT 一样工作,当我添加标签时,ajax 停止(这个是正常的,因为&lt;h:head&gt;&lt;/h:head&gt; 标签会获取所有需要的 JS 和 CSS),我该怎么办?

Example.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<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:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

<f:view contentType="text/html">
    <h:head>
    </h:head>
    <h:body>
        <h:form id="toolBarForm">
            <p:toolbar style="margin-bottom:5px;">
                <p:toolbarGroup align="right">
                    <p:commandButton value="Add" update=":toolBarForm"
                        action="#{bean.add}" />
                </p:toolbarGroup>
            </p:toolbar>
            <p:messages id="operationDefinitionMessages" />
            <h:panelGrid columns="2">
                <p:outputLabel for="text" value="Text" />
                <p:inputText id="text" required="true" value="#{bean.text}" />
            </h:panelGrid>
        </h:form>
    </h:body>
</f:view>
</html>

我的环境

  • Primefaces:3.5
  • JSF-Mojarra:2.2
  • 弹簧:3.2.3.RELEASE

【问题讨论】:

  • 你有没有抛出异常?
  • 不,如果有的话,我会把它包括在我的问题中。

标签: ajax jsf primefaces


【解决方案1】:

万一有人遇到同样的问题。我注意到Primefaces showcase 正在使用JSF-Mojarra-2.1.22。我将我的JSF-Mojarra 版本从2.2 降级为2.1.22,它就像一个魅力。

如果我没记错的话,我想应该向 primefaces 报告(如果不是当前问题)。

【讨论】:

    猜你喜欢
    • 2012-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-17
    • 2021-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多