use of javax.faces.component.UIData in project gdmatrix by gdmatrix.
the class HtmlDataScroller method findUIData.
protected UIData findUIData() {
String forStr = getFor();
UIComponent forComp;
if (forStr == null) {
// DataScroller may be a child of uiData
forComp = getParent();
} else {
forComp = findComponent(forStr);
}
if (forComp == null) {
throw new IllegalArgumentException("could not find UIData referenced by attribute dataScroller@for = '" + forStr + "'");
} else if (!(forComp instanceof UIData)) {
throw new IllegalArgumentException("uiComponent referenced by attribute dataScroller@for = '" + forStr + "' must be of type " + UIData.class.getName() + ", not type " + forComp.getClass().getName());
}
return (UIData) forComp;
}
use of javax.faces.component.UIData in project gdmatrix by gdmatrix.
the class HtmlDataScroller method broadcast.
@Override
public void broadcast(FacesEvent event) {
super.broadcast(event);
if (event instanceof ScrollerActionEvent) {
ScrollerActionEvent scrollerEvent = (ScrollerActionEvent) event;
UIData uiData = getUIData();
if (uiData == null)
return;
switch(scrollerEvent.action) {
case NEXT:
int next = uiData.getFirst() + uiData.getRows();
if (next < uiData.getRowCount()) {
uiData.setFirst(next);
}
break;
case PREVIOUS:
int previous = uiData.getFirst() - uiData.getRows();
if (previous >= 0) {
uiData.setFirst(previous);
}
break;
case FIRST:
uiData.setFirst(0);
break;
case LAST:
int rowCount = uiData.getRowCount();
int rows = uiData.getRows();
int delta = rowCount % rows;
int first = delta > 0 && delta < rows ? rowCount - delta : rowCount - rows;
if (first >= 0) {
uiData.setFirst(first);
} else {
uiData.setFirst(0);
}
break;
}
}
}
use of javax.faces.component.UIData in project liferay-faces-alloy by liferay.
the class Paginator method getRender.
@Override
public String getRender() {
String render = super.getRender();
if ((render != null) && render.contains("@for")) {
UIData uiData = getUIData();
if (uiData != null) {
String uiDataId = uiData.getId();
render = render.replace("@for", uiDataId);
}
}
return render;
}
use of javax.faces.component.UIData in project liferay-faces-alloy by liferay.
the class PaginatorRenderer method encodeBegin.
@Override
public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
// Encode the starting <div> element that represents the alloy:paginator.
Paginator paginator = (Paginator) uiComponent;
String clientId = paginator.getClientId(facesContext);
ResponseWriter responseWriter = facesContext.getResponseWriter();
responseWriter.startElement("div", uiComponent);
responseWriter.writeAttribute("id", clientId, null);
RendererUtil.encodeStyleable(responseWriter, (Styleable) uiComponent);
// Determine the current pagination state of the associated UIData component.
UIViewRoot viewRoot = facesContext.getViewRoot();
Locale locale = viewRoot.getLocale();
UIData uiData = paginator.getUIData();
int first = uiData.getFirst();
int rows = uiData.getRows();
int curPage = (first / rows) + 1;
int rowCount = uiData.getRowCount();
int pageCount = (int) Math.ceil((double) rowCount / (double) rows);
// If the summary is to be positioned above the pagination controls, then encode the summary.
String summaryPosition = paginator.getSummaryPosition();
if ("top".equals(summaryPosition)) {
encodeSummary(facesContext, responseWriter, paginator, summaryPosition, locale, first, curPage, rows, rowCount, pageCount);
}
// If any of the pagination controls are the be encoded, then
boolean showPageNumberControls = paginator.isShowPageNumberControls();
boolean showFirstPageControl = paginator.isShowFirstPageControl();
boolean showLastPageControl = paginator.isShowLastPageControl();
boolean showNextPageControl = paginator.isShowNextPageControl();
boolean showPreviousPageControl = paginator.isShowPreviousPageControl();
if (showPageNumberControls || showFirstPageControl || showLastPageControl || showNextPageControl || showPreviousPageControl) {
// Encode the starting <div> element that represents the Bootstrap pagination component.
responseWriter.startElement("div", uiComponent);
// Encode the starting <ul> element that represents the unordered list of pagination controls.
responseWriter.startElement("ul", uiComponent);
responseWriter.writeAttribute("class", "pagination", null);
// summary.
if ("left".equals(summaryPosition)) {
encodeSummary(facesContext, responseWriter, paginator, summaryPosition, locale, first, curPage, rows, rowCount, pageCount);
}
// Encode the "First Page" pagination control.
if (showFirstPageControl) {
encodeFirstPageListItem(facesContext, responseWriter, paginator, clientId, first);
}
// Encode the "Previous Page" pagination control.
if (showPreviousPageControl) {
encodePrevPageListItem(facesContext, responseWriter, paginator, clientId, first);
}
// If pagination controls for page numbers are to be encoded, then
if (showPageNumberControls) {
// Determine the first and last page numbers controls.
int firstPage = paginator.getFirstPage();
int lastPage = firstPage + paginator.getMaxPageNumberControls() - 1;
while (curPage < firstPage) {
firstPage -= 1;
lastPage -= 1;
}
while (curPage > lastPage) {
firstPage += 1;
lastPage += 1;
}
// Remember the state of the first page number that is displayed.
paginator.setFirstPage(firstPage);
if (lastPage > pageCount) {
lastPage = pageCount;
}
// Encode the pagination controls for the appropriate page numbers.
for (int i = firstPage; i <= lastPage; i++) {
encodePageNumberListItem(facesContext, responseWriter, paginator, clientId, i, curPage, first, rows, rowCount);
}
}
// Encode the "Next Page" pagination control.
if (showNextPageControl) {
encodeNextPageListItem(facesContext, responseWriter, paginator, uiData, clientId);
}
// Encode the "Last Page" pagination control.
if (showLastPageControl) {
encodeLastPageListItem(facesContext, responseWriter, paginator, uiData, clientId);
}
// If the summary is to be positioned on the right of the pagination controls, then encode the summary.
if ("right".equals(summaryPosition)) {
encodeSummary(facesContext, responseWriter, paginator, summaryPosition, locale, first, curPage, rows, rowCount, pageCount);
}
// Encode the closing </div> element that represents the unordered list of pagination controls.
responseWriter.endElement("ul");
// Encode the closing </div> element that represents the Bootstrap pagination component.
responseWriter.endElement("div");
}
// If the summary is to be positioned beneath the pagination controls, then encode the summary.
if ("bottom".equals(summaryPosition)) {
encodeSummary(facesContext, responseWriter, paginator, summaryPosition, locale, first, curPage, rows, rowCount, pageCount);
}
}
use of javax.faces.component.UIData in project liferay-faces-alloy by liferay.
the class PaginatorRenderer method decode.
@Override
public void decode(FacesContext facesContext, UIComponent uiComponent) {
boolean activatedPaginationControl = false;
// Decode the client behaviors.
RendererUtil.decodeClientBehaviors(facesContext, uiComponent);
// If there is a UIData component associated with the paginator, then
Paginator paginator = (Paginator) uiComponent;
UIData uiData = paginator.getUIData();
if (uiData != null) {
// Determine the pagination option selected by the user
ExternalContext externalContext = facesContext.getExternalContext();
Map<String, String> requestParameterMap = externalContext.getRequestParameterMap();
String paginatorActionParamName = uiComponent.getClientId().concat("_paginatorAction");
String paginatorAction = requestParameterMap.get(paginatorActionParamName);
if (paginatorAction != null) {
// the first row in the data model.
if ("firstPage".equals(paginatorAction)) {
uiData.setFirst(0);
activatedPaginationControl = true;
} else // component to display the previous set of rows in the data model.
if ("previousPage".equals(paginatorAction)) {
int rows = uiData.getRows();
int first = uiData.getFirst();
first -= rows;
if (first >= 0) {
uiData.setFirst(first);
}
activatedPaginationControl = true;
} else // display the next set of rows in the data model.
if ("nextPage".equals(paginatorAction)) {
int rows = uiData.getRows();
int rowCount = uiData.getRowCount();
int first = uiData.getFirst();
first += rows;
if (first < rowCount) {
uiData.setFirst(first);
}
activatedPaginationControl = true;
} else // display the last set of rows in the data model.
if ("lastPage".equals(paginatorAction)) {
uiData.setFirst((uiData.getRowCount() / uiData.getRows()) * uiData.getRows());
activatedPaginationControl = true;
} else // Otherwise, assume that the user clicked on a page number and cause the associated UIData component to
// display the corresponding set of rows.
{
try {
int pageNumber = Integer.parseInt(paginatorAction);
int pageIndex = pageNumber - 1;
int first = pageIndex * uiData.getRows();
if (first > uiData.getRowCount()) {
first = 0;
}
uiData.setFirst(first);
activatedPaginationControl = true;
} catch (NumberFormatException e) {
logger.error("Invalid parameter value paginatorAction=[{0}]", paginatorAction);
}
}
}
// RENDER_RESPONSE phase.
if (activatedPaginationControl) {
facesContext.renderResponse();
}
} else {
logger.error("The alloy:paginator must have it's for attribute set or it must be inside of an f:facet of an alloy:dataTable or alloy:dataList");
}
}
Aggregations