use of com.sun.faces.context.StateContext in project mojarra by eclipse-ee4j.
the class FaceletFullStateManagementStrategy method restoreDynamicRemove.
/**
* 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(FINEST)) {
LOGGER.finest("FaceletFullStateManagementStrategy.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();
if (struct.getFacetName() != null) {
parent.getFacets().remove(struct.getFacetName());
} else {
parent.getChildren().remove(child);
}
}
}
use of com.sun.faces.context.StateContext in project mojarra by eclipse-ee4j.
the class FaceletViewHandlingStrategy method reapplyDynamicAdd.
/**
* Reapply the dynamic add after Facelets reapply.
*
* @param context the Faces context.
* @param struct the component struct.
*/
private void reapplyDynamicAdd(FacesContext context, ComponentStruct struct) {
UIComponent parent = locateComponentByClientId(context, context.getViewRoot(), struct.getParentClientId());
if (parent != null) {
UIComponent child = locateComponentByClientId(context, parent, struct.getClientId());
StateContext stateContext = StateContext.getStateContext(context);
if (child == null) {
child = stateContext.getDynamicComponents().get(struct.getClientId());
}
if (child != null) {
if (struct.getFacetName() != null) {
parent.getFacets().remove(struct.getFacetName());
parent.getFacets().put(struct.getFacetName(), child);
child.getClientId();
} else {
int childIndex = -1;
if (child.getAttributes().containsKey(DYNAMIC_COMPONENT)) {
childIndex = (Integer) child.getAttributes().get(DYNAMIC_COMPONENT);
}
child.setId(struct.getId());
if (childIndex >= parent.getChildCount() || childIndex == -1) {
parent.getChildren().add(child);
} else {
parent.getChildren().add(childIndex, child);
}
child.getClientId();
child.getAttributes().put(DYNAMIC_COMPONENT, child.getParent().getChildren().indexOf(child));
}
stateContext.getDynamicComponents().put(struct.getClientId(), child);
}
}
}
use of com.sun.faces.context.StateContext in project mojarra by eclipse-ee4j.
the class FaceletFullStateManagementStrategy method restoreView.
/**
* Restore the view.
*
* @param context the Faces context.
* @param viewId the view id.
* @param renderKitId the render kit id.
* @return the view root.
*/
@Override
public UIViewRoot restoreView(FacesContext context, String viewId, String renderKitId) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "FaceletFullStateManagementStrategy.restoreView", new Object[] { viewId, renderKitId });
}
UIViewRoot result = null;
ResponseStateManager rsm = RenderKitUtils.getResponseStateManager(context, renderKitId);
Object[] state = (Object[]) rsm.getState(context, viewId);
if (state != null && state.length >= 2) {
/*
* Restore the component tree.
*/
if (state[0] != null) {
result = restoreTree(context, renderKitId, ((Object[]) state[0]).clone());
context.setViewRoot(result);
}
if (result != null) {
StateContext stateContext = StateContext.getStateContext(context);
stateContext.startTrackViewModifications(context, result);
stateContext.setTrackViewModifications(false);
try {
@SuppressWarnings("unchecked") HashMap<String, Object> stateMap = (HashMap<String, Object>) state[1];
if (stateMap != null) {
/*
* Restore the component state.
*/
restoreComponentState(context, stateMap);
/*
* Restore the dynamic actions.
*/
restoreDynamicActions(context, stateContext, stateMap);
}
} finally {
stateContext.setTrackViewModifications(true);
}
}
}
/*
* Make sure the library contracts get setup as well.
*/
ViewHandler viewHandler = context.getApplication().getViewHandler();
ViewDeclarationLanguage vdl = viewHandler.getViewDeclarationLanguage(context, viewId);
context.setResourceLibraryContracts(vdl.calculateResourceLibraryContracts(context, viewId));
return result;
}
use of com.sun.faces.context.StateContext in project mojarra by eclipse-ee4j.
the class FaceletPartialStateManagementStrategy method restoreDynamicRemove.
/**
* 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();
if (struct.getFacetName() != null) {
parent.getFacets().remove(struct.getFacetName());
} else {
parent.getChildren().remove(child);
}
}
}
use of com.sun.faces.context.StateContext in project mojarra by eclipse-ee4j.
the class FaceletPartialStateManagementStrategy method restoreDynamicAdd.
/**
* Method that takes care of restoring a dynamic add.
*
* @param context the Faces context.
* @param state the state.
* @param struct the component struct.
*/
private void restoreDynamicAdd(FacesContext context, Map<String, Object> state, ComponentStruct struct) {
if (LOGGER.isLoggable(FINEST)) {
LOGGER.finest("FaceletPartialStateManagementStrategy.restoreDynamicAdd");
}
UIComponent parent = locateComponentByClientId(context, context.getViewRoot(), struct.getParentClientId());
if (parent != null) {
UIComponent child = locateComponentByClientId(context, parent, struct.getClientId());
/*
* If Facelets engine restored the child before us we are going to use it, but we need to remove it before we can add it
* in the correct place.
*/
if (child != null) {
if (struct.getFacetName() == null) {
parent.getChildren().remove(child);
} else {
parent.getFacets().remove(struct.getFacetName());
}
}
/*
* The child was not build previously, so we are going to check if the component was saved in the state.
*/
if (child == null) {
StateHolderSaver saver = (StateHolderSaver) state.get(struct.getClientId());
if (saver != null) {
child = (UIComponent) saver.restore(context);
}
}
/*
* Are we adding =BACK= in a component that was not in the state, because it was added by the initial buildView and
* removed by another dynamic action?
*/
StateContext stateContext = StateContext.getStateContext(context);
if (child == null) {
child = stateContext.getDynamicComponents().get(struct.getClientId());
}
/*
* Now if we have the child we are going to add it back in.
*/
if (child != null) {
if (struct.getFacetName() != null) {
parent.getFacets().put(struct.getFacetName(), child);
} else {
int childIndex = -1;
if (child.getAttributes().containsKey(DYNAMIC_COMPONENT)) {
childIndex = (Integer) child.getAttributes().get(DYNAMIC_COMPONENT);
}
child.setId(struct.getId());
if (childIndex >= parent.getChildCount() || childIndex == -1) {
parent.getChildren().add(child);
} else {
parent.getChildren().add(childIndex, child);
}
child.getClientId();
}
child.getAttributes().put(DYNAMIC_COMPONENT, child.getParent().getChildren().indexOf(child));
stateContext.getDynamicComponents().put(struct.getClientId(), child);
}
}
}
Aggregations