use of org.primefaces.event.data.PageEvent in project primefaces by primefaces.
the class DataList method queueEvent.
@Override
public void queueEvent(FacesEvent event) {
FacesContext context = getFacesContext();
if (ComponentUtils.isRequestSource(this, context) && event instanceof AjaxBehaviorEvent) {
setRowIndex(-1);
AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
if ("page".equals(eventName)) {
String clientId = getClientId(context);
int rows = getRowsToRender();
int first = Integer.parseInt(params.get(clientId + "_first"));
int page = rows > 0 ? first / rows : 0;
PageEvent pageEvent = new PageEvent(this, behaviorEvent.getBehavior(), page);
pageEvent.setPhaseId(behaviorEvent.getPhaseId());
super.queueEvent(pageEvent);
} else if ("tap".equals(eventName) || "taphold".equals(eventName)) {
String clientId = getClientId(context);
int index = Integer.parseInt(params.get(clientId + "_item"));
setRowIndex(index);
SelectEvent<?> selectEvent = new SelectEvent(this, behaviorEvent.getBehavior(), getRowData());
selectEvent.setPhaseId(behaviorEvent.getPhaseId());
setRowIndex(-1);
super.queueEvent(selectEvent);
}
} else {
super.queueEvent(event);
}
}
use of org.primefaces.event.data.PageEvent in project primefaces by primefaces.
the class DataTable method queueEvent.
@Override
public void queueEvent(FacesEvent event) {
FacesContext context = getFacesContext();
if (ComponentUtils.isRequestSource(this, context) && event instanceof AjaxBehaviorEvent) {
setRowIndex(-1);
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
String clientId = getClientId(context);
FacesEvent wrapperEvent = null;
AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
if ("rowSelect".equals(eventName) || "rowSelectRadio".equals(eventName) || "contextMenu".equals(eventName) || "rowSelectCheckbox".equals(eventName) || "rowDblselect".equals(eventName)) {
String rowKey = params.get(clientId + "_instantSelectedRowKey");
wrapperEvent = new SelectEvent(this, behaviorEvent.getBehavior(), getRowData(rowKey));
} else if ("rowUnselect".equals(eventName) || "rowUnselectCheckbox".equals(eventName)) {
String rowKey = params.get(clientId + "_instantUnselectedRowKey");
wrapperEvent = new UnselectEvent(this, behaviorEvent.getBehavior(), getRowData(rowKey));
} else if ("page".equals(eventName) || "virtualScroll".equals(eventName) || "liveScroll".equals(eventName)) {
int rows = getRowsToRender();
int first = Integer.parseInt(params.get(clientId + "_first"));
int page = rows > 0 ? (first / rows) : 0;
wrapperEvent = new PageEvent(this, behaviorEvent.getBehavior(), page);
} else if ("sort".equals(eventName)) {
wrapperEvent = new SortEvent(this, behaviorEvent.getBehavior(), getSortByAsMap());
} else if ("filter".equals(eventName)) {
deferredEvents.put("filter", (AjaxBehaviorEvent) event);
return;
} else if ("rowEdit".equals(eventName) || "rowEditCancel".equals(eventName) || "rowEditInit".equals(eventName)) {
loadLazyDataIfRequired();
int rowIndex = Integer.parseInt(params.get(clientId + "_rowEditIndex"));
setRowIndex(rowIndex);
wrapperEvent = new RowEditEvent(this, behaviorEvent.getBehavior(), getRowData());
} else if ("colResize".equals(eventName)) {
String columnId = params.get(clientId + "_columnId");
int width = Double.valueOf(params.get(clientId + "_width")).intValue();
int height = Double.valueOf(params.get(clientId + "_height")).intValue();
wrapperEvent = new ColumnResizeEvent(this, behaviorEvent.getBehavior(), width, height, findColumn(columnId));
} else if ("toggleSelect".equals(eventName)) {
boolean checked = Boolean.parseBoolean(params.get(clientId + "_checked"));
wrapperEvent = new ToggleSelectEvent(this, behaviorEvent.getBehavior(), checked);
} else if ("colReorder".equals(eventName)) {
wrapperEvent = behaviorEvent;
} else if ("rowToggle".equals(eventName)) {
loadLazyDataIfRequired();
boolean expansion = params.containsKey(clientId + "_rowExpansion");
Visibility visibility = expansion ? Visibility.VISIBLE : Visibility.HIDDEN;
String rowIndex = expansion ? params.get(clientId + "_expandedRowIndex") : params.get(clientId + "_collapsedRowIndex");
setRowIndex(Integer.parseInt(rowIndex));
wrapperEvent = new ToggleEvent(this, behaviorEvent.getBehavior(), visibility, getRowData());
} else if ("cellEdit".equals(eventName) || "cellEditCancel".equals(eventName) || "cellEditInit".equals(eventName)) {
String[] cellInfo = params.get(clientId + "_cellInfo").split(",");
int rowIndex = Integer.parseInt(cellInfo[0]);
int cellIndex = Integer.parseInt(cellInfo[1]);
String rowKey = null;
if (cellInfo.length == 3) {
rowKey = cellInfo[2];
}
int i = -1;
UIColumn column = null;
for (UIColumn col : getColumns()) {
if (col.isRendered()) {
i++;
if (i == cellIndex) {
column = col;
break;
}
}
}
wrapperEvent = new CellEditEvent(this, behaviorEvent.getBehavior(), rowIndex, column, rowKey);
} else if ("rowReorder".equals(eventName)) {
int fromIndex = Integer.parseInt(params.get(clientId + "_fromIndex"));
int toIndex = Integer.parseInt(params.get(clientId + "_toIndex"));
wrapperEvent = new ReorderEvent(this, behaviorEvent.getBehavior(), fromIndex, toIndex);
} else if ("tap".equals(eventName) || "taphold".equals(eventName)) {
String rowkey = params.get(clientId + "_rowkey");
wrapperEvent = new SelectEvent(this, behaviorEvent.getBehavior(), getRowData(rowkey));
}
if (wrapperEvent == null) {
throw new FacesException("Component " + getClass().getName() + " does not support event " + eventName + "!");
}
wrapperEvent.setPhaseId(event.getPhaseId());
super.queueEvent(wrapperEvent);
} else {
super.queueEvent(event);
}
}
use of org.primefaces.event.data.PageEvent in project primefaces by primefaces.
the class DataView method queueEvent.
@Override
public void queueEvent(FacesEvent event) {
FacesContext context = getFacesContext();
if (ComponentUtils.isRequestSource(this, context) && event instanceof AjaxBehaviorEvent) {
setRowIndex(-1);
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
if ("page".equals(eventName)) {
AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
String clientId = getClientId(context);
int rows = getRowsToRender();
int first = Integer.parseInt(params.get(clientId + "_first"));
int page = rows > 0 ? (int) (first / rows) : 0;
PageEvent pageEvent = new PageEvent(this, behaviorEvent.getBehavior(), page);
pageEvent.setPhaseId(behaviorEvent.getPhaseId());
super.queueEvent(pageEvent);
}
} else {
super.queueEvent(event);
}
}
use of org.primefaces.event.data.PageEvent in project primefaces by primefaces.
the class DataGrid method queueEvent.
@Override
public void queueEvent(FacesEvent event) {
FacesContext context = getFacesContext();
if (ComponentUtils.isRequestSource(this, context) && event instanceof AjaxBehaviorEvent) {
setRowIndex(-1);
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
if ("page".equals(eventName)) {
AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
String clientId = getClientId(context);
int rows = getRowsToRender();
int first = Integer.parseInt(params.get(clientId + "_first"));
int page = rows > 0 ? (int) (first / rows) : 0;
PageEvent pageEvent = new PageEvent(this, behaviorEvent.getBehavior(), page);
pageEvent.setPhaseId(behaviorEvent.getPhaseId());
super.queueEvent(pageEvent);
}
} else {
super.queueEvent(event);
}
}
use of org.primefaces.event.data.PageEvent in project primefaces by primefaces.
the class TreeTable method queueEvent.
@Override
public void queueEvent(FacesEvent event) {
FacesContext context = getFacesContext();
if (ComponentUtils.isRequestSource(this, context) && (event instanceof AjaxBehaviorEvent)) {
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
String clientId = getClientId(context);
FacesEvent wrapperEvent = null;
TreeNode root = getValue();
AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
if ("expand".equals(eventName)) {
String nodeKey = params.get(clientId + "_expand");
setRowKey(root, nodeKey);
TreeNode node = getRowNode();
wrapperEvent = new NodeExpandEvent(this, behaviorEvent.getBehavior(), node);
wrapperEvent.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
} else if ("collapse".equals(eventName)) {
String nodeKey = params.get(clientId + "_collapse");
setRowKey(root, nodeKey);
TreeNode node = getRowNode();
node.setExpanded(false);
wrapperEvent = new NodeCollapseEvent(this, behaviorEvent.getBehavior(), node);
wrapperEvent.setPhaseId(PhaseId.APPLY_REQUEST_VALUES);
} else if ("select".equals(eventName) || "contextMenu".equals(eventName)) {
String nodeKey = params.get(clientId + "_instantSelection");
setRowKey(root, nodeKey);
TreeNode node = getRowNode();
wrapperEvent = new NodeSelectEvent(this, behaviorEvent.getBehavior(), node);
wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
} else if ("unselect".equals(eventName)) {
String nodeKey = params.get(clientId + "_instantUnselection");
setRowKey(root, nodeKey);
TreeNode node = getRowNode();
wrapperEvent = new NodeUnselectEvent(this, behaviorEvent.getBehavior(), node);
wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
} else if ("colResize".equals(eventName)) {
String columnId = params.get(clientId + "_columnId");
int width = Integer.parseInt(params.get(clientId + "_width"));
int height = Integer.parseInt(params.get(clientId + "_height"));
wrapperEvent = new ColumnResizeEvent(this, behaviorEvent.getBehavior(), width, height, findColumn(columnId));
} else if ("sort".equals(eventName)) {
wrapperEvent = new SortEvent(this, behaviorEvent.getBehavior(), getSortByAsMap());
} else if ("filter".equals(eventName)) {
deferredEvents.put("filter", (AjaxBehaviorEvent) event);
return;
} else if ("rowEdit".equals(eventName) || "rowEditCancel".equals(eventName) || "rowEditInit".equals(eventName)) {
String nodeKey = params.get(clientId + "_rowEditIndex");
setRowKey(root, nodeKey);
wrapperEvent = new RowEditEvent(this, behaviorEvent.getBehavior(), getRowNode());
wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
} else if ("cellEdit".equals(eventName) || "cellEditCancel".equals(eventName) || "cellEditInit".equals(eventName)) {
String[] cellInfo = params.get(clientId + "_cellInfo").split(",");
String rowKey = cellInfo[0];
int cellIndex = Integer.parseInt(cellInfo[1]);
int i = -1;
UIColumn column = null;
for (UIColumn col : getColumns()) {
if (col.isRendered()) {
i++;
if (i == cellIndex) {
column = col;
break;
}
}
}
wrapperEvent = new CellEditEvent(this, behaviorEvent.getBehavior(), column, rowKey);
wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
} else if ("page".equals(eventName)) {
int rows = getRowsToRender();
int first = Integer.parseInt(params.get(clientId + "_first"));
int page = rows > 0 ? (first / rows) : 0;
wrapperEvent = new PageEvent(this, behaviorEvent.getBehavior(), page);
wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
}
super.queueEvent(wrapperEvent);
} else {
super.queueEvent(event);
}
}
Aggregations