alpheratz
Feb 21st, 2007, 05:37 AM
There are a lot of questions around regarding popup windows.
I thought I'd explain how *I* do it...give something back into the
community at last!
Maybe I'll learn a better way, as well...
The Flow:
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-1.0.xsd">
<start-state idref="mainView" />
<view-state id="mainView" view="mainView">
<transition on="popup" to="popupSubflow" />
</view-state>
<subflow-state id="popupSubflow" flow="popupInlineFlow">
<transition on="*" to="popupEnder" />
</subflow-state>
<view-state id="popupEnder" view="popupEnder" />
<inline-flow id="popupInlineFlow">
<flow>
<start-state idref="v1" />
<view-state id="v1" view="v1">
<transition on="end" to="end" />
</view-state>
<end-state id="end" />
</flow>
</inline-flow>
</flow>
To spawn a popup, mainView.jsp looks like:
...
<input type="button" value="Scripting"
onclick="openPopup('<%= request.getContextPath() %>/tce.spring?_flowExecutionKey=${flowExecutionKey}&_eventId=popup', 'Popup', 640, 480);" />
...
openPopup() is a simple Javascript function:
function openPopup(url, name, width, height)
{
window.open(url, name, "width=" + width + ",height=" + height +
",status=no,toolbar=no,menubar=no,location=no");
}
v1.jsp contains:
<input type="submit" name="_eventId_end" value="End" />
popupEnder.jsp is:
<%@ page language="java" session="false" isErrorPage="false" pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>No-one should see this!</title>
<script type="text/javascript" language="Javascript1.5">
function doOnload()
{
window.opener.document.location = window.opener.document.location;
window.close();
}
</script>
</head>
<body onload="doOnload();">
<p>
Window is closing...
</p>
</body>
</html>
Note that popupEnder.jsp causes a refresh of the opener...allows the
popup window to make a change to the underlying model(s) and have those
changes shown in the opener page at the end of the flow.
Note also that popupEnder has to be invoked from the main flow, not the
subflow...a little inconvenient, but workable.
(As an aside, why is this the case? The doco is clear on this, but the
reason...?)
Hope this helps someone out there!
Cheers,
Alph
I thought I'd explain how *I* do it...give something back into the
community at last!
Maybe I'll learn a better way, as well...
The Flow:
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-1.0.xsd">
<start-state idref="mainView" />
<view-state id="mainView" view="mainView">
<transition on="popup" to="popupSubflow" />
</view-state>
<subflow-state id="popupSubflow" flow="popupInlineFlow">
<transition on="*" to="popupEnder" />
</subflow-state>
<view-state id="popupEnder" view="popupEnder" />
<inline-flow id="popupInlineFlow">
<flow>
<start-state idref="v1" />
<view-state id="v1" view="v1">
<transition on="end" to="end" />
</view-state>
<end-state id="end" />
</flow>
</inline-flow>
</flow>
To spawn a popup, mainView.jsp looks like:
...
<input type="button" value="Scripting"
onclick="openPopup('<%= request.getContextPath() %>/tce.spring?_flowExecutionKey=${flowExecutionKey}&_eventId=popup', 'Popup', 640, 480);" />
...
openPopup() is a simple Javascript function:
function openPopup(url, name, width, height)
{
window.open(url, name, "width=" + width + ",height=" + height +
",status=no,toolbar=no,menubar=no,location=no");
}
v1.jsp contains:
<input type="submit" name="_eventId_end" value="End" />
popupEnder.jsp is:
<%@ page language="java" session="false" isErrorPage="false" pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>No-one should see this!</title>
<script type="text/javascript" language="Javascript1.5">
function doOnload()
{
window.opener.document.location = window.opener.document.location;
window.close();
}
</script>
</head>
<body onload="doOnload();">
<p>
Window is closing...
</p>
</body>
</html>
Note that popupEnder.jsp causes a refresh of the opener...allows the
popup window to make a change to the underlying model(s) and have those
changes shown in the opener page at the end of the flow.
Note also that popupEnder has to be invoked from the main flow, not the
subflow...a little inconvenient, but workable.
(As an aside, why is this the case? The doco is clear on this, but the
reason...?)
Hope this helps someone out there!
Cheers,
Alph