【问题标题】:Jsf2 listener not called with f:ajax未使用 f:ajax 调用 Jsf2 侦听器
【发布时间】:2014-03-13 22:07:42
【问题描述】:

我正在使用 jsf2 和 Richfaces 4。

这是我的 home.xhtml

<!DOCTYPE composition 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:f="http://java.sun.com/jsf/core"      
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets" 
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:rich="http://richfaces.org/rich">

<h:head>
    <title>My Web Application</title>
    <link rel="stylesheet" href="resources/stylesheet/style.css" />
</h:head>

<h:body>

    <h:panelGrid columns="2">

        <h:form>

            <rich:panel>

                <f:facet name="header">
                    Statut
                    <div class="status_refresh" style="float:right;">
                        <h:graphicImage styleClass="loading" value="resources/stylesheet/images/refresh.png">
                            <f:ajax execute="@form" event="click" listener="#{statusBean.refresh}" render="station_status station_action"/>
                        </h:graphicImage>
                    </div>
                </f:facet>

                <h:panelGroup id="station_status" style="display:inline-block;" class="#{statusBean.stationTableStatus?'status_ok':'status_not_ok'}">
                    <a4j:outputPanel>
                        <rich:tooltip rendered="#{statusBean.stationTableStatus != true}">
                            <h:outputText value="#{statusBean.stationTableStatusMessage}" />
                        </rich:tooltip>
                        <h:outputText value="Table " />
                        <b><h:outputText style="margin-right:10px;" value="Station" /></b>
                    </a4j:outputPanel>
                </h:panelGroup>
                <h:panelGroup id="station_action" rendered="#{statusBean.stationTableStatus != true}">
                    <a4j:status>
                        <f:facet name="start">
                            <div class="loading_container">
                                <h:graphicImage styleClass="loading" value="resources/stylesheet/images/waiting.gif" alt="Please wait ..." />
                            </div>
                        </f:facet>
                        <f:facet name="stop">
                            <h:commandButton type="button" value="Créer la table">
                                <a4j:ajax execute="@form" listener="#{statusBean.createStationTable}" render="station_status,station_action"/>
                            </h:commandButton>
                        </f:facet>
                    </a4j:status>                       
                </h:panelGroup>

            </rich:panel>

        </h:form>

    </h:panelGrid>

</h:body>

</html>

通过支持 bean,我有:

public void createStationTable()
{
....
}

public void refresh()
{
    System.out.println("******* start refresh() ************");
}

而且我不明白为什么我的按钮的侦听器被调用,而不是我的图像之一。

我也试过

public void refresh(ActionEvent actionEvent)

public void refresh(AjaxBehaviorEvent e)

但没有一个有效。

我也尝试过使用 f:ajax 和 a4j:ajax。同样的结果。

【问题讨论】:

    标签: jsf-2 richfaces


    【解决方案1】:

    好吧,我试过你的代码,它调用了&lt;f:ajax&gt;标签中定义的监听器。

    不知道你是不是抄的时候漏了,你漏了&lt;/html&gt;

    对于&lt;h:panelGrid&gt;,您使用了错误的属性。应该是styleClass 而不是class

    【讨论】:

    • 在女巫环境下你试过了吗?对我来说,我正在使用 glassfish 3.1.2.2
    • 我在 Tomcat 7 中进行了测试,而不是在 glassfish 中。我使用的是 JSF 2.2 RI。
    • 好的,现在可以了。有时玻璃鱼会有一些奇怪的事情。只需进行一次取消部署,然后进行部署以代替重新部署。
    猜你喜欢
    • 2012-04-08
    • 2012-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    • 2012-04-30
    相关资源
    最近更新 更多