Author: awiner
Date: Sun Apr 8 21:38:08 2007
New Revision: 526649
URL: http://svn.apache.org/viewvc?view=rev&rev=526649
Log:
ADFFACES-191: Handle alt-f4 in dialogs
- Apply patch from Martin Koci
- Enhanced the dialog framework demo to show the new code working
Added:
incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/demos/cancelledDialog.jspx
Modified:
incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java
incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/demos/launchDialog.jspx
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderKit.java
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/pages/FredJSP.java
Modified:
incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java
URL:
http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java?view=diff&rev=526649&r1=526648&r2=526649
==============================================================================
---
incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java
(original)
+++
incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java
Sun Apr 8 21:38:08 2007
@@ -23,6 +23,7 @@
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
+import org.apache.myfaces.trinidad.component.UIXCommand;
import org.apache.myfaces.trinidad.component.UIXInput;
import org.apache.myfaces.trinidad.context.RequestContext;
import org.apache.myfaces.trinidad.event.ReturnEvent;
@@ -70,6 +71,7 @@
public void returned(ReturnEvent event)
{
+ String dialogViewId;
if (event.getReturnValue() != null)
{
getInput().setSubmittedValue(null);
@@ -77,17 +79,26 @@
RequestContext afContext = RequestContext.getCurrentInstance();
afContext.addPartialTarget(getInput());
-
- FacesContext context = FacesContext.getCurrentInstance();
- UIViewRoot root = context.getApplication().getViewHandler().createView(
- context, "/demos/successDialog.jspx");
- // Launch a new, success dialog with a different width and height;
- // this shows how to do so by queueing a LaunchEvent.
- LaunchEvent launchEvent = new LaunchEvent(event.getComponent(), root);
- launchEvent.getWindowProperties().put("width", "200");
- launchEvent.getWindowProperties().put("height", "100");
- launchEvent.queue();
+ dialogViewId = "/demos/successDialog.jspx";
+ }
+ else
+ {
+ dialogViewId = "/demos/cancelledDialog.jspx";
}
+
+
+ // Launch a new, success dialog with a different width and height;
+ // this shows how to do so by queueing a LaunchEvent.
+ // (Here, we queue it to a dummy UIXCommand just so we don't
+ // get in a fun infinite loop of ReturnEvents!)
+ FacesContext context = FacesContext.getCurrentInstance();
+ UIViewRoot root = context.getApplication().getViewHandler().createView(
+ context, dialogViewId);
+ LaunchEvent launchEvent = new LaunchEvent(getDummyCommand(), root);
+ launchEvent.getWindowProperties().put("width", "200");
+ launchEvent.getWindowProperties().put("height", "100");
+ addParameter(launchEvent);
+ launchEvent.queue();
}
@@ -124,6 +135,18 @@
}
}
+
+ public UIXCommand getDummyCommand()
+ {
+ return _dummyCommand;
+ }
+
+ public void setDummyCommand(UIXCommand dummyCommand)
+ {
+ _dummyCommand = dummyCommand;
+ }
+
private UIXInput _input;
private UIXInput _tableInput;
+ private UIXCommand _dummyCommand;
}
Added:
incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/demos/cancelledDialog.jspx
URL:
http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/demos/cancelledDialog.jspx?view=auto&rev=526649
==============================================================================
---
incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/demos/cancelledDialog.jspx
(added)
+++
incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/demos/cancelledDialog.jspx
Sun Apr 8 21:38:08 2007
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+
+-->
+<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:trh="http://myfaces.apache.org/trinidad/html"
+ xmlns:tr="http://myfaces.apache.org/trinidad" >
+ <jsp:directive.page contentType="text/html;charset=utf-8"/>
+ <f:view>
+ <tr:document title="Cancelled">
+ <tr:form>
+ <tr:panelPage>
+ <tr:panelHeader text="Cancelled">
+ <tr:outputText value="The dialog was cancelled."/>
+ <tr:panelButtonBar>
+ <tr:commandButton text="Done" immediate="true">
+ <tr:returnActionListener/>
+ </tr:commandButton>
+ </tr:panelButtonBar>
+ </tr:panelHeader>
+ </tr:panelPage>
+ </tr:form>
+ </tr:document>
+ </f:view>
+</jsp:root>
Modified:
incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/demos/launchDialog.jspx
URL:
http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/demos/launchDialog.jspx?view=diff&rev=526649&r1=526648&r2=526649
==============================================================================
---
incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/demos/launchDialog.jspx
(original)
+++
incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/demos/launchDialog.jspx
Sun Apr 8 21:38:08 2007
@@ -61,6 +61,9 @@
</tr:panelBorderLayout>
</tr:column>
</tr:table>
+ <!-- A dummy UIXCommand component, used purely for a launch event -->
+ <tr:commandLink inlineStyle="display:none" useWindow="true"
+ binding="#{launchDialog.dummyCommand}"/>
<tr:goLink text="Demo of launching a dialog from <tr:poll>"
destination="launchFromPoll.jspx"/>
</tr:panelHeader>
Modified:
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderKit.java
URL:
http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderKit.java?view=diff&rev=526649&r1=526648&r2=526649
==============================================================================
---
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderKit.java
(original)
+++
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreRenderKit.java
Sun Apr 8 21:38:08 2007
@@ -237,8 +237,10 @@
// with cross frame XmlHttpRequest invocation
Writer out = _getHtmlWriter(context);
out.write("<script>");
- out.write("var callback = 'ADFDialogReturn[" + returnId + "]()';");
- out.write("top.opener.setTimeout(callback, 1);");
+ // http://issues.apache.org/jira/browse/ADFFACES-191 - handling alt-f4
+ // Following code is now called from onunload JS function - see FredJSP
+ // out.write("var callback = 'ADFDialogReturn[" + returnId + "]()';");
+ // out.write("top.opener.setTimeout(callback, 1);");
out.write("top.close()");
out.write("</script>");
out.close();
Modified:
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/pages/FredJSP.java
URL:
http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/pages/FredJSP.java?view=diff&rev=526649&r1=526648&r2=526649
==============================================================================
---
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/pages/FredJSP.java
(original)
+++
incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/pages/FredJSP.java
Sun Apr 8 21:38:08 2007
@@ -165,6 +165,7 @@
// Prepend an extra slash to avoid re-prepending the context path
String redirectString = "/" + vh.getActionURL(context,
viewIdRedirect);
+
// if redirectString contains ?, append queryString with &,
// otherwise append queryString with &
char sep = (redirectString.indexOf('?') != -1) ? '&' : '?';
@@ -200,7 +201,7 @@
// would be good...
// Bug #2464627: Allow support for forcing a minimum size
- StringBuffer onload = new StringBuffer(_FRAMESET_ONLOAD_TEXT.length()
+ StringBuilder onload = new StringBuilder(_FRAMESET_ONLOAD_TEXT.length()
// space for the param plus the 'W:'
+ (gotWidth
? widthParam.length() + 2
@@ -239,7 +240,16 @@
onload.append(")");
frameSet.setOnload(onload.toString());
- frameSet.setOnunload(_FRAMESET_ONUNLOAD_TEXT);
+
+ // http://issues.apache.org/jira/browse/ADFFACES-191
+ // Following code was once in CoreRenderKit.launchDialog.
+ StringBuilder onunload = new StringBuilder(53 + returnId.length());
+ onunload.append(_FRAMESET_ONUNLOAD_TEXT);
+ onunload.append(";window.opener.setTimeout(");
+ onunload.append("'ADFDialogReturn[").append(returnId).append("]();'");
+ onunload.append(",1)");
+ frameSet.setOnunload(onunload.toString());
+
root.getChildren().add(frameSet);
}