我被要求编写一个处理结果分页的JSF组件。该组件接受实现接口的bean。在运行时,调用getter方法,但从不调用setter。这是代码
<cc:interface>
<cc:attribute name="pagableResultsBean" />
</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>
<c:set var="pagableResultsBean" value="#{cc.attrs.pagableResultsBean}" />
<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="#{pagableResultsBean.showingRecordMin}" /> - <h:outputLabel value="#{pagableResultsBean.showingRecordMax}" /> of
#{pagableResultsBean.totalRecordsNum} Results per Page:
<h:selectOneMenu value="#{pagableResultsBean.resultsPerPage}" onchange="$j(document).find('.pageBarSubmitBtn').click();">
<f:selectItems value="#{pagableResultsBean.resultsPerPageItems}" />
</h:selectOneMenu>
</div>
<div style="float: right; width: auto;">
Showing Page #{pagableResultsBean.currentPageNum} of #{pagableResultsBean.totalPagesNum} Jump
to Page
<h:selectOneMenu id="_pagesMenu" value="#{pagableResultsBean.currentPageNum}" onchange="$j(document).find('.pageBarSubmitBtn').click();">
<f:selectItems value="#{pagableResultsBean.resultsPerPageItems}" />
</h:selectOneMenu>
<h:commandLink style="position: relative; top: 3px;" action="#{pagableResultsBean.goToFirstPage()}">
<h:graphicImage value="/images/arrow-first.gif" />
</h:commandLink>
<h:commandLink style="position: relative; top: 3px;" action="#{pagableResultsBean.goToPreviousPage()}">
<h:graphicImage value="/images/arrow-previous.gif" />
</h:commandLink>
<h:commandLink style="position: relative; top: 3px;" action="#{pagableResultsBean.goToNextPage()}">
<h:graphicImage value="/images/arrow-next.gif" />
</h:commandLink>
<h:commandLink style="position: relative; top: 3px;" action="#{pagableResultsBean.goToLastPage()}">
<h:graphicImage value="/images/arrow-last.gif" />
</h:commandLink>
</div>
<h:commandButton style="visibility: hidden;" styleClass="jsfHidden pageBarSubmitBtn"/>
</h:panelGroup>
</div>
</cc:implementation>
这是支持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();
}
以下是使用控件的代码段
<h:form>
<ndar:pagingBar pagableResultsBean="#{pageBean}" />
</h:form>
任何人都可以看到为什么只有被吸引者被召唤而不是被设定者?
答案 0 :(得分:0)
当您似乎使用JSP JSTL核心标记库中的c:set
时,这可能不适用于JSF,尤其是JSF Composite Component系统。
您是否尝试将pagableResultsBean
的所有实例替换为cc.attrs.pagableResultsBean
,因为这样可以消除错误的一个可能原因?
另外,将调试器放在你认为没有被调用的set-method上 - 并验证它是否真的没有被调用,或只是html结果看起来像。
更新2014-12-31
还要确保为jsf添加h:messages
标记,以确保JSF告诉您可能的转换错误。