use of javax.portlet.faces.BridgeURLFactory in project liferay-faces-bridge-impl by liferay.
the class FormRendererPrimeFacesImpl method encodeBegin.
@Override
public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
// "javax.faces.encodedURL" hidden field.
if ((majorVersion == 3) && (minorVersion < 3) && isMultiPartForm(uiComponent)) {
boolean hasPrimeFacesAjaxFileUploadChild = false;
UIComponent childComponent = getChildWithRendererType(uiComponent, RenderKitBridgeImpl.PRIMEFACES_FILE_UPLOAD_RENDERER_TYPE);
if (childComponent != null) {
if (!isSimpleMode(uiComponent)) {
hasPrimeFacesAjaxFileUploadChild = true;
facesContext.getAttributes().put(AJAX_FILE_UPLOAD, Boolean.TRUE);
}
}
// Continue encoding with the wrapped FormRenderer. When it comes time to call
// ExternalContext.encodeActionURL(String), the bridge will check for the
// PrimeFacesFileUpload.AJAX_FILE_UPLOAD attribute. If found, then it will return a PartialActionURL
// suitable for Ajax requests.
super.encodeBegin(facesContext, uiComponent);
if (hasPrimeFacesAjaxFileUploadChild) {
facesContext.getAttributes().remove(AJAX_FILE_UPLOAD);
}
} else // the ACTION_PHASE of the portlet lifecycle.
if (hasNonAjaxActionListener(uiComponent)) {
ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
String viewId = facesContext.getViewRoot().getViewId();
String facesActionURL = viewHandler.getActionURL(facesContext, viewId);
ExternalContext externalContext = facesContext.getExternalContext();
PortletContext portletContext = (PortletContext) externalContext.getContext();
BridgeURLFactory bridgeURLFactory = (BridgeURLFactory) BridgeFactoryFinder.getFactory(portletContext, BridgeURLFactory.class);
try {
BridgeURL partialActionURL = bridgeURLFactory.getBridgePartialActionURL(facesContext, facesActionURL);
partialActionURL.removeParameter(Bridge.FACES_AJAX_PARAMETER);
partialActionURL.setParameter(BridgeExt.FACES_EXPORT_COMPONENT_PARAMETER, "true");
String nonAjaxPartialActionURL = partialActionURL.toString();
ResponseWriter responseWriter = facesContext.getResponseWriter();
ResponseWriter primeFacesResponseWriter = new ResponseWriterPrimeFacesBodyImpl(responseWriter, nonAjaxPartialActionURL);
facesContext.setResponseWriter(primeFacesResponseWriter);
super.encodeBegin(facesContext, uiComponent);
facesContext.setResponseWriter(responseWriter);
} catch (BridgeException e) {
logger.error(e);
}
} else // Otherwise, delegate encoding to the wrapped renderer.
{
super.encodeBegin(facesContext, uiComponent);
}
}
use of javax.portlet.faces.BridgeURLFactory in project liferay-faces-bridge-impl by liferay.
the class BridgeNavigationHandlerImpl method handleNavigation.
@Override
public void handleNavigation(FacesContext facesContext, String fromAction, String outcome) {
logger.debug("fromAction=[{0}] outcome=[{1}]", fromAction, outcome);
String queryString = null;
UIViewRoot uiViewRoot = facesContext.getViewRoot();
String viewId = uiViewRoot.getViewId();
if (viewId != null) {
int pos = viewId.indexOf("?");
if (pos > 0) {
queryString = viewId.substring(pos);
viewId = viewId.substring(0, pos);
uiViewRoot.setViewId(viewId);
}
}
NavigationCase navigationCase = getNavigationCase(facesContext, fromAction, outcome);
// Ask the wrapped NavigationHandler to perform the navigation.
getWrappedNavigationHandler().handleNavigation(facesContext, fromAction, outcome);
if (queryString != null) {
uiViewRoot.setViewId(viewId.concat(queryString));
}
if (navigationCase != null) {
// Hack for http://jira.icesoft.org/browse/ICE-7996
Iterator<FacesMessage> itr = facesContext.getMessages();
while (itr.hasNext()) {
FacesMessage facesMessage = itr.next();
if (facesMessage.getDetail().contains("Unable to find matching navigation case")) {
logger.warn("Removed bogus FacesMessage caused by http://jira.icesoft.org/browse/ICE-7996");
itr.remove();
}
}
// ExternalContext.redirect(String) directly from their application.
if (!navigationCase.isRedirect()) {
String toViewId = navigationCase.getToViewId(facesContext);
if (toViewId != null) {
ExternalContext externalContext = facesContext.getExternalContext();
PortletResponse portletResponse = (PortletResponse) externalContext.getResponse();
if (portletResponse instanceof StateAwareResponse) {
PortletContext portletContext = (PortletContext) externalContext.getContext();
BridgeURLFactory bridgeURLFactory = (BridgeURLFactory) BridgeFactoryFinder.getFactory(portletContext, BridgeURLFactory.class);
try {
BridgeURL bridgeActionURL = bridgeURLFactory.getBridgeActionURL(facesContext, toViewId);
BridgeNavigationCase bridgeNavigationCase = new BridgeNavigationCaseImpl(navigationCase);
String portletMode = bridgeNavigationCase.getPortletMode();
if (portletMode != null) {
bridgeActionURL.setParameter(Bridge.PORTLET_MODE_PARAMETER, portletMode);
}
String windowState = bridgeNavigationCase.getWindowState();
if (windowState != null) {
bridgeActionURL.setParameter(Bridge.PORTLET_WINDOWSTATE_PARAMETER, windowState);
}
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
BridgeNavigationUtil.navigate(portletRequest, (StateAwareResponse) portletResponse, bridgeActionURL.getParameterMap());
} catch (Exception e) {
logger.error(e.getMessage());
}
}
}
}
}
}
Aggregations