未调用模板客户端中的<f:event type =“preRenderView”> </f:event>

时间:2015-01-15 11:00:54

标签: jsf facelets prerenderview

以下是我的XHTML代码。 preRenderView事件监听器被忽略,我的所需方法没有被调用。我觉得这是因为使用了模板,但无法弄清楚确切的事情。 请帮忙

XHTML:

<?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://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:corejsf="http://corejsf.com"
      xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
      xmlns:snw="http://jsf.switchNwalk.com">

    <h:body>
        <ui:decorate template="/template/common/commonLayout.xhtml">
            <ui:define name="content">
                <h:form>
                    <section class="box">
                        <h:outputStylesheet name="assets/css/consumer.css"/>
                        <div class="row-fluid" >
                            <div class="span7" style=""><span class="heading">Consumer Offers</span></div>
                        </div>
                        <div class="row-fluid main_container">
                            <div class="span12 main_container_info">
                                <div class="cosumer_offers">
                                    <h:commandButton class="btn btn_upload"
                                                     style=""
                                                     value="Create Consumer Offer"
                                                     action="#{partnerCreateOffer.createOffer()}">
                                    </h:commandButton>
                                </div>

                                <h:dataTable value="#{partnerGetOffers.getOffers()}" var="offers">
                                    <h:column>
                                        <f:facet name="header">Consumer Offer</f:facet>
                                            #{offers.offerText}
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">Start Date</f:facet>
                                            #{offers.startDate}
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">End Date</f:facet>
                                            #{offers.offerText}
                                    </h:column>
                                    <h:column>
                                        <f:facet name="header">Status</f:facet>
                                            #{offers.status}
                                    </h:column>

                                    <h:column>
                                        <f:facet name="header">Modify</f:facet>
                                            #{offers.modify}
                                    </h:column>
                                </h:dataTable>
                            </div>
                        </div>
                    </section>
                </h:form>
            </ui:define>
        </ui:decorate>
        <f:event type="preRenderView" listener="#{partnerGetOffers.testmethod}" />
    </h:body>
</html>

Backing bean简单测试方法:

public void testmethod() {
    System.out.println("listenrersuccess");
}   

1 个答案:

答案 0 :(得分:-1)

尝试在f:metadata

中添加它
<ui:define name="content">
...

<f:metadata>
    <f:event type="preRenderView" listener="#{partnerGetOffers.testmethod}" />
</f:metadata>

...
<h:form>