Details
-
New Feature
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0.0, 2.0.1
-
None
-
All
-
Patch
Description
Modified the FacesResult class to compare the result uri from the struts result config to the JSF viewId and build a new JSF viewId if they do not match. Processing is then delegated to the render.
I had to split the render() into it's own class because I needed the StrutsResultSupport functionality for parsing the result string to garuantee that the parameter functionality would be available. This will allow the FacesResult to work the same as the other Result classes in respect to how you can define the location to forward to.
Simple Example Configuration:
<result name="success" type="jsf" >
/listBillingActions.jsp
</result>
org.apache.struts2.jsf.FacesRender.java
/*
- $Id: PlainTextResult.java 394468 2006-04-16 12:16:03Z tmjee $
* - Copyright 2006 The Apache Software Foundation.
* - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
* - http://www.apache.org/licenses/LICENSE-2.0
* - Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
*/
package org.apache.struts2.jsf;
import java.io.IOException;
import javax.faces.FacesException;
import javax.faces.application.Application;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
import org.apache.struts2.dispatcher.StrutsResultSupport;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.Result;
/**
- Handles the results navigation and then executes the JSF render phase
*/
public class FacesResult extends StrutsResultSupport implements Result {
private static final long serialVersionUID = -3548970638740937804L;
/**
- Checks to see if we need to build a new JSF ViewId from the Struts Result config and
- then renders the result by delegating to the FacesRender.render().
- @see org.apache.struts2.dispatcher.StrutsResultSupport#doExecute(java.lang.String, com.opensymphony.xwork2.ActionInvocation)
*/
protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { performNavigation(finalLocation, FacesContext.getCurrentInstance()); new FacesRender().render(FacesContext.getCurrentInstance()); }
/**
- Compares the Struts Result uri to the faces viewId.
- If they are different use the Struts uri to build
- a new faces viewId.
- @param finalLocation The result uri
- @param facesContext The FacesContext
*/
private void performNavigation(String finalLocation, FacesContext facesContext) {
String facesViewId = facesContext.getViewRoot().getViewId();
if (finalLocation != null) {
if (finalLocation.equals(facesViewId) == false)
}
}
}
org.apache.struts2.jsf.FacesRender.java
/*
- $Id: PlainTextResult.java 394468 2006-04-16 12:16:03Z tmjee $
* - Copyright 2006 The Apache Software Foundation.
* - Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
* - http://www.apache.org/licenses/LICENSE-2.0
* - Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
*/
package org.apache.struts2.jsf;
import java.io.IOException;
import javax.faces.FacesException;
import javax.faces.application.Application;
import javax.faces.application.ViewHandler;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
/**
- Performs the JSF render lifecycle phase.
*
*/
public class FacesRender extends FacesSupport {
/**
- Executes the render phase, borrowed from MyFaces
- @param facesContext
- The faces context
- @throws FacesException
- If anything goes wrong
*/
public void render(FacesContext facesContext) throws FacesException {
// if the response is complete we should not be invoking the phase
// listeners
if (isResponseComplete(facesContext, "render", true)) { return; }if (log.isTraceEnabled())
log.trace("entering renderResponse");
informPhaseListenersBefore(facesContext, PhaseId.RENDER_RESPONSE);
try {
// also possible that one of the listeners completed the response
if (isResponseComplete(facesContext, "render", true))
Application application = facesContext.getApplication();
ViewHandler viewHandler = application.getViewHandler();
try
catch (IOException e)
{ throw new FacesException(e.getMessage(), e); }} finally
{ informPhaseListenersAfter(facesContext, PhaseId.RENDER_RESPONSE); }if (log.isTraceEnabled())
{ // Note: DebugUtils Logger must also be in trace level // DebugUtils.traceView("View after rendering"); } if (log.isTraceEnabled())
log.trace("exiting renderResponse");
}
}