/** * Scrolls to a component with the given clientId. * * @param clientId clientId of the target component. */ public void scrollTo(String clientId) { executeScript("PrimeFaces.scrollTo('" + clientId + "');"); }
public static PrimeFaces current() { return PrimeFaces.current(); } }
public void loadLazyScrollData(int offset, int rows) { DataModel model = getDataModel(); if (model instanceof LazyDataModel) { LazyDataModel lazyModel = (LazyDataModel) model; List<?> data = null; if (isMultiSort()) { data = lazyModel.load(offset, rows, getMultiSortMeta(), getFilters()); } else { data = lazyModel.load(offset, rows, resolveSortField(), convertSortOrder(), getFilters()); } lazyModel.setPageSize(rows); lazyModel.setWrappedData(data); //Update paginator/livescroller for callback if (ComponentUtils.isRequestSource(this, getFacesContext()) && (isPaginator() || isLiveScroll() || isVirtualScroll())) { PrimeFaces.current().ajax().addCallbackParam("totalRecords", lazyModel.getRowCount()); } } }
public void loadLazyData() { DataModel model = getDataModel(); if (model instanceof LazyDataModel) { LazyDataModel lazyModel = (LazyDataModel) model; List<?> data = lazyModel.load(getFirst(), getRows(), null, null, null); lazyModel.setPageSize(getRows()); lazyModel.setWrappedData(data); //Update paginator for callback if (ComponentUtils.isRequestSource(this, getFacesContext()) && isPaginator()) { PrimeFaces.current().ajax().addCallbackParam("totalRecords", lazyModel.getRowCount()); } } }
public void loadLazyData() { DataModel model = getDataModel(); if (model instanceof LazyDataModel) { LazyDataModel lazyModel = (LazyDataModel) model; List<?> data = lazyModel.load(getFirst(), getRows(), null, null, null); lazyModel.setPageSize(getRows()); lazyModel.setWrappedData(data); //Update paginator for callback if (ComponentUtils.isRequestSource(this, getFacesContext()) && isPaginator()) { PrimeFaces.current().ajax().addCallbackParam("totalRecords", lazyModel.getRowCount()); } } }
@Override public void decode(FacesContext context, UIComponent component) { ProgressBar progressBar = (ProgressBar) component; String clientId = progressBar.getClientId(context); Map<String, String> params = context.getExternalContext().getRequestParameterMap(); if (params.containsKey(clientId)) { PrimeFaces.current().ajax().addCallbackParam(progressBar.getClientId(context) + "_value", progressBar.getValue()); } decodeBehaviors(context, progressBar); }
@Override public void broadcast(FacesEvent event) throws AbortProcessingException { super.broadcast(event); if (event instanceof TabEvent) { MethodExpression me = getTabController(); if (me != null) { boolean retVal = (Boolean) me.invoke(getFacesContext().getELContext(), new Object[]{event}); PrimeFaces.current().ajax().addCallbackParam("access", retVal); } } } }
protected void encodeStep(FacesContext context, Wizard wizard) throws IOException { String stepToDisplay = wizard.getStep(); if (!isValueBlank(stepToDisplay)) { UIComponent tabToDisplay = null; for (UIComponent child : wizard.getChildren()) { if (child.getId().equals(stepToDisplay)) { tabToDisplay = child; } } if (tabToDisplay != null) { tabToDisplay.encodeAll(context); } PrimeFaces.current().ajax().addCallbackParam("currentStep", wizard.getStep()); } }
@Override public void decode(FacesContext context, UIComponent component) { Clock clock = (Clock) component; if (clock.isSyncRequest()) { PrimeFaces.current().ajax().addCallbackParam("datetime", System.currentTimeMillis()); context.renderResponse(); } }
/** * Displays a message in a dynamic dialog. * * @param message the {@link FacesMessage} to be displayed. */ public void showMessageDynamic(FacesMessage message) { String summary = EscapeUtils.forJavaScript(message.getSummary()); String detail = EscapeUtils.forJavaScript(message.getDetail()); executeScript("PrimeFaces.showMessageInDialog({severity:\"" + message.getSeverity() + "\",summary:\"" + summary + "\",detail:\"" + detail + "\"});"); } }
/** * Updates all components with the given expressions or clientIds. * * @param expressions a list of expressions or clientIds. */ public void update(String... expressions) { if (expressions == null || expressions.length == 0) { return; } update(Arrays.asList(expressions)); } }
/** * Executes a JavaScript statement. * * @param statement the JavaScript statement. */ public void executeScript(String statement) { getRequestContext().getScriptsToExecute().add(statement); }
/** * Add a parameter for ajax oncomplete client side callbacks. Value will be serialized to json. * Currently supported values are primitives, POJOs, JSONObject and JSONArray. * * @param name name of the parameter. * @param value value of the parameter. */ public void addCallbackParam(String name, Object value) { getRequestContext().getCallbackParams().put(name, value); }
/** * Opens a view in a dynamic dialog. * * @param outcome the logical outcome used to resolve the navigation case. */ public void openDynamic(String outcome) { getFacesContext().getAttributes().put(Constants.DIALOG_FRAMEWORK.OUTCOME, outcome); }
/** * Resolves the search expressions, starting from the viewroot and resets all found {@link UIInput} components. * * @param expressions a list of search expressions. */ public void resetInputs(String... expressions) { if (expressions == null || expressions.length == 0) { return; } resetInputs(Arrays.asList(expressions)); }
/** * Resolves the search expression, starting from the viewroot, and focus the resolved component. * * @param expression The search expression. */ public void focus(String expression) { focus(expression, FacesContext.getCurrentInstance().getViewRoot()); }
/** * Removes the multiViewState for one specific DataList within the current session. * @param key Key of the DataList. See {@link org.primefaces.component.datalist.DataList#getDataListState(boolean)}} for the namebuild of this key. */ public void clearDataListState(String key) { Map<String, Object> sessionMap = getFacesContext().getExternalContext().getSessionMap(); Map<String, TableState> dtState = (Map) sessionMap.get(Constants.DATALIST_STATE); if (dtState != null) { dtState.remove(key); } }
/** * Shortcut for {@link PartialViewContext#isAjaxRequest()}. * * @return <code>true</code> if the current request is a AJAX request. */ public boolean isAjaxRequest() { return getFacesContext().getPartialViewContext().isAjaxRequest(); }
/** * Opens a view in a dynamic dialog. * * @param outcome the logical outcome used to resolve the navigation case. * @param options configuration options for the dialog. * @param params parameters to send to the view displayed in the dynamic dialog. */ public void openDynamic(String outcome, Map<String, Object> options, Map<String, List<String>> params) { FacesContext facesContext = getFacesContext(); facesContext.getAttributes().put(Constants.DIALOG_FRAMEWORK.OUTCOME, outcome); if (options != null) { facesContext.getAttributes().put(Constants.DIALOG_FRAMEWORK.OPTIONS, options); } if (params != null) { facesContext.getAttributes().put(Constants.DIALOG_FRAMEWORK.PARAMS, params); } }