if (event instanceof MenuActionEvent) { FacesContext facesContext = getFacesContext(); ELContext eLContext = facesContext.getELContext(); MenuActionEvent menuActionEvent = (MenuActionEvent) event; MenuItem menuItem = menuActionEvent.getMenuItem(); MethodExpression noArgExpr = facesContext.getApplication().getExpressionFactory(). createMethodExpression(eLContext, actionExpressionString, String.class, new Class[0]); Object invokeResult = null; invokeResult = noArgExpr.invoke(eLContext, null); MethodExpression argExpr = facesContext.getApplication().getExpressionFactory(). createMethodExpression(eLContext, actionExpressionString, String.class, new Class[]{ActionEvent.class}); invokeResult = argExpr.invoke(eLContext, new Object[]{event}); MethodExpression argExpr = facesContext.getApplication().getExpressionFactory(). createMethodExpression(eLContext, actionExpressionString, String.class, new Class[]{MenuActionEvent.class}); invokeResult = argExpr.invoke(eLContext, new Object[]{event});
private void processCustomArgListener(FacesContext context, ELContext elContext, AjaxBehaviorEvent event) throws AbortProcessingException { if (listenerWithCustomArg == null) { MethodExpression argListener = context.getApplication().getExpressionFactory(). createMethodExpression(elContext, listener.getExpressionString(), Void.class, new Class[]{event.getClass()}); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Try to invoke customListener: " + argListener.getExpressionString()); } argListener.invoke(elContext, new Object[]{event}); } else { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Try to invoke customListener: " + listenerWithCustomArg.getExpressionString()); } listenerWithCustomArg.invoke(elContext, new Object[]{event}); } } }
private void processArgListener(FacesContext context, ELContext elContext, AjaxBehaviorEvent event) throws AbortProcessingException { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Try to invoke listenerWithArg: " + listenerWithArg.getExpressionString()); } try { listenerWithArg.invoke(elContext, new Object[]{event}); } catch (MethodNotFoundException | IllegalArgumentException mnfe) { processCustomArgListener(context, elContext, event); } }
@Override public void processAjaxBehavior(AjaxBehaviorEvent event) throws AbortProcessingException { FacesContext context = FacesContext.getCurrentInstance(); final ELContext elContext = context.getELContext(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Try to invoke listener: " + listener.getExpressionString()); } try { listener.invoke(elContext, new Object[]{}); } catch (MethodNotFoundException | IllegalArgumentException | ArrayIndexOutOfBoundsException mnfe) { processArgListener(context, elContext, event); } }
Locale viewLocale = null; UIViewRoot viewRoot = (UIViewRoot) component; FacesContext context = FacesContext.getCurrentInstance(); ELContext elContext = context.getELContext(); try { if (renderKitId.isLiteralText()) { viewRoot.setRenderKitId(renderKitId.getValue(elContext).toString()); } else { viewRoot.setRenderKitId(null); viewRoot.setValueExpression("renderKitId", renderKitId); if (locale.isLiteralText()) { component.setValueExpression("locale", locale); Object result = locale.getValue(context.getELContext()); if (result instanceof Locale) { if (beforePhase.isLiteralText()) { Object params [] = {beforePhase}; throw new javax.faces.FacesException(MessageUtils.getExceptionMessageString(MessageUtils.INVALID_EXPRESSION_ID, params)); if (afterPhase.isLiteralText()) { Object params [] = {afterPhase}; throw new javax.faces.FacesException(MessageUtils.getExceptionMessageString(MessageUtils.INVALID_EXPRESSION_ID, params));
public int compare(Object obj1, Object obj2) { try { FacesContext context = FacesContext.getCurrentInstance(); context.getExternalContext().getRequestMap().put(var, obj1); Object value1 = sortBy.getValue(context.getELContext()); context.getExternalContext().getRequestMap().put(var, obj2); Object value2 = sortBy.getValue(context.getELContext()); result = (Integer) sortFunction.invoke(context.getELContext(), new Object[]{value1, value2});
public void processAction(ActionEvent actionEvent) throws AbortProcessingException FacesContext facesContext = FacesContext.getCurrentInstance(); Application application = facesContext.getApplication(); UIComponent component = actionEvent.getComponent(); fromAction = methodExpression.getExpressionString(); try Object objOutcome = methodExpression.invoke(facesContext.getELContext(), null); if (objOutcome != null) Throwable cause = e.getCause(); if (cause != null && cause instanceof AbortProcessingException) throw new FacesException("Error calling action method of component with id " + actionEvent.getComponent().getClientId(facesContext), e); throw new FacesException("Error calling action method of component with id " + actionEvent.getComponent().getClientId(facesContext), e); throw new FacesException("Error calling action method of component with id " + actionEvent.getComponent().getClientId(facesContext), e); NavigationHandler navigationHandler = application.getNavigationHandler(); navigationHandler.handleNavigation(facesContext, fromAction, outcome);
public MethodExpressionAjaxBehaviorListener(MethodExpression methodExpressionOneArg) { this.methodExpressionOneArg = methodExpressionOneArg; FacesContext context = FacesContext.getCurrentInstance(); ELContext elContext = context.getELContext(); this.methodExpressionZeroArg = context .getApplication() .getExpressionFactory() .createMethodExpression(elContext, methodExpressionOneArg.getExpressionString(), Void.class, ACTION_LISTENER_ZEROARG_SIG); }
@Override public void decode(FacesContext context, DataTable table) { MethodExpression me = table.getDraggableRowsFunction(); if (me != null) { me.invoke(context.getELContext(), new Object[]{table}); } else { Map<String, String> params = context.getExternalContext().getRequestParameterMap(); String clientId = table.getClientId(context); int fromIndex = Integer.parseInt(params.get(clientId + "_fromIndex")); int toIndex = Integer.parseInt(params.get(clientId + "_toIndex")); table.setRowIndex(fromIndex); Object value = table.getValue(); if (value instanceof List) { List list = (List) value; if (toIndex >= fromIndex) { Collections.rotate(list.subList(fromIndex, toIndex + 1), -1); } else { Collections.rotate(list.subList(toIndex, fromIndex + 1), 1); } } else { LOGGER.info("Row reordering is only available for list backed datatables, " + "use rowReorder ajax behavior with listener for manual handling of model update."); } } }
@Override public void broadcast(javax.faces.event.FacesEvent event) throws AbortProcessingException { super.broadcast(event); FacesContext context = FacesContext.getCurrentInstance(); String outcome = null; MethodExpression me = null; DataTable table = RowEditorRenderer.findParentTable(context, this); RowState state = (RowState)(context.getExternalContext().getRequestMap().get(table.getRowStateVar())); if (event instanceof RowEditEvent) me = getRowEditListener(); else if (event instanceof RowEditCancelEvent) me = getRowEditCancelListener(); if (me != null) outcome = (String) me.invoke(context.getELContext(), new Object[] {event}); if (outcome != null) { NavigationHandler navHandler = context.getApplication().getNavigationHandler(); navHandler.handleNavigation(context, null, outcome); context.renderResponse(); } }
@Override public void export(FacesContext context, List<String> clientIds, String filename, boolean pageOnly, boolean selectionOnly, String encodingType, MethodExpression preProcessor, MethodExpression postProcessor, ExporterOptions options, MethodExpression onTableRender) throws IOException { Workbook wb = createWorkBook(); if (preProcessor != null) { preProcessor.invoke(context.getELContext(), new Object[]{wb}); } VisitContext visitContext = VisitContext.createVisitContext(context, clientIds, null); VisitCallback visitCallback = new ExcelExportVisitCallback(this, wb, pageOnly, selectionOnly); context.getViewRoot().visitTree(visitContext, visitCallback); if (postProcessor != null) { postProcessor.invoke(context.getELContext(), new Object[]{wb}); } writeExcelToResponse(context.getExternalContext(), wb, filename); }
/** * Notify afterPhase listener that is registered on the View Root. * @param context the FacesContext for the current request * @param lifecycle lifecycle instance */ private void notifyAfter(FacesContext context, Lifecycle lifecycle) { UIViewRoot viewRoot = context.getViewRoot(); if (null == viewRoot) { return; } MethodExpression afterPhase = viewRoot.getAfterPhaseListener(); if (null != afterPhase) { try { PhaseEvent event = new PhaseEvent(context, PhaseId.RESTORE_VIEW, lifecycle); afterPhase.invoke(context.getELContext(), new Object[]{event}); } catch (Exception e) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, "severe.component.unable_to_process_expression", new Object[] { afterPhase.getExpressionString(), ("afterPhase")}); } return; } } }
@SuppressWarnings("unchecked") protected <C extends UIComponent, O extends Serializable> void export(final ActionEvent event) throws Exception { final FacesContext facesContext = FacesContext.getCurrentInstance(); final ExternalContext externalContext = facesContext.getExternalContext(); final ELContext elContext = facesContext.getELContext(); final String componentId = (String) sourceExpr.getValue(elContext); final C sourceComponent = (C) event.getComponent().findComponent(componentId); if (sourceComponent == null) { throw new FacesException("Could not find component \"" + componentId + "\" in view"); final String fileType = (String) fileInfo.getFileType().getValue(elContext); final String fileName = (String) fileInfo.getFileName().getValue(elContext); callback.getPreProcessor().invoke(elContext, new Object[] { exporter.getPreProcessorParam() }); callback.getPostProcessor().invoke(elContext, new Object[] { exporter.getPostProcessorParam() });
parameters[i] = param.getValue().getValue(facesContext.getELContext()); clazzes[i] = param.getName() != null ? ClassUtils.simpleJavaTypeToClass(param.getName()) : method = facesContext.getApplication().getExpressionFactory().createMethodExpression( facesContext.getELContext(), method.getExpressionString(), null, clazzes); value = method.invoke(facesContext.getELContext(), parameters); value = method.invoke(facesContext.getELContext(), null);
MethodExpression onTableRender) throws IOException { ExternalContext externalContext = context.getExternalContext(); configureResponse(externalContext, filename); StringBuilder builder = new StringBuilder(); preProcessor.invoke(context.getELContext(), new Object[]{builder}); postProcessor.invoke(context.getELContext(), new Object[]{builder}); OutputStream os = externalContext.getResponseOutputStream(); OutputStreamWriter osw = new OutputStreamWriter(os, encodingType); PrintWriter writer = new PrintWriter(osw);
/** ********************************************************* */ /* * (non-Javadoc) * * @see javax.faces.event.ActionListener#processAction(javax.faces.event.ActionEvent) */ public void processAction(ActionEvent actionEvent) throws AbortProcessingException { FacesContext context = getFacesContext(); ELContext elContext = context.getELContext(); ValueExpression updateBinding = getAssignToBinding(); if (updateBinding != null && (!updateBinding.isReadOnly(elContext))) { Object requestValue = context.getExternalContext().getRequestParameterMap().get(getName()); if (requestValue != null && requestValue instanceof String) { Class<?> type = updateBinding.getType(elContext); Converter converter = createConverter(context, type); if (null != converter) { requestValue = converter.getAsObject(context, this, (String) requestValue); } } if (null != requestValue) { updateBinding.setValue(elContext, requestValue); } MethodExpression listener = getActionListener(); if (listener != null) { listener.invoke(elContext, new Object[] { actionEvent }); } } }
@Override public void broadcast(javax.faces.event.FacesEvent event) throws javax.faces.event.AbortProcessingException { super.broadcast(event); //backward compatibility FacesContext facesContext = getFacesContext(); MethodExpression me = getListener(); if (me != null) { me.invoke(facesContext.getELContext(), new Object[]{}); } ValueExpression expr = getValueExpression(PropertyKeys.stop.toString()); if (expr != null) { Boolean stop = (Boolean) expr.getValue(facesContext.getELContext()); if (Boolean.TRUE.equals(stop)) { String widgetVar = resolveWidgetVar(); PrimeFaces.current().executeScript("PF('" + widgetVar + "').stop();"); } } }
public void processEvent(ComponentSystemEvent event) FacesContext facesContext = FacesContext.getCurrentInstance(); UIComponent cc = facesContext.getViewRoot().findComponent(_compositeComponentExpression); cc.pushComponentToEL(facesContext, cc); try ELContext elContext = facesContext.getELContext(); try this.methodExpOneArg.invoke(elContext, new Object[] { event }); this.methodExpZeroArg.invoke(elContext, new Object[0]);
FacesContext context = FacesContext.getCurrentInstance(); ELContext elContext = context.getELContext(); methodExpression.invoke(elContext, new Object[] {actionEvent}); } catch (ELException ee) { Throwable eeCause = ee.getCause(); if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, new Object[]{ eeCause == null ? ee.getClass().getName() : eeCause.getClass().getName(), methodExpression.getExpressionString(), actionEvent.getComponent().getId() }); StringWriter writer = new StringWriter(1024); if (eeCause == null) { ee.printStackTrace(new PrintWriter(writer)); } else { eeCause.printStackTrace(new PrintWriter(writer)); throw eeCause == null ? new AbortProcessingException(ee.getMessage(), ee) : new AbortProcessingException(ee.getMessage(), eeCause);
throw new NullPointerException(); FacesContext context = FacesContext.getCurrentInstance(); ELContext elContext = context.getELContext(); try { methodExpressionOneArg.invoke(elContext, new Object[] {actionEvent}); } catch (MethodNotFoundException mnfe) { if (null != methodExpressionZeroArg) { try { methodExpressionZeroArg.invoke(elContext, new Object[]{}); cause = ee.getCause(); thrown = ee; cause = ee.getCause(); thrown = ee; new Object[]{ cause == null ? thrown.getClass().getName() : cause.getClass().getName(), methodExpressionOneArg.getExpressionString(), actionEvent.getComponent().getId() }); StringWriter writer = new StringWriter(1024);