Discussion:
open new window form struts action
Ashish Kulkarni
2005-01-19 17:47:45 UTC
Permalink
Hi
can we open a new window from action class?
i dont want to use
<form action="display.jsp" method="post"
target="_blank">
as i want to be able to open this new window from any
form( i have a menu option which can be executed from
any page of my website)
Basically i have a java script which looks like this
TheNewWin = window.open(url, '',
config='height='+height+', width='+width+',
toolbar=no, menubar=no,scrollbars=no,resizable=no,
location=no,directories=no, status=no
,offscreenBuffering=false');

Ashish



__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com
f***@omnytex.com
2005-01-19 17:56:36 UTC
Permalink
This should probably be an answer on the Wiki since I see this asked quite a bit...

No, you cannot open a new window from an Action. Not directly anyway. Opening a window is strictly a client-side activity. Therefore, you have two choices:

(1) Submit a form to _blank, as you said (actually, I think it's _new, but my memory sucks so I'm not sure)

(2) Use Javascript to open it, as you have already

I have something similar on all my pages... I can return a message from any Action that is displayed via JS alert(). To do this, I simply send a "message" attribute back in request, and every page checks if it's null onLoad, and if not calls:

alert("<%=(String)request.getAttribute("message")%>");

Since all my JSP's import a common file for things like this, it's only in one place.

I'm not sure if you want the new window to open in response to a for submission (in which case just targeting a new window is probably the better idea) or variably depending on what the server returns. I think it's the later based on what you said, so I think something like I do would suit you.
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
Post by Ashish Kulkarni
Hi
can we open a new window from action class?
i dont want to use
<form action="display.jsp" method="post"
target="_blank">
as i want to be able to open this new window from any
form( i have a menu option which can be executed from
any page of my website)
Basically i have a java script which looks like this
TheNewWin = window.open(url, '',
config='height='+height+', width='+width+',
toolbar=no, menubar=no,scrollbars=no,resizable=no,
location=no,directories=no, status=no
,offscreenBuffering=false');
Ashish
__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com
---------------------------------------------------------------------
PA
2005-01-19 18:00:59 UTC
Permalink
Post by f***@omnytex.com
(1) Submit a form to _blank, as you said (actually, I think it's _new,
but my memory sucks so I'm not sure)
Actually, you can define whatever target you like.

There are a couple of "standard" ones though:

• _blank - the target URL will open in a new window
• _self - the target URL will open in the same frame as it was clicked
• _parent - the target URL will open in the parent frameset
• _top - the target URL will open in the full body of the window

http://www.w3schools.com/tags/tag_a.asp

Cheers

--
PA
http://alt.textdrive.com/
f***@omnytex.com
2005-01-19 18:05:21 UTC
Permalink
For my own edification, can you expand on the ability to "...define whatever target you like"? I've never heard that before, I'd be interested to know more. I'm wondering specifically since the browser wouldn't know what anything other than the defined targets you referenced meant, how would you go about handling them yourself? Can you give an example use case?

Thanks PA!
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
Post by PA
Post by f***@omnytex.com
(1) Submit a form to _blank, as you said (actually, I think it's _new,
but my memory sucks so I'm not sure)
Actually, you can define whatever target you like.
? _blank - the target URL will open in a new window
? _self - the target URL will open in the same frame as it was clicked
? _parent - the target URL will open in the parent frameset
? _top - the target URL will open in the full body of the window
http://www.w3schools.com/tags/tag_a.asp
Cheers
--
PA
http://alt.textdrive.com/
---------------------------------------------------------------------
PA
2005-01-19 18:50:15 UTC
Permalink
Post by f***@omnytex.com
For my own edification, can you expand on the ability to "...define
whatever target you like"? I've never heard that before, I'd be
interested to know more. I'm wondering specifically since the browser
wouldn't know what anything other than the defined targets you
referenced meant, how would you go about handling them yourself? Can
you give an example use case?
The target can be named anyway you choose. This is handy when you want
to create an external window and consistently reuse it (e.g. always
open external link in "target = 'externalLink'").

Cheers

--
PA
http://alt.textdrive.com/
f***@omnytex.com
2005-01-19 18:55:40 UTC
Permalink
Geez, I wish I'd have known that before! So are you saying that if the browser doesn't recognize the target as one of the predefined types, it will assume it should open a new window named according to the target value? That's cool, and I didn't know it. It would have saved me some trouble a few weeks back because I had to add some code to a system to deal with a situation where a popup window might have been opened and things broke if a certain request was submitted again with it still open. I just added a quick Javascript check and closed the window if it was open before submitting the form, but this would have been much better!
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
Post by PA
Post by f***@omnytex.com
For my own edification, can you expand on the ability to "...define
whatever target you like"? I've never heard that before, I'd be
interested to know more. I'm wondering specifically since the browser
wouldn't know what anything other than the defined targets you
referenced meant, how would you go about handling them yourself? Can
you give an example use case?
The target can be named anyway you choose. This is handy when you want
to create an external window and consistently reuse it (e.g. always
open external link in "target = 'externalLink'").
Cheers
--
PA
http://alt.textdrive.com/
---------------------------------------------------------------------
Ashish Kulkarni
2005-01-19 19:27:42 UTC
Permalink
Hi
thanx guys for the clarification, here is a very
intresting problem with defining target and opening
new window,
suppose you open a new window using java script in
mypage.jsp
your code will be like below in mypage.jsp
var TheNewWin;
if(!TheNewWin || TheNewWin.closed)
{
TheNewWin = window.open('abc.jsp');
}
else
{
TheNewWin.focus();
}
for some reason you browse to mypage2.jsp and then
come back to mypage.jsp
and call this java script, it will open a new window
(remmemer we have not closed the previous window)
because variable TheNewWin is defined again, and as no
knowledge of the already open window,
how will you handle this situation
Ashish
Post by f***@omnytex.com
Geez, I wish I'd have known that before! So are you
saying that if the browser doesn't recognize the
target as one of the predefined types, it will
assume it should open a new window named according
to the target value? That's cool, and I didn't know
it. It would have saved me some trouble a few weeks
back because I had to add some code to a system to
deal with a situation where a popup window might
have been opened and things broke if a certain
request was submitted again with it still open. I
just added a quick Javascript check and closed the
window if it was open before submitting the form,
but this would have been much better!
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
Post by PA
Post by f***@omnytex.com
For my own edification, can you expand on the
ability to "...define
Post by PA
Post by f***@omnytex.com
whatever target you like"? I've never heard that
before, I'd be
Post by PA
Post by f***@omnytex.com
interested to know more. I'm wondering
specifically since the browser
Post by PA
Post by f***@omnytex.com
wouldn't know what anything other than the
defined targets you
Post by PA
Post by f***@omnytex.com
referenced meant, how would you go about handling
them yourself? Can
Post by PA
Post by f***@omnytex.com
you give an example use case?
The target can be named anyway you choose. This is
handy when you want
Post by PA
to create an external window and consistently
reuse it (e.g. always
Post by PA
open external link in "target = 'externalLink'").
Cheers
--
PA
http://alt.textdrive.com/
---------------------------------------------------------------------
---------------------------------------------------------------------
user-***@struts.apache.org




__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail
David G. Friedman
2005-01-19 19:48:06 UTC
Permalink
Why not set the window name to something specific such as mysite_com_popup
and then use that name as a target in the future?

Regards,
David

-----Original Message-----
From: Ashish Kulkarni [mailto:***@yahoo.com]
Sent: Wednesday, January 19, 2005 2:28 PM
To: Struts Users Mailing List
Subject: Re: open new window form struts action..java script variable


Hi
thanx guys for the clarification, here is a very
intresting problem with defining target and opening
new window,
suppose you open a new window using java script in
mypage.jsp
your code will be like below in mypage.jsp
var TheNewWin;
if(!TheNewWin || TheNewWin.closed)
{
TheNewWin = window.open('abc.jsp');
}
else
{
TheNewWin.focus();
}
for some reason you browse to mypage2.jsp and then
come back to mypage.jsp
and call this java script, it will open a new window
(remmemer we have not closed the previous window)
because variable TheNewWin is defined again, and as no
knowledge of the already open window,
how will you handle this situation
Ashish
Post by f***@omnytex.com
Geez, I wish I'd have known that before! So are you
saying that if the browser doesn't recognize the
target as one of the predefined types, it will
assume it should open a new window named according
to the target value? That's cool, and I didn't know
it. It would have saved me some trouble a few weeks
back because I had to add some code to a system to
deal with a situation where a popup window might
have been opened and things broke if a certain
request was submitted again with it still open. I
just added a quick Javascript check and closed the
window if it was open before submitting the form,
but this would have been much better!
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
Post by PA
Post by f***@omnytex.com
For my own edification, can you expand on the
ability to "...define
Post by PA
Post by f***@omnytex.com
whatever target you like"? I've never heard that
before, I'd be
Post by PA
Post by f***@omnytex.com
interested to know more. I'm wondering
specifically since the browser
Post by PA
Post by f***@omnytex.com
wouldn't know what anything other than the
defined targets you
Post by PA
Post by f***@omnytex.com
referenced meant, how would you go about handling
them yourself? Can
Post by PA
Post by f***@omnytex.com
you give an example use case?
The target can be named anyway you choose. This is
handy when you want
Post by PA
to create an external window and consistently
reuse it (e.g. always
Post by PA
open external link in "target = 'externalLink'").
Cheers
--
PA
http://alt.textdrive.com/
---------------------------------------------------------------------
---------------------------------------------------------------------
user-***@struts.apache.org




__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@struts.apache.org
For additional commands, e-mail: user-***@struts.apache.org
Ashish Kulkarni
2005-01-20 18:39:08 UTC
Permalink
Hi
it is not the name, when you exit from that jsp page
and revisit it, the variable is defined again, and
does not refer to the previously defined, and so have
no clue of te open browser window

Ashish
Post by David G. Friedman
Why not set the window name to something specific
such as mysite_com_popup
and then use that name as a target in the future?
Regards,
David
-----Original Message-----
From: Ashish Kulkarni
Sent: Wednesday, January 19, 2005 2:28 PM
To: Struts Users Mailing List
Subject: Re: open new window form struts
action..java script variable
Hi
thanx guys for the clarification, here is a very
intresting problem with defining target and opening
new window,
suppose you open a new window using java script in
mypage.jsp
your code will be like below in mypage.jsp
var TheNewWin;
if(!TheNewWin || TheNewWin.closed)
{
TheNewWin = window.open('abc.jsp');
}
else
{
TheNewWin.focus();
}
for some reason you browse to mypage2.jsp and then
come back to mypage.jsp
and call this java script, it will open a new window
(remmemer we have not closed the previous window)
because variable TheNewWin is defined again, and as
no
knowledge of the already open window,
how will you handle this situation
Ashish
Post by f***@omnytex.com
Geez, I wish I'd have known that before! So are
you
Post by f***@omnytex.com
saying that if the browser doesn't recognize the
target as one of the predefined types, it will
assume it should open a new window named according
to the target value? That's cool, and I didn't
know
Post by f***@omnytex.com
it. It would have saved me some trouble a few
weeks
Post by f***@omnytex.com
back because I had to add some code to a system to
deal with a situation where a popup window might
have been opened and things broke if a certain
request was submitted again with it still open. I
just added a quick Javascript check and closed the
window if it was open before submitting the form,
but this would have been much better!
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
Post by PA
Post by f***@omnytex.com
For my own edification, can you expand on the
ability to "...define
Post by PA
Post by f***@omnytex.com
whatever target you like"? I've never heard
that
Post by f***@omnytex.com
before, I'd be
Post by PA
Post by f***@omnytex.com
interested to know more. I'm wondering
specifically since the browser
Post by PA
Post by f***@omnytex.com
wouldn't know what anything other than the
defined targets you
Post by PA
Post by f***@omnytex.com
referenced meant, how would you go about
handling
Post by f***@omnytex.com
them yourself? Can
Post by PA
Post by f***@omnytex.com
you give an example use case?
The target can be named anyway you choose. This
is
Post by f***@omnytex.com
handy when you want
Post by PA
to create an external window and consistently
reuse it (e.g. always
Post by PA
open external link in "target =
'externalLink'").
Post by f***@omnytex.com
Post by PA
Cheers
--
PA
http://alt.textdrive.com/
---------------------------------------------------------------------
---------------------------------------------------------------------
Post by David G. Friedman
__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail
---------------------------------------------------------------------
---------------------------------------------------------------------
__________________________________
Do you Yahoo!?
The all-new My Yahoo! - What will yours do?
http://my.yahoo.com
Backus, Matthew J
2005-01-20 13:33:19 UTC
Permalink
though not a struts issue, the anchor tags target attribute is generally
used when dealing with frames. I have READ that forcing content into a new
window can cause problems for user agents (html readers).

-----Original Message-----
From: David G. Friedman [mailto:***@ix.netcom.com]
Sent: Wednesday, January 19, 2005 2:48 PM
To: Struts Users Mailing List
Subject: RE: open new window form struts action..java script variable


Why not set the window name to something specific such as mysite_com_popup
and then use that name as a target in the future?

Regards,
David

-----Original Message-----
From: Ashish Kulkarni [mailto:***@yahoo.com]
Sent: Wednesday, January 19, 2005 2:28 PM
To: Struts Users Mailing List
Subject: Re: open new window form struts action..java script variable


Hi
thanx guys for the clarification, here is a very
intresting problem with defining target and opening
new window,
suppose you open a new window using java script in
mypage.jsp
your code will be like below in mypage.jsp
var TheNewWin;
if(!TheNewWin || TheNewWin.closed)
{
TheNewWin = window.open('abc.jsp');
}
else
{
TheNewWin.focus();
}
for some reason you browse to mypage2.jsp and then
come back to mypage.jsp
and call this java script, it will open a new window
(remmemer we have not closed the previous window)
because variable TheNewWin is defined again, and as no knowledge of the
already open window, how will you handle this situation Ashish
Post by f***@omnytex.com
Geez, I wish I'd have known that before! So are you
saying that if the browser doesn't recognize the
target as one of the predefined types, it will
assume it should open a new window named according
to the target value? That's cool, and I didn't know
it. It would have saved me some trouble a few weeks
back because I had to add some code to a system to
deal with a situation where a popup window might
have been opened and things broke if a certain
request was submitted again with it still open. I
just added a quick Javascript check and closed the
window if it was open before submitting the form,
but this would have been much better!
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
Post by PA
Post by f***@omnytex.com
For my own edification, can you expand on the
ability to "...define
Post by PA
Post by f***@omnytex.com
whatever target you like"? I've never heard that
before, I'd be
Post by PA
Post by f***@omnytex.com
interested to know more. I'm wondering
specifically since the browser
Post by PA
Post by f***@omnytex.com
wouldn't know what anything other than the
defined targets you
Post by PA
Post by f***@omnytex.com
referenced meant, how would you go about handling
them yourself? Can
Post by PA
Post by f***@omnytex.com
you give an example use case?
The target can be named anyway you choose. This is
handy when you want
Post by PA
to create an external window and consistently
reuse it (e.g. always
Post by PA
open external link in "target = 'externalLink'").
Cheers
--
PA
http://alt.textdrive.com/
---------------------------------------------------------------------
---------------------------------------------------------------------
user-***@struts.apache.org




__________________________________
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.
http://promotions.yahoo.com/new_mail

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@struts.apache.org
For additional commands, e-mail: user-***@struts.apache.org
j***@chello.at
2005-01-20 20:25:24 UTC
Permalink
Post by Ashish Kulkarni
Hi
can we open a new window from action class?
i dont want to use
<form action="display.jsp" method="post"
target="_blank">
as i want to be able to open this new window from any
form( i have a menu option which can be executed from
any page of my website)
Basically i have a java script which looks like this
TheNewWin = window.open(url, '',
config='height='+height+', width='+width+',
toolbar=no, menubar=no,scrollbars=no,resizable=no,
location=no,directories=no, status=no
,offscreenBuffering=false');
Ashish
this is exactly the problem, with target=_blank_whatever, you are not
able to
spezify height, toolbar,statusbar, etc.
With window.open(url, ...) you have to add your form fields in query
string manner
and retrieve them in the action via: String someFormField =
request.getParameter("theField");
which disrupts the struts ActionForm paradigm.

Wolfgang
Post by Ashish Kulkarni
__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com
---------------------------------------------------------------------
j***@chello.at
2005-02-02 20:30:01 UTC
Permalink
Post by Ashish Kulkarni
Hi
can we open a new window from action class?
i dont want to use
<form action="display.jsp" method="post"
target="_blank">
as i want to be able to open this new window from any
form( i have a menu option which can be executed from
any page of my website)
Basically i have a java script which looks like this
TheNewWin = window.open(url, '',
config='height='+height+', width='+width+',
toolbar=no, menubar=no,scrollbars=no,resizable=no,
location=no,directories=no, status=no
,offscreenBuffering=false');
Ashish
Try:

<form action="/yourAction" . . . . . target="someName"
onsumit="window.open('',this.target,
'menubar=no,resizable=no,....,status=no');return true;">

Wolfgang
Post by Ashish Kulkarni
__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com
---------------------------------------------------------------------
Loading...