D
Dave
I've been slowly learning struts in my spare time and I've been trying
to do a simple popup. I wanted to display some data along with an edit
button. If you click on the edit button you get a new window on which
the values are editable. When you click save of the new window, it
should disappear and the editted values should appear in the original
window.
It was easy enough creating the 2 views. It was even easy to get the
edit button to bring up the new window. It didn't work from that point
though. The Save button painted the original view (with the new values)
into the popup window while leaving the original window stiff alive in
the background.
The solution I found has two problems for me.
1 - it works only in IE.
2 - It feels very un struts like. Navigation is coded in the page
instead of in struts-config.xml.
Here are the views. First the main page:
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<jsp:useBean id="DataForm"
scope="session"
type=
"com.flashline.strutsexample.popup.forms.DataForm" />
<html:html locale="true">
<head>
<html:base/>
</head>
<body bgcolor="white" OnLoad="window.name='MainWindow';">
<b>Data</b>
<html:form action="Edit" target="Popup" >
<p>Str1 : <bean:write name="DataForm" property="str1"/></p>
<p>Str2 : <bean:write name="DataForm" property="str2"/></p>
<html:submit styleClass="button" value="Edit" />
</html:form>
</body>
</html:html>
The javascript in the onload attribute of the body tag gives the main
window a name that can be targeted by the edit window.
The target attribute of the form tag causes the results of the submit to
appear in a new window (or reused window if the popup window already
exists).
Now the edit view:
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<html:html locale="true">
<head>
<html:base/>
</head>
<body bgcolor="white">
<b>Edit</b>
<html:form action="Data"
onsubmit="window.close();"
target="MainWindow">
<html:text property="str1"/>
<html:text property="str2"/>
<html:submit styleClass="button" value="Save" />
</html:form>
</body>
</html:html>
The javascript in the onsubmit attribute of the form tag causes the edit
window to close.
The target attribute of the form tag refers to the name set in the main
page using javascript. It causes the results to appear there (as long
as the browser is IE)
This seems like a bad solution (even apart from not working in other
browsers) because the edit window is aware of the name of the launching
window. If the launching window should change names or I want to reuse
this edit window from another window I'd have to edit it.
Also, as a navigation issue it seems to me that this should be handled
in the struts-config.xml file.
can it be?
Any thoughts?
to do a simple popup. I wanted to display some data along with an edit
button. If you click on the edit button you get a new window on which
the values are editable. When you click save of the new window, it
should disappear and the editted values should appear in the original
window.
It was easy enough creating the 2 views. It was even easy to get the
edit button to bring up the new window. It didn't work from that point
though. The Save button painted the original view (with the new values)
into the popup window while leaving the original window stiff alive in
the background.
The solution I found has two problems for me.
1 - it works only in IE.
2 - It feels very un struts like. Navigation is coded in the page
instead of in struts-config.xml.
Here are the views. First the main page:
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<jsp:useBean id="DataForm"
scope="session"
type=
"com.flashline.strutsexample.popup.forms.DataForm" />
<html:html locale="true">
<head>
<html:base/>
</head>
<body bgcolor="white" OnLoad="window.name='MainWindow';">
<b>Data</b>
<html:form action="Edit" target="Popup" >
<p>Str1 : <bean:write name="DataForm" property="str1"/></p>
<p>Str2 : <bean:write name="DataForm" property="str2"/></p>
<html:submit styleClass="button" value="Edit" />
</html:form>
</body>
</html:html>
The javascript in the onload attribute of the body tag gives the main
window a name that can be targeted by the edit window.
The target attribute of the form tag causes the results of the submit to
appear in a new window (or reused window if the popup window already
exists).
Now the edit view:
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<html:html locale="true">
<head>
<html:base/>
</head>
<body bgcolor="white">
<b>Edit</b>
<html:form action="Data"
onsubmit="window.close();"
target="MainWindow">
<html:text property="str1"/>
<html:text property="str2"/>
<html:submit styleClass="button" value="Save" />
</html:form>
</body>
</html:html>
The javascript in the onsubmit attribute of the form tag causes the edit
window to close.
The target attribute of the form tag refers to the name set in the main
page using javascript. It causes the results to appear there (as long
as the browser is IE)
This seems like a bad solution (even apart from not working in other
browsers) because the edit window is aware of the name of the launching
window. If the launching window should change names or I want to reuse
this edit window from another window I'd have to edit it.
Also, as a navigation issue it seems to me that this should be handled
in the struts-config.xml file.
can it be?
Any thoughts?