Author: craigmcc
Date: Fri Nov 17 20:35:21 2006
New Revision: 476437
URL: http://svn.apache.org/viewvc?view=rev&rev=476437
Log:
Make it possible to navigate via redirects in the shale-dialog-basic
implementation. Because we could no longer rely on passing the dialog id
via the JSF saved state, it is passed (transparently) as a request parameter
in this scenario.
Thanks to Sean Schofield for the suggestion (SHALE-337).
Modified:
shale/framework/trunk/shale-apps/shale-test-dialog-basic/ (props changed)
shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/webapp/WEB-INF/dialog-config.xml
shale/framework/trunk/shale-dialog/ (props changed)
shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/BasicDialogContext.java
shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/config/ViewStateImpl.java
shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/model/ViewState.java
shale/framework/trunk/shale-dialog-basic/src/main/resources/org/apache/shale/dialog/dialog-config_1_1.dtd
shale/framework/trunk/shale-dialog-scxml/ (props changed)
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/Constants.java
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/faces/DialogPhaseListener.java
Propchange: shale/framework/trunk/shale-apps/shale-test-dialog-basic/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Nov 17 20:35:21 2006
@@ -0,0 +1 @@
+target
Modified: shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/webapp/WEB-INF/dialog-config.xml
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/webapp/WEB-INF/dialog-config.xml?view=diff&rev=476437&r1=476436&r2=476437
==============================================================================
--- shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/webapp/WEB-INF/dialog-config.xml
(original)
+++ shale/framework/trunk/shale-apps/shale-test-dialog-basic/src/main/webapp/WEB-INF/dialog-config.xml
Fri Nov 17 20:35:21 2006
@@ -56,6 +56,7 @@
</view>
<view name="page2"
+ redirect="true"
viewId="/wizardpage2.jsp">
<transition outcome="cancelled"
target="cancelled"/>
@@ -70,6 +71,7 @@
</view>
<view name="page3"
+ redirect="true"
viewId="/wizardpage3.jsp">
<transition outcome="cancelled"
target="cancelled"/>
Propchange: shale/framework/trunk/shale-dialog/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Nov 17 20:35:21 2006
@@ -0,0 +1 @@
+target
Modified: shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/BasicDialogContext.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/BasicDialogContext.java?view=diff&rev=476437&r1=476436&r2=476437
==============================================================================
--- shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/BasicDialogContext.java
(original)
+++ shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/BasicDialogContext.java
Fri Nov 17 20:35:21 2006
@@ -17,16 +17,20 @@
package org.apache.shale.dialog.basic;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import javax.faces.FacesException;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.el.MethodBinding;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.shale.dialog.Constants;
import org.apache.shale.dialog.DialogContext;
import org.apache.shale.dialog.DialogContextManager;
@@ -275,6 +279,7 @@
transition(position, outcome);
State state = position.getState();
String viewId = null;
+ boolean redirect = false;
// Advance through states until we again encounter the
// need to render a view state
@@ -305,6 +310,7 @@
stop(context);
}
viewId = ((EndState) state).getViewId();
+ redirect = ((EndState) state).isRedirect();
break;
} else if (state instanceof SubdialogState) {
SubdialogState sstate = (SubdialogState) state;
@@ -323,9 +329,12 @@
continue;
} else if (state instanceof ViewState) {
viewId = ((ViewState) state).getViewId();
+ redirect = ((ViewState) state).isRedirect();
if (log().isTraceEnabled()) {
log().trace("-->ViewState(viewId="
- + ((ViewState) state).getViewId() + ")");
+ + ((ViewState) state).getViewId()
+ + ",redirect=" + ((ViewState) state).isRedirect()
+ + ")");
}
break;
} else {
@@ -344,10 +353,27 @@
log().trace("-->Navigate(viewId=" + viewId + ")");
}
ViewHandler vh = context.getApplication().getViewHandler();
- UIViewRoot view = vh.createView(context, viewId);
- view.setViewId(viewId);
- context.setViewRoot(view);
- context.renderResponse();
+ if (redirect) {
+ String actionURL = vh.getActionURL(context, viewId);
+ if (actionURL.indexOf('?') < 0) {
+ actionURL += '?';
+ } else {
+ actionURL += '&';
+ }
+ actionURL += Constants.DIALOG_ID + "=" + this.id;
+ try {
+ ExternalContext econtext = context.getExternalContext();
+ econtext.redirect(econtext.encodeActionURL(actionURL));
+ context.responseComplete();
+ } catch (IOException e) {
+ throw new FacesException("Cannot redirect to " + actionURL, e);
+ }
+ } else {
+ UIViewRoot view = vh.createView(context, viewId);
+ view.setViewId(viewId);
+ context.setViewRoot(view);
+ context.renderResponse();
+ }
}
Modified: shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/config/ViewStateImpl.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/config/ViewStateImpl.java?view=diff&rev=476437&r1=476436&r2=476437
==============================================================================
--- shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/config/ViewStateImpl.java
(original)
+++ shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/config/ViewStateImpl.java
Fri Nov 17 20:35:21 2006
@@ -33,6 +33,13 @@
/**
+ * <p>Flag indicating that the transition to this view should be done
+ * with a redirect.</p>
+ */
+ private boolean redirect = false;
+
+
+ /**
* <p>The view identifier of the JavaServer Faces view to render if this
* state is entered.</p>
*/
@@ -45,6 +52,16 @@
/**
* {@inheritDoc}
*/
+ public boolean isRedirect() {
+
+ return this.redirect;
+
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
public String getViewId() {
return this.viewId;
@@ -65,12 +82,25 @@
return "ViewState[dialog=" +
((getDialog() != null) ? getDialog().getName() : "<null>") +
",name=" + getName() +
+ ",redirect=" + this.redirect +
",viewId=" + this.viewId + "]";
}
// --------------------------------------------------- Configuration Methods
+
+
+ /**
+ * <p>Set the redirect flag for this state.</p>
+ *
+ * @param redirect The new redirect flag
+ */
+ public void setRedirect(boolean redirect) {
+
+ this.redirect = redirect;
+
+ }
/**
Modified: shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/model/ViewState.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/model/ViewState.java?view=diff&rev=476437&r1=476436&r2=476437
==============================================================================
--- shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/model/ViewState.java
(original)
+++ shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/model/ViewState.java
Fri Nov 17 20:35:21 2006
@@ -34,6 +34,13 @@
/**
+ * <p>Return <code>true</code> if the transition to this view should
+ * be done with a redirect, instead of the normal view creation process.</p>
+ */
+ public boolean isRedirect();
+
+
+ /**
* <p>Return the view identifier of the JavaServer Faces view to render
* if this state is entered.</p>
*
Modified: shale/framework/trunk/shale-dialog-basic/src/main/resources/org/apache/shale/dialog/dialog-config_1_1.dtd
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-basic/src/main/resources/org/apache/shale/dialog/dialog-config_1_1.dtd?view=diff&rev=476437&r1=476436&r2=476437
==============================================================================
--- shale/framework/trunk/shale-dialog-basic/src/main/resources/org/apache/shale/dialog/dialog-config_1_1.dtd
(original)
+++ shale/framework/trunk/shale-dialog-basic/src/main/resources/org/apache/shale/dialog/dialog-config_1_1.dtd
Fri Nov 17 20:35:21 2006
@@ -125,6 +125,10 @@
name Name of this state (must be unique among
all states defined for this dialog).
+ redirect Flag indicating that the transition to this
+ view should be done with a redirect, rather
+ than by calling ViewHandler.createView().
+
viewId View identifier of the JavaServer Faces view
that should be rendered. The logical outcome
returned by whatever action handles the
@@ -135,6 +139,7 @@
<!ELEMENT view (property|transition*)>
<!ATTLIST view className CDATA #IMPLIED>
<!ATTLIST view name CDATA #REQUIRED>
+<!ATTLIST view redirect CDATA #IMPLIED>
<!ATTLIST view viewId CDATA #REQUIRED>
@@ -150,6 +155,10 @@
name Name of this state (must be unique among
all states defined for this dialog).
+ redirect Flag indicating that the transition to this
+ view should be done with a redirect, rather
+ than by calling ViewHandler.createView().
+
viewId View identifier of the JavaServer Faces view
that should be rendered (if any). The logical
outcome returned by whatever action handles the
@@ -160,6 +169,7 @@
<!ELEMENT end (property|transition*)>
<!ATTLIST end className CDATA #IMPLIED>
<!ATTLIST end name CDATA #REQUIRED>
+<!ATTLIST end redirect CDATA #IMPLIED>
<!ATTLIST end viewId CDATA #IMPLIED>
Propchange: shale/framework/trunk/shale-dialog-scxml/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Nov 17 20:35:21 2006
@@ -0,0 +1 @@
+target
Modified: shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/Constants.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/Constants.java?view=diff&rev=476437&r1=476436&r2=476437
==============================================================================
--- shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/Constants.java
(original)
+++ shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/Constants.java
Fri Nov 17 20:35:21 2006
@@ -44,6 +44,17 @@
/**
+ * <p>Request parameter containing the dialog identifier of an
+ * existing {@link DialogContext} instance to be restored for
+ * the current view. Normally, this identifier will be passed
+ * implicitly as part of the JSF view state, but must be passed
+ * explicitly if navigation to a view is performed by a redirect.</p>
+ */
+ public static final String DIALOG_ID =
+ "org.apache.shale.dialog.DIALOG_ID";
+
+
+ /**
* <p>Request parameter containing the logical name of a new
* {@link DialogContext} instance to be created for the current view, if
* there is no active instance already. If the request parameter
Modified: shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/faces/DialogPhaseListener.java
URL: http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/faces/DialogPhaseListener.java?view=diff&rev=476437&r1=476436&r2=476437
==============================================================================
--- shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/faces/DialogPhaseListener.java
(original)
+++ shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/faces/DialogPhaseListener.java
Fri Nov 17 20:35:21 2006
@@ -171,9 +171,16 @@
private void afterRestoreView(FacesContext context) {
// If this view has a currently active dialog context instance,
- // make it visible in request scope and return
+ // make it visible in request scope and return. Normally, the
+ // instance identifier is passed as part of the JSF view state,
+ // but it might also have been passed as a request parameter in
+ // the case of a redirect
String id = (String)
context.getViewRoot().getAttributes().get(Constants.CONTEXT_ID_ATTR);
+ if (id == null) {
+ id = (String) context.getExternalContext().getRequestParameterMap().
+ get(Constants.DIALOG_ID);
+ }
if (id != null) {
restore(context, id);
return;
|