public static void addToScriptHash( Map<String, Object> hash, FacesContext facesContext, UIComponent component, Attributes attributes, ScriptHashVariableWrapper wrapper) { boolean disabled = isDisabled(component); for (ComponentAttribute knownAttribute : attributes) { if (!disabled || knownAttribute.getEventNames().length == 0) { String attributeName = knownAttribute.getComponentAttributeName(); addToScriptHash( hash, attributeName, getAttributeAndBehaviorsValue(facesContext, component, knownAttribute), knownAttribute.getDefaultValue(), wrapper); } } }
// TODO - create special method for event handlers that will return String? // TODO - add check for 'disabled'? public static Object getAttributeAndBehaviorsValue( FacesContext facesContext, UIComponent component, ComponentAttribute componentAttribute) { if (facesContext == null) { throw new NullPointerException("facesContext"); } if (component == null) { throw new NullPointerException("component"); } if (componentAttribute == null) { throw new NullPointerException("componentAttribute"); } String componentAttributeName = componentAttribute.getComponentAttributeName(); Object attributeValue = component.getAttributes().get(componentAttributeName); String[] eventNames = componentAttribute.getEventNames(); if (eventNames.length > 0) { Map<String, List<ClientBehavior>> behaviorsMap = getClientBehaviorsMap(component); if (behaviorsMap.size() > 0) { for (String eventName : eventNames) { if (behaviorsMap.containsKey(eventName)) { List<ClientBehavior> behaviorsList = behaviorsMap.get(eventName); if (!behaviorsList.isEmpty()) { // TODO - parameters handling ClientBehaviorContext behaviorContext = ClientBehaviorContext.createClientBehaviorContext( facesContext, component, eventName, null, null); attributeValue = createBehaviorsChain(attributeValue, behaviorContext, behaviorsList); } break; } } } } return attributeValue; }