【问题标题】:Custom JSF Control isn't binding properly自定义 JSF 控件未正确绑定
【发布时间】:2014-12-26 15:00:56
【问题描述】:

因此,我被要求制作一个自定义 JSF 控件来处理我公司网站的结果分页。对于这个组件,支持 bean 的四个方法中的三个可以正常工作,但最后一个不能正常工作。也许我遗漏了一些东西,但代码看起来是正确的。我希望社区能够对正在发生的事情有所了解。

所以这里是代码。 #{cc.attrs.goToLastPage} 行为不端

<cc:interface>
    <cc:attribute name="showingRecordMin" required="true" />
    <cc:attribute name="showingRecordMax" required="true" />
    <cc:attribute name="totalRecords" required="true" />
    <cc:attribute name="resultsPerPage" required="true" />
    <cc:attribute name="currentPageNum" required="true" />
    <cc:attribute name="totalPagesNum" required="true" />
    <cc:attribute name="resultsPerPageItems" required="true" />
    <cc:attribute name="resultPagesItems" required="true" />

    <cc:attribute name="goToNextPage" 
        method-signature="java.lang.String action()" required="true"/>
    <cc:attribute name="goToPreviousPage"
        method-signature="java.lang.String action()" required="true"/>
    <cc:attribute name="goToFirstPage"
        method-signature="java.lang.String action()" required="true"/>
    <cc:attribute name="goToLastPage"
        method-signtature="java.lang.String action()" required="true"/>
</cc:interface>

<!-- Question: We can't have a form inside of a form. Do we ecapsulate form operations here or 
    should the client handle them? -->
<cc:implementation>
    <div
        style="background-color: #F0F3FA; border: 1px solid #ABABAB; height: 25px; margin: 0px; padding: 2px 8px; position: relative; vertical-align: middle;">
        <h:panelGroup>
            <div style="float: left; width: auto;">
                Showing Results <h:outputLabel value="#{cc.attrs.showingRecordMin}" />  - <h:outputLabel value="#{cc.attrs.showingRecordMax}" /> of
                #{cc.attrs.totalRecords} Results per Page:
                <h:selectOneMenu value="#{cc.attrs.resultsPerPage}" onchange="$j(document).find('.pageBarSubmitBtn').click();">
                    <f:selectItems value="#{cc.attrs.resultsPerPageItems}" />
                </h:selectOneMenu>
            </div>
            <div style="float: right; width: auto;">
                Showing Page #{cc.attrs.currentPageNum} of #{cc.attrs.totalPagesNum} Jump
                to Page
                <h:selectOneMenu id="_pagesMenu" value="#{cc.attrs.currentPage}" onchange="$j(document).find('.pageBarSubmitBtn').click();">
                    <f:selectItems value="#{cc.attrs.resultPagesItems}" />
                </h:selectOneMenu>
                <!-- These three work properly -->
                <h:commandLink style="position: relative; top: 3px;" action="#{cc.attrs.goToFirstPage}"> 
                    <h:graphicImage value="/images/arrow-first.gif" />
                </h:commandLink>
                <h:commandLink style="position: relative; top: 3px;" action="#{cc.attrs.goToPreviousPage}">
                    <h:graphicImage value="/images/arrow-previous.gif" />
                </h:commandLink>
                <h:commandLink style="position: relative; top: 3px;" action="#{cc.attrs.goToNextPage}">
                    <h:graphicImage value="/images/arrow-next.gif" />
                </h:commandLink>
                <!-- This one is the bad guy -->
                <h:commandLink style="position: relative; top: 3px;" action="#{cc.attrs.goToLastPage}">
                    <h:graphicImage value="/images/arrow-last.gif" />
                </h:commandLink>

            </div>
            <h:commandButton style="visibility: hidden;" styleClass="jsfHidden pageBarSubmitBtn"/>
        </h:panelGroup>
    </div>
</cc:implementation>

继续,这是从控制台抛出的异常

09:23:15,108 WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (http-localhost-  127.0.0.1-3333-5) Unable to resolve composite component from using page using EL expression '#  {cc.attrs.goToLastPage}': javax.faces.FacesException: Unable to resolve composite component from   using page using EL expression '#{cc.attrs.goToLastPage}'

以下是该控件在我的页面中的使用方式: 句法

最后这里是我的 backing bean 正在实现的与此控件一起使用的接口

public interface PagableResults {
    public int getShowingRecordMin();
    public int getShowingRecordMax();

    public ResultsPerPage getResultsPerPage();
    public void setResultsPerPage(ResultsPerPage rpp);

    public int getCurrentPageNum();
    public void setCurrentPageNum(int pageNum);

    public int getTotalPagesNum();
    public int getTotalRecordsNum();

    public List<SelectItem> getResultsPerPageItems();
    public List<SelectItem> getResultsPagesItems();

    public void goToFirstPage();
    public void goToLastPage();
    public void goToPreviousPage();
    public void goToNextPage();
}

【问题讨论】:

    标签: jsf jsf-2


    【解决方案1】:

    你拼错了method-signature:

    <cc:attribute name="goToLastPage"
        method-signtature="java.lang.String action()" required="true"/>
    

    【讨论】:

    • 干得好!我盯着代码看了好几个小时,从来没有注意到这一点!我猜眼睛只能看到它想看到的东西!
    猜你喜欢
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    相关资源
    最近更新 更多