private void removeChildState(FacesContext faces, UIComponent c) { String id = c.getId(); c.setId(id); Iterator itr = c.getFacetsAndChildren(); while (itr.hasNext()) { removeChildState(faces, (UIComponent) itr.next()); } if (childState != null) { childState.remove(c.getClientId(faces)); } }
/** * Finds the first component with the given id (NOT clientId!). * * @param id The id. * @param base The base component to start the traversal. * @return The component or null. */ public static UIComponent firstWithId(String id, UIComponent base) { if (id.equals(base.getId())) { return base; } UIComponent result = null; Iterator<UIComponent> kids = base.getFacetsAndChildren(); while (kids.hasNext() && (result == null)) { UIComponent kid = kids.next(); if (id.equals(kid.getId())) { result = kid; break; } result = firstWithId(id, kid); if (result != null) { break; } } return result; }
public static void withId(String id, UIComponent base, List<UIComponent> components) { if (id.equals(base.getId())) { components.add(base); } if (base.getFacetCount() > 0) { for (UIComponent facet : base.getFacets().values()) { withId(id, facet, components); } } if (base.getChildCount() > 0) { for (int i = 0, childCount = base.getChildCount(); i < childCount; i++) { UIComponent child = base.getChildren().get(i); withId(id, child, components); } } }
private static UIComponent findMenuPopup(UIComponent comp) { String id = (String) comp.getAttributes().get("menuPopup"); if(id != null && id.trim().length() > 0) { //System.out.println("MenuPopupHelper.findMenuPopup() menuPopup: " + id); UIComponent menuPopup = CoreComponentUtils.findComponent(id, comp); if(menuPopup == null) { //TODO Suggest potentials throw new IllegalArgumentException( "Could not find the MenuPopup UIComponent referenced by " + "attribute menuPopup=\""+id+"\" in UIComponent of type: " + comp.getClass().getName() + " with id: \""+comp.getId()+"\""); } return menuPopup; } return null; } }
private static Entry lookupByIdOrClientId(UIComponent component, Map messagesMap) { Entry id = (Entry) messagesMap.get(component.getId()); if (id == null) { return (Entry) messagesMap.get(component.getClientId()); } else { return id; } }
private void restoreDescendantState(UIComponent component, FacesContext context) { //force id reset String id = component.getId(); component.setId(id); Map<String, SavedState> saved = (Map<String, SavedState>) getStateHelper().get(PropertyKeys.saved); if (component instanceof EditableValueHolder) { EditableValueHolder input = (EditableValueHolder) component; String clientId = component.getClientId(context); SavedState state = saved.get(clientId); if (state == null) { state = new SavedState(); } input.setValue(state.getValue()); input.setValid(state.isValid()); input.setSubmittedValue(state.getSubmittedValue()); input.setLocalValueSet(state.isLocalValueSet()); } for (UIComponent kid : component.getChildren()) { restoreDescendantState(kid, context); } if (component.getFacetCount() > 0) { for (UIComponent facet : component.getFacets().values()) { restoreDescendantState(facet, context); } } }
private static String getId(UIComponent component) { String id = component.getId(); if (id == null) { // TODO force clientId creation? component.getClientId(); id = component.getId(); } return id; }
private void restoreTransientDescendantComponentStates(FacesContext facesContext, Iterator<UIComponent> childIterator, Map<String, Object> state, boolean restoreChildFacets) { while (childIterator.hasNext()) { UIComponent component = childIterator.next(); // reset the client id (see spec 3.1.6) component.setId(component.getId()); if (!component.isTransient()) { component.restoreTransientState(facesContext, (state == null) ? null : state.get(component.getClientId(facesContext))); Iterator<UIComponent> childsIterator; if (restoreChildFacets) { childsIterator = component.getFacetsAndChildren(); } else { childsIterator = component.getChildren().iterator(); } restoreTransientDescendantComponentStates(facesContext, childsIterator, state, true); } } }
private void decodeUISelectOne(FacesContext context, UIComponent component, String clientId) { Map<String, String> requestParameterMap = context.getExternalContext() .getRequestParameterMap(); if (requestParameterMap.containsKey(clientId)) { String newValue = requestParameterMap.get(clientId); setSubmittedValue(component, newValue); if (logger.isLoggable(FINE)) { logger.fine("submitted value for UISelectOne component " + component.getId() + " after decoding " + newValue); } } else { // there is no value, but this is different from a null value. setSubmittedValue(component, NO_VALUE); } }
private boolean isForRenderedComponent() { UIComponent currentComponent = UIComponent.getCurrentComponent(facesContext); // Typically a single component writes multiple times to the response writer in quick succession. // Shortcut id matching by doing a cheaper check on the outcome of the last processed component. if (lastComponent == currentComponent) { return lastRendered; } lastComponent = currentComponent; // Check if a rendering decision already made for this component by checking the cache if (renderedIdCache.containsKey(currentComponent.getClientId())) { lastRendered = renderedIdCache.get(currentComponent.getClientId()); return lastRendered; } // No decision made, check for an explicit id match lastRendered = componentIds.contains(currentComponent.getId()) || clientIds.contains(currentComponent.getClientId()); if (renderChildren) { checkParents(currentComponent); } return lastRendered; }
protected void restoreDescendantState(UIComponent component, FacesContext context) { String id = component.getId(); String componentClientId = component.getClientId(context); SavedState state = saved.get(componentClientId); if (state == null) { state = new SavedState(); String componentClientId = component.getClientId(context); SavedState state = saved.get(componentClientId); if (state == null) { state = new SavedState(); for (UIComponent kid : component.getChildren()) { restoreDescendantState(kid, context);
public VisitResult visit(VisitContext context, UIComponent target) { if (this.id.equals(target.getId())) { this.clientIds.add(target.getClientId()); } return VisitResult.ACCEPT; } }
for (int i = 0; i < dynamicColumns.size(); i++) { DynamicColumn dynamicColumn = dynamicColumns.get(i); for (UIComponent comp : column.getChildren()) { + dynamicColumn.getId() + seperatorChar + i + seperatorChar + comp.getId(); for (UIComponent cell : column.getChildren()) { clientIds += data.getClientId(context) + seperatorChar + row + seperatorChar + cell.getId();
private void restoreChildState(FacesContext faces, UIComponent c) { String id = c.getId(); c.setId(id); String clientId = c.getClientId(faces); SavedState ss = getChildState().get(clientId); if (ss != null) { ss.restoreState(evh); childId = initialClientId + getSeparatorChar(faces) + childId; if (initialChildState.containsKey(childId)) { SavedState initialState = initialChildState.get(childId); initialState.restoreState(evh); while (itr.hasNext()) { restoreChildState(faces, (UIComponent) itr.next());
private void getClientIds( UIComponent component, Set<String> clientIds ) { for ( Iterator<UIComponent> i = component.getFacetsAndChildren(); i.hasNext(); ) { UIComponent childComponent = i.next(); String id = childComponent.getId(); if ( id != null ) { clientIds.add( id ); } getClientIds( childComponent, clientIds ); } } }
public static String getLabel(UIComponent component) { String label = (String) component.getAttributes().get( JsfConstants.LABEL_ATTR); if (label != null) { return label; } label = LabelUtil.getLabelValue(component.getId()); if (label != null) { return label; } String title = (String) component.getAttributes().get( JsfConstants.TITLE_ATTR); if (title != null) { return title; } return component.getId(); }
static String lookupMessageConfig(UIComponent validatedComponent) { final Map<String, Object> messageMap = getMap(MESSAGE_MAP); final Entry entry = lookupByIdOrClientId(validatedComponent, messageMap); if (entry != null && entry.isInComponentTree()) { return entry.getMessageConfiguration(); } final Entry inViewEntry = (Entry) messageMap.get(IN_VIEW); if (inViewEntry != null && inViewEntry.isInComponentTree()) { final List idsInView = ComponentUtils.findIdsInView(FacesContext.getCurrentInstance()); if (idsInView.contains(validatedComponent.getClientId())) { return inViewEntry.getMessageConfiguration(); } } final Entry allEntry = (Entry) messageMap.get(ALL); if (allEntry != null && allEntry.isInComponentTree()) { return allEntry.getMessageConfiguration(); } throw new FaceletException("Cannot find message/s component assigned to " + validatedComponent.getId()); }
public static void writeIdIfNecessary(ResponseWriter writer, UIComponent component, FacesContext facesContext) throws IOException { if (component.getId() != null && !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) { writer.writeAttribute(HTML.ID_ATTR, component.getClientId(facesContext), null); } }
private UIComponent findComponent(UIComponent parent, String id) { for (UIComponent child : parent.getChildren()) { if (child.getId() != null && child.getId().equals(id)) { return child; } } return null; }