use of javax.portlet.faces.BridgeConfig in project liferay-faces-bridge-impl by liferay.
the class BridgeImpl method doFacesRequest.
@Override
public void doFacesRequest(ActionRequest actionRequest, ActionResponse actionResponse) throws BridgeDefaultViewNotSpecifiedException, BridgeUninitializedException, BridgeException {
checkNull(actionRequest, actionResponse);
if (initialized) {
String nonFacesTargetPath = actionRequest.getParameter(Bridge.NONFACES_TARGET_PATH_PARAMETER);
if (nonFacesTargetPath != null) {
throw new BridgeNotAFacesRequestException(nonFacesTargetPath);
}
PortletConfig wrappedPortletConfig = BridgePortletConfigFactory.getPortletConfigInstance(portletConfig);
BridgeConfig bridgeConfig = BridgeConfigFactory.getBridgeConfigInstance(wrappedPortletConfig);
BridgePhase bridgePhase = new BridgePhaseActionImpl(actionRequest, actionResponse, wrappedPortletConfig, bridgeConfig);
bridgePhase.execute();
} else {
throw new BridgeUninitializedException();
}
}
use of javax.portlet.faces.BridgeConfig in project liferay-faces-bridge-impl by liferay.
the class IPCPhaseListener method processIncomingPublicRenderParameters.
/**
* This method processes the "incoming" Public Render Parameters in accordance with Section 5.3.2 of the Spec.
*/
public void processIncomingPublicRenderParameters(FacesContext facesContext) {
try {
// since this phase listener is being executed within the portlet lifecycle.
if (facesContext != null) {
// Section 5.3.2 requires the phase listener to inject the public render parameters into the
// Model concern of the MVC design pattern (as in JSF model managed-beans) after RESTORE_VIEW
// phase completes. This is accomplished below by evaluating the EL expressions found in the
// <model-el>...</model-el> section of the WEB-INF/faces-config.xml file.
ExternalContext externalContext = facesContext.getExternalContext();
PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();
BridgeConfig bridgeConfig = RequestMapUtil.getBridgeConfig(portletRequest);
Map<String, String[]> publicParameterMappings = bridgeConfig.getPublicParameterMappings();
if (publicParameterMappings != null) {
boolean invokeHandler = false;
PortletConfig portletConfig = RequestMapUtil.getPortletConfig(portletRequest);
String portletName = portletConfig.getPortletName();
Map<String, String[]> publicParameterMap = portletRequest.getPublicParameterMap();
Set<String> publicRenderParameterNames = publicParameterMappings.keySet();
// For each of the public render parameters found in the WEB-INF/faces-config.xml file:
for (String prefixedParameterName : publicRenderParameterNames) {
String[] modelExpressions = publicParameterMappings.get(prefixedParameterName);
if (modelExpressions != null) {
String parameterPrefix;
String nonPrefixedParameterName;
int colonPos = prefixedParameterName.indexOf(":");
if (colonPos > 0) {
parameterPrefix = prefixedParameterName.substring(0, colonPos);
nonPrefixedParameterName = prefixedParameterName.substring(colonPos + 1);
} else {
parameterPrefix = null;
nonPrefixedParameterName = prefixedParameterName;
}
if (publicParameterMap.containsKey(nonPrefixedParameterName)) {
for (String originalModelEL : modelExpressions) {
String[] parameterValues = publicParameterMap.get(nonPrefixedParameterName);
String parameterValue = null;
if ((parameterValues != null) && (parameterValues.length > 0)) {
parameterValue = parameterValues[0];
}
PublicRenderParameter publicRenderParameter = new PublicRenderParameterImpl(parameterPrefix, parameterValue, originalModelEL, portletName);
if (logger.isTraceEnabled()) {
logger.trace("portletName=[{0}] public render parameter=[{1}] originalModelEL=[{2}] modifiedModelEL=[{3}] isForThisPortlet=[{4}]", portletName, nonPrefixedParameterName, originalModelEL, publicRenderParameter.getModifiedModelEL(), publicRenderParameter.isForThisPortlet());
}
if (publicRenderParameter.isForThisPortlet()) {
logger.debug("Injecting render parameter=[{0}] value=[{1}] into expression=[{2}]", nonPrefixedParameterName, parameterValue, publicRenderParameter.getModifiedModelEL());
invokeHandler = publicRenderParameter.injectIntoModel(facesContext);
} else {
logger.debug("NOT injecting render parameter=[{0}] value=[{1}] into expression=[{2}] because it is NOT for this portletName=[{3}]", nonPrefixedParameterName, parameterValue, publicRenderParameter.getModifiedModelEL(), portletName);
}
}
} else {
logger.debug("NOT injecting render parameter=[{0}] because it is not found in the public parameter map", nonPrefixedParameterName);
}
}
}
// processing that might be necessary.
if (invokeHandler) {
String bridgePublicRenderParameterHandlerAttributeName = Bridge.BRIDGE_PACKAGE_PREFIX + portletName + "." + Bridge.BRIDGE_PUBLIC_RENDER_PARAMETER_HANDLER;
logger.trace("bridgePublicRenderParameterHandlerAttributeName=[{0}]", bridgePublicRenderParameterHandlerAttributeName);
BridgePublicRenderParameterHandler bridgePublicRenderParameterHandler = (BridgePublicRenderParameterHandler) externalContext.getApplicationMap().get(bridgePublicRenderParameterHandlerAttributeName);
if (bridgePublicRenderParameterHandler == null) {
bridgePublicRenderParameterHandler = BridgePublicRenderParameterHandlerFactory.getBridgePublicRenderParameterHandlerInstance(portletConfig);
}
if (bridgePublicRenderParameterHandler != null) {
logger.debug("Invoking {0} for class=[{1}]", bridgePublicRenderParameterHandler, bridgePublicRenderParameterHandler.getClass());
bridgePublicRenderParameterHandler.processUpdates(facesContext);
}
}
}
}
} catch (Exception e) {
// There's no point in throwing a RuntimeException of any kind like FacesException because the Faces
// runtime will swallow it. So the best we can do is log the exception.
logger.error(e);
}
}
use of javax.portlet.faces.BridgeConfig in project liferay-faces-bridge-impl by liferay.
the class BridgeConfigFactoryImpl method getBridgeConfig.
@Override
public BridgeConfig getBridgeConfig(PortletConfig portletConfig) {
PortletContext portletContext = portletConfig.getPortletContext();
BridgeConfig bridgeConfig = (BridgeConfig) portletContext.getAttribute(BridgeConfigFactoryImpl.class.getName());
if (bridgeConfig == null) {
bridgeConfig = new BridgeConfigImpl(portletConfig);
portletContext.setAttribute(BridgeConfigFactoryImpl.class.getName(), bridgeConfig);
}
return bridgeConfig;
}
use of javax.portlet.faces.BridgeConfig in project liferay-faces-bridge-ext by liferay.
the class BridgeRedirectURLLiferayImpl method toString.
@Override
public String toString() {
FacesContext facesContext = FacesContext.getCurrentInstance();
if (BridgeUtil.getPortletRequestPhase(facesContext) == Bridge.PortletPhase.ACTION_PHASE) {
ExternalContext externalContext = facesContext.getExternalContext();
Map<String, Object> requestMap = externalContext.getRequestMap();
BridgeConfig bridgeConfig = (BridgeConfig) requestMap.get(BridgeConfig.class.getName());
PortletResponse portletResponse = (PortletResponse) externalContext.getResponse();
LiferayPortletResponse liferayPortletResponse = new LiferayPortletResponse(portletResponse);
PortletURL renderURL = liferayPortletResponse.createRenderURL();
renderURL.setParameter(bridgeConfig.getViewIdRenderParameterName(), wrappedBridgeRedirectURL.getViewId());
Map<String, String[]> parameterMap = getParameterMap();
Set<Map.Entry<String, String[]>> entrySet = parameterMap.entrySet();
for (Map.Entry<String, String[]> mapEntry : entrySet) {
String parameterName = mapEntry.getKey();
String[] parameterValues = mapEntry.getValue();
renderURL.setParameter(parameterName, parameterValues);
}
return renderURL.toString();
} else {
return wrappedBridgeRedirectURL.toString();
}
}
Aggregations