/** * Restore the list of dynamic actions and replay them. * * @param context the Faces context. * @param stateContext the state context. * @param stateMap the state. * @param viewRoot the view root. */ private void restoreDynamicActions(FacesContext context, StateContext stateContext, Map<String, Object> stateMap) { if (LOGGER.isLoggable(FINEST)) { LOGGER.finest("FaceletPartialStateManagementStrategy.restoreDynamicActions"); } @SuppressWarnings("unchecked") List<Object> savedActions = (List<Object>) stateMap.get(DYNAMIC_ACTIONS); List<ComponentStruct> actions = stateContext.getDynamicActions(); if (!isEmpty(savedActions)) { for (Object savedAction : savedActions) { ComponentStruct action = new ComponentStruct(); action.restoreState(context, savedAction); if (ADD.equals(action.getAction())) { restoreDynamicAdd(context, stateMap, action); } if (REMOVE.equals(action.getAction())) { restoreDynamicRemove(context, action); } pruneAndReAddToDynamicActions(actions, action); } } }
List<Object> savedActions = new ArrayList<>(actions.size()); for (ComponentStruct action : actions) { UIComponent component = componentMap.get(action.getClientId()); if (component == null && context.isProjectStage(ProjectStage.Development)) { LOGGER.log( Level.WARNING, "Unable to save dynamic action with clientId ''{0}'' because the UIComponent cannot be found", action.getClientId()); savedActions.add(action.saveState(context));
if (firstIndex == -1) { actionList.add(struct); componentMap.put(struct.getClientId(), component); } else { int lastIndex = actionList.lastIndexOf(struct); if (lastIndex == firstIndex) { ComponentStruct previousStruct = actionList.get(firstIndex); if (ADD.equals(previousStruct.getAction())) { if (ADD.equals(struct.getAction())) { throw new FacesException("Cannot add the same component twice: " + struct.getClientId()); if (REMOVE.equals(struct.getAction())) { actionList.remove(firstIndex); componentMap.remove(struct.getClientId()); if (REMOVE.equals(previousStruct.getAction())) { if (ADD.equals(struct.getAction())) { actionList.add(struct); componentMap.put(struct.getClientId(), component); if (REMOVE.equals(struct.getAction())) { throw new FacesException("Cannot remove the same component twice: " + struct.getClientId()); if (ADD.equals(struct.getAction())) { throw new FacesException("Cannot add the same component twice: " + struct.getClientId()); if (REMOVE.equals(struct.getAction())) { actionList.remove(lastIndex);
UIComponent parent = locateComponentByClientId(context, context.getViewRoot(), struct.getParentClientId()); UIComponent child = locateComponentByClientId(context, parent, struct.getClientId()); StateContext stateContext = StateContext.getStateContext(context); child = stateContext.getDynamicComponents().get(struct.getClientId()); if (struct.getFacetName() != null) { parent.getFacets().remove(struct.getFacetName()); parent.getFacets().put(struct.getFacetName(), child); child.getClientId(); } else { childIndex = (Integer) child.getAttributes().get(DYNAMIC_COMPONENT); child.setId(struct.getId()); if (childIndex >= parent.getChildCount() || childIndex == -1) { parent.getChildren().add(child); child.getAttributes().put(DYNAMIC_COMPONENT, child.getParent().getChildren().indexOf(child)); stateContext.getDynamicComponents().put(struct.getClientId(), child);
/** * Handle the remove. * * @param context the Faces context. * @param component the UI component to add to the list as a REMOVE. */ @Override protected void handleRemove(FacesContext context, UIComponent component) { if (component.isInView()) { decrementDynamicChildCount(context, component.getParent()); handleAddRemoveWithAutoPrune( component, new ComponentStruct(REMOVE, component.getClientId(context), component.getId()) ); } }
/** * Restore the list of dynamic actions and replay them. * * @param context the Faces context. * @param stateContext the state context. * @param stateMap the state. * @param viewRoot the view root. */ private void restoreDynamicActions(FacesContext context, StateContext stateContext, Map<String, Object> stateMap) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("FaceletPartialStateManagementStrategy.restoreDynamicActions"); } List<Object> savedActions = (List<Object>) stateMap.get(DYNAMIC_ACTIONS); List<ComponentStruct> actions = stateContext.getDynamicActions(); if (savedActions != null && !savedActions.isEmpty()) { for (Object object : savedActions) { ComponentStruct action = new ComponentStruct(); action.restoreState(context, object); if (ComponentStruct.ADD.equals(action.action)) { restoreDynamicAdd(context, stateMap, action); } if (ComponentStruct.REMOVE.equals(action.action)) { restoreDynamicRemove(context, action); } pruneAndReAddToDynamicActions(actions, action); } } }
/** * Method that takes care of restoring a dynamic remove. * * @param context the Faces context. * @param struct the component struct. */ private void restoreDynamicRemove(FacesContext context, ComponentStruct struct) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("FaceletPartialStateManagementStrategy.restoreDynamicRemove"); } UIComponent child = locateComponentByClientId(context, context.getViewRoot(), struct.getClientId()); if (child != null) { StateContext stateContext = StateContext.getStateContext(context); stateContext.getDynamicComponents().put(struct.getClientId(), child); UIComponent parent = child.getParent(); parent.getChildren().remove(child); } }
savedActions.add(action.saveState(context));
UIComponent parent = locateComponentByClientId(context, context.getViewRoot(), struct.getParentClientId()); UIComponent child = locateComponentByClientId(context, parent, struct.getClientId()); StateContext stateContext = StateContext.getStateContext(context); child = stateContext.getDynamicComponents().get(struct.getClientId()); if (struct.getFacetName() != null) { parent.getFacets().remove(struct.getFacetName()); parent.getFacets().put(struct.getFacetName(), child); child.getClientId(); } else { childIndex = (Integer) child.getAttributes().get(DYNAMIC_COMPONENT); child.setId(struct.getId()); if (childIndex >= parent.getChildCount() || childIndex == -1) { parent.getChildren().add(child); child.getAttributes().put(DYNAMIC_COMPONENT, child.getParent().getChildren().indexOf(child)); stateContext.getDynamicComponents().put(struct.getClientId(), child);
/** * Handle the remove. * * @param context the Faces context. * @param component the UI component to add to the list as a REMOVE. */ @Override protected void handleRemove(FacesContext context, UIComponent component) { if (component.isInView()) { decrementDynamicChildCount(context, component.getParent()); handleAddRemoveWithAutoPrune( component, new ComponentStruct(REMOVE, component.getClientId(context), component.getId()) ); } }
/** * Restore the list of dynamic actions and replay them. * * @param context the Faces context. * @param stateContext the state context. * @param stateMap the state. * @param viewRoot the view root. */ private void restoreDynamicActions(FacesContext context, StateContext stateContext, HashMap<String, Object> state) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("FaceletFullStateManagementStrategy.restoreDynamicActions"); } UIViewRoot viewRoot = context.getViewRoot(); List<Object> savedActions = (List<Object>) viewRoot.getAttributes().get(DYNAMIC_ACTIONS); List<ComponentStruct> actions = stateContext.getDynamicActions(); if (savedActions != null && !savedActions.isEmpty()) { for (Object object : savedActions) { ComponentStruct action = new ComponentStruct(); action.restoreState(context, object); if (ComponentStruct.ADD.equals(action.action)) { restoreDynamicAdd(context, state, action); } if (ComponentStruct.REMOVE.equals(action.action)) { restoreDynamicRemove(context, action); } pruneAndReAddToDynamicActions(actions, action); } } }
if (firstIndex == -1) { actionList.add(struct); componentMap.put(struct.getClientId(), component); } else { int lastIndex = actionList.lastIndexOf(struct); if (lastIndex == firstIndex) { ComponentStruct previousStruct = actionList.get(firstIndex); if (ADD.equals(previousStruct.getAction())) { if (ADD.equals(struct.getAction())) { throw new FacesException("Cannot add the same component twice: " + struct.getClientId()); if (REMOVE.equals(struct.getAction())) { actionList.remove(firstIndex); componentMap.remove(struct.getClientId()); if (REMOVE.equals(previousStruct.getAction())) { if (ADD.equals(struct.getAction())) { actionList.add(struct); componentMap.put(struct.getClientId(), component); if (REMOVE.equals(struct.getAction())) { throw new FacesException("Cannot remove the same component twice: " + struct.getClientId()); if (ADD.equals(struct.getAction())) { throw new FacesException("Cannot add the same component twice: " + struct.getClientId()); if (REMOVE.equals(struct.getAction())) { actionList.remove(lastIndex);
/** * Method that takes care of restoring a dynamic remove. * * @param context the Faces context. * @param struct the component struct. */ private void restoreDynamicRemove(FacesContext context, ComponentStruct struct) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("FaceletPartialStateManagementStrategy.restoreDynamicRemove"); } UIComponent child = locateComponentByClientId(context, context.getViewRoot(), struct.getClientId()); if (child != null) { StateContext stateContext = StateContext.getStateContext(context); stateContext.getDynamicComponents().put(struct.getClientId(), child); UIComponent parent = child.getParent(); parent.getChildren().remove(child); } }
/** * Save the dynamic actions. * * @param context the Faces context. * @param stateContext the state context. * @param stateMap the state. */ private void saveDynamicActions(FacesContext context, StateContext stateContext, UIViewRoot viewRoot) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("FaceletFullStateManagementStrategy.saveDynamicActions"); } List<ComponentStruct> actions = stateContext.getDynamicActions(); HashMap<String, UIComponent> componentMap = stateContext.getDynamicComponents(); if (actions != null) { List<Object> savedActions = new ArrayList<Object>(actions.size()); for (ComponentStruct action : actions) { UIComponent component = componentMap.get(action.clientId); if (component == null && context.isProjectStage(ProjectStage.Development)) { LOGGER.log( Level.WARNING, "Unable to save dynamic action with clientId ''{0}'' because the UIComponent cannot be found", action.clientId); } if (component != null) { savedActions.add(action.saveState(context)); } } viewRoot.getAttributes().put(DYNAMIC_ACTIONS, savedActions); } }
UIComponent parent = locateComponentByClientId(context, context.getViewRoot(), struct.getParentClientId()); UIComponent child = locateComponentByClientId(context, parent, struct.getClientId()); if (struct.getFacetName() == null) { parent.getChildren().remove(child); } else { parent.getFacets().remove(struct.getFacetName()); StateHolderSaver saver = (StateHolderSaver) state.get(struct.getClientId()); if (saver != null) { child = (UIComponent) saver.restore(context); child = stateContext.getDynamicComponents().get(struct.getClientId()); if (struct.getFacetName() != null) { parent.getFacets().put(struct.getFacetName(), child); } else { int childIndex = -1; childIndex = (Integer) child.getAttributes().get(DYNAMIC_COMPONENT); child.setId(struct.getId()); if (childIndex >= parent.getChildCount() || childIndex == -1) { parent.getChildren().add(child); stateContext.getDynamicComponents().put(struct.getClientId(), child);
/** * Restore the list of dynamic actions and replay them. * * @param context the Faces context. * @param stateContext the state context. * @param stateMap the state. * @param viewRoot the view root. */ private void restoreDynamicActions(FacesContext context, StateContext stateContext, Map<String, Object> stateMap) { if (LOGGER.isLoggable(FINEST)) { LOGGER.finest("FaceletPartialStateManagementStrategy.restoreDynamicActions"); } @SuppressWarnings("unchecked") List<Object> savedActions = (List<Object>) stateMap.get(DYNAMIC_ACTIONS); List<ComponentStruct> actions = stateContext.getDynamicActions(); if (!isEmpty(savedActions)) { for (Object savedAction : savedActions) { ComponentStruct action = new ComponentStruct(); action.restoreState(context, savedAction); if (ADD.equals(action.getAction())) { restoreDynamicAdd(context, stateMap, action); } if (REMOVE.equals(action.getAction())) { restoreDynamicRemove(context, action); } pruneAndReAddToDynamicActions(actions, action); } } }
List<Object> savedActions = new ArrayList<>(actions.size()); for (ComponentStruct action : actions) { UIComponent component = componentMap.get(action.getClientId()); if (component == null && context.isProjectStage(ProjectStage.Development)) { LOGGER.log( Level.WARNING, "Unable to save dynamic action with clientId ''{0}'' because the UIComponent cannot be found", action.getClientId()); savedActions.add(action.saveState(context));
/** * Handle the remove. * * @param context the Faces context. * @param component the UI component to add to the list as a REMOVE. */ @Override protected void handleRemove(FacesContext context, UIComponent component) { if (component.isInView()) { decrementDynamicChildCount(context, component.getParent()); handleAddRemoveWithAutoPrune( component, new ComponentStruct(REMOVE, component.getClientId(context), component.getId()) ); } }