private static String getChainedHandler( FacesContext context, UIComponent component, List<ClientBehavior> behaviors, Collection<ClientBehaviorContext.Parameter> params, String behaviorEventName, String userHandler) { StringBuilder builder = new StringBuilder(100); builder.append("jsf.util.chain(this,event,"); appendScriptToChain(builder, userHandler); boolean submitting = appendBehaviorsToChain(builder, context, component, behaviors, behaviorEventName, params); boolean hasParams = ((null != params) && !params.isEmpty()); if (!submitting && hasParams) { String submitHandler = getSubmitHandler(context, component, params, false); appendScriptToChain(builder, submitHandler); submitting = true; } builder.append(")"); if (submitting && ("action".equals(behaviorEventName) || "click".equals(behaviorEventName))) { builder.append(";return false"); } return builder.toString(); }
private static String getSubmitHandler( FacesContext context, UIComponent component, Collection<ClientBehaviorContext.Parameter> params, boolean preventDefault) { StringBuilder builder = new StringBuilder(256); String formClientId = getFormClientId(component, context); String componentClientId = component.getClientId(context); builder.append("qab.sf(document.getElementById('"); builder.append(formClientId); builder.append("'),{"); appendProperty(builder, componentClientId, componentClientId); if ((null != params) && (!params.isEmpty())) { for (ClientBehaviorContext.Parameter param : params) { appendProperty(builder, param.getName(), param.getValue()); } } builder.append("})"); if (preventDefault) { builder.append(";return false"); } return builder.toString(); }
private static HandlerType getHandlerType( List<ClientBehavior> behaviors, Collection<ClientBehaviorContext.Parameter> params, String userHandler) { if ((behaviors == null) || (behaviors.isEmpty())) { if (params.isEmpty()) return HandlerType.USER_HANDLER_ONLY; return (userHandler == null) ? HandlerType.SUBMIT_ONLY : HandlerType.CHAIN; } if ((behaviors.size() == 1) && (userHandler == null)) { ClientBehavior behavior = behaviors.get(0); if (isSubmitting(behavior) || params.isEmpty()) return HandlerType.SINGLE_BEHAVIOR_ONLY; } return HandlerType.CHAIN; }
protected void addViewParameters( FacesContext ctx, String viewId, Map<String, List<String>> existingParameters) { UIViewRoot currentRoot = ctx.getViewRoot(); String currentViewId = currentRoot.getViewId(); Collection<UIViewParameter> toViewParams; Collection<UIViewParameter> currentViewParams; boolean currentIsSameAsNew = false; currentViewParams = ViewMetadata.getViewParameters(currentRoot); if (currentViewId.equals(viewId)) { currentIsSameAsNew = true; toViewParams = currentViewParams; } else { ViewDeclarationLanguage pdl = getViewDeclarationLanguage(ctx, viewId); ViewMetadata viewMetadata = pdl.getViewMetadata(ctx, viewId); UIViewRoot root = viewMetadata.createMetadataView(ctx); toViewParams = ViewMetadata.getViewParameters(root); } if (toViewParams.isEmpty()) { return; } for (UIViewParameter viewParam : toViewParams) { String value; // don't bother looking at view parameter if it's been overridden if (existingParameters.containsKey(viewParam.getName())) { continue; } else if (paramHasValueExpression(viewParam)) { value = viewParam.getStringValueFromModel(ctx); } else { // Anonymous view parameter: // Get string value from UIViewParameter instance stored in current view if (currentIsSameAsNew) { value = viewParam.getStringValue(ctx); } // ...or transfer string value from matching UIViewParameter instance stored in current view else { value = getStringValueToTransfer(ctx, viewParam, currentViewParams); } } if (value != null) { List<String> existing = existingParameters.get(viewParam.getName()); if (existing == null) { existing = new ArrayList<String>(4); existingParameters.put(viewParam.getName(), existing); } existing.add(value); } } }
private static String getStringValueToTransfer( FacesContext context, UIViewParameter param, Collection<UIViewParameter> viewParams) { if (viewParams != null && !viewParams.isEmpty()) { for (UIViewParameter candidate : viewParams) { if ((null != candidate.getName() && null != param.getName()) && candidate.getName().equals(param.getName())) { return candidate.getStringValue(context); } else { return param.getStringValue(context); } } } return null; }