0
我被要求編寫一個處理結果分頁的JSF組件。組件接受一個實現接口的bean。在運行時,getter方法被調用,但從來不是setters。下面是代碼JSF只調用getter,但從不設置複合組件
<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>
任何人都可以看到任何理由爲什麼只有getter被調用而不是setter?
我已經按照你的建議完成了,但這沒有什麼區別。此外,我也對二傳手方法提出了一個斷點,並證實他們沒有被調用。 – user2980252