@SuppressWarnings(value = "unchecked")
public static UIPage findPage(FacesContext context, UIComponent component) {
javax.faces.component.UIViewRoot view = context.getViewRoot();
if (view != null) {
TransientStateHolder stateHolder = (TransientStateHolder) view.getAttributes().get(UIPage.COMPONENT_TYPE);
if (stateHolder == null || stateHolder.isEmpty()) {
UIPage page = findPage(component);
stateHolder = new TransientStateHolder(page);
context.getViewRoot().getAttributes().put(UIPage.COMPONENT_TYPE, stateHolder);
}
return (UIPage) stateHolder.get();
} else {
return findPage(component);
}
}