Search in sources :

Example 1 with ComponentStruct

use of com.sun.faces.util.ComponentStruct in project mojarra by eclipse-ee4j.

the class FaceletFullStateManagementStrategy method restoreDynamicActions.

/**
 * 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(FINEST)) {
        LOGGER.finest("FaceletFullStateManagementStrategy.restoreDynamicActions");
    }
    @SuppressWarnings("unchecked") List<Object> savedActions = (List<Object>) context.getViewRoot().getAttributes().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, state, action);
            }
            if (REMOVE.equals(action.getAction())) {
                restoreDynamicRemove(context, action);
            }
            pruneAndReAddToDynamicActions(actions, action);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ComponentStruct(com.sun.faces.util.ComponentStruct)

Example 2 with ComponentStruct

use of com.sun.faces.util.ComponentStruct in project mojarra by eclipse-ee4j.

the class FaceletPartialStateManagementStrategy method saveDynamicActions.

/**
 * 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, Map<String, Object> stateMap) {
    if (LOGGER.isLoggable(Level.FINEST)) {
        LOGGER.finest("FaceletPartialStateManagementStrategy.saveDynamicActions");
    }
    List<ComponentStruct> actions = stateContext.getDynamicActions();
    HashMap<String, UIComponent> componentMap = stateContext.getDynamicComponents();
    if (actions != null) {
        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());
            }
            if (component != null) {
                savedActions.add(action.saveState(context));
            }
        }
        stateMap.put(DYNAMIC_ACTIONS, savedActions);
    }
}
Also used : UIComponent(jakarta.faces.component.UIComponent) ArrayList(java.util.ArrayList) ComponentStruct(com.sun.faces.util.ComponentStruct)

Example 3 with ComponentStruct

use of com.sun.faces.util.ComponentStruct in project mojarra by eclipse-ee4j.

the class FaceletPartialStateManagementStrategy method restoreDynamicActions.

/**
 * 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);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ComponentStruct(com.sun.faces.util.ComponentStruct)

Example 4 with ComponentStruct

use of com.sun.faces.util.ComponentStruct in project mojarra by eclipse-ee4j.

the class FaceletFullStateManagementStrategy method saveDynamicActions.

/**
 * 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(FINEST)) {
        LOGGER.finest("FaceletFullStateManagementStrategy.saveDynamicActions");
    }
    List<ComponentStruct> actions = stateContext.getDynamicActions();
    HashMap<String, UIComponent> componentMap = stateContext.getDynamicComponents();
    if (actions != null) {
        List<Object> savedActions = new ArrayList<>(actions.size());
        for (ComponentStruct action : actions) {
            UIComponent component = componentMap.get(action.getClientId());
            if (component == null && context.isProjectStage(Development)) {
                LOGGER.log(WARNING, "Unable to save dynamic action with clientId ''{0}'' because the UIComponent cannot be found", action.getClientId());
            }
            if (component != null) {
                savedActions.add(action.saveState(context));
            }
        }
        viewRoot.getAttributes().put(DYNAMIC_ACTIONS, savedActions);
    }
}
Also used : UIComponent(jakarta.faces.component.UIComponent) ArrayList(java.util.ArrayList) ComponentStruct(com.sun.faces.util.ComponentStruct)

Example 5 with ComponentStruct

use of com.sun.faces.util.ComponentStruct in project mojarra by eclipse-ee4j.

the class FaceletViewHandlingStrategy method reapplyDynamicActions.

/**
 * Reapply the dynamic actions after Facelets reapply.
 *
 * <p>
 * Note a precondition to this method is that tracking view modifications is turned off during the execution of this
 * method. The caller of this method is responsible for turning tracking view modifications off and on as required.
 * </p>
 *
 * @param context the Faces context.
 */
private void reapplyDynamicActions(FacesContext context) {
    StateContext stateContext = StateContext.getStateContext(context);
    List<ComponentStruct> actions = stateContext.getDynamicActions();
    if (actions != null) {
        for (ComponentStruct action : actions) {
            if (REMOVE.equals(action.getAction())) {
                reapplyDynamicRemove(context, action);
            }
            if (ADD.equals(action.getAction())) {
                reapplyDynamicAdd(context, action);
            }
        }
    }
}
Also used : StateContext.getStateContext(com.sun.faces.context.StateContext.getStateContext) StateContext(com.sun.faces.context.StateContext) ComponentStruct(com.sun.faces.util.ComponentStruct)

Aggregations

ComponentStruct (com.sun.faces.util.ComponentStruct)5 ArrayList (java.util.ArrayList)4 UIComponent (jakarta.faces.component.UIComponent)2 List (java.util.List)2 StateContext (com.sun.faces.context.StateContext)1 StateContext.getStateContext (com.sun.faces.context.StateContext.getStateContext)1