You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Christopher Loschen <CL...@axeda.com> on 2007/02/07 20:14:35 UTC

Struts action call in a JS method returns blank page

Hi all,

 

I'm honestly unsure if I'm having a problem with Struts (sadly, 1.1) or
with Javascript, or something else. But my best guess is it's a Struts
issue, and anyway, there are a lot of very knowledgeable people on both
of those technologies here, so I hope someone can help. Bottom line: I'm
getting the popup with the correct values, but my main page under the
popup becomes blank.

 

I'm adding some functionality to an existing application. The
functionality I'm adding takes the values from some checkboxes on page
A, gets the corresponding devices from the checkbox values, and saves
the resulting List into the request. Later down the stream, other code
gets those values again and uses them as a list of devices on which to
perform an action. Pretty straightforward. 

 

All of the actual navigation is happening via Javascript calls, starting
with a link on page A, but outside the form where my checkboxes are
declared. That link fires a Javascript function which pops up a small
window with a list of actions which have been defined. If the user then
clicks on one of those actions, another Javascript function fires which
pops up another window to confirm that the user wants to perform the
selected action on the selected devices. 

 

I have inserted my added functionality into that second script.
Basically I need to submit the appropriate form on the page. I've
defined it with the correct action and I've got a mapping in my
struts-config.xml file:

 

    <form-bean

     name="service.device.selected-devices-form"

     type="com.xxx.webapp.common.CheckboxForm"/>

...

    <action path="/service/device/actions/store-selected-devices"

 
type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"

            name="service.device.selected-devices-form" />

 

The mapping doesn't have any action forwards defined because it doesn't
actually need to go anywhere (though that might be part of my problem).
The JS function looks like this:

 

function popActionConfirm(url) {

 

  var form = document.forms['service.device.selected-devices-form'];

  if (form!=null) form.submit();

 

  var winl = (screen.width - 500) / 2;

 

  var wint = (screen.height - 350) / 2;

 

    winprops =
'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable=
0';

 

  var child = window.open(url,"action_confirm", winprops);

 

  self.name="main_window";

 

}

 

I added the first two lines of the JS method - it worked correctly
before I put those in (though of course it didn't have my added
functionality in place). The popup window does appear, and it has the
correct values in it (that is, the devices which were selected). But the
main window goes blank where before it remained unchanged. When I've
seen blank pages like this before, it meant there was a bad action
forward in the struts-config file, but I don't want the main page to
change at all, so what I really want is for the main page to just stay
in place as it was before the form was submitted.

 

How do I go about doing that? Thanks!

 

Chris Loschen

 

 


RE: Struts action call in a JS method returns blank page

Posted by Christopher Loschen <CL...@axeda.com>.
Thanks Musachy.

I changed the success action forward to point to the original page (or
really the action which creates that page) and that works, though it
does rebuild the page, which is unfortunate overhead. But it does do
what I need to do, so I'm happy.

Thank you.

Chris

-----Original Message-----
From: Musachy Barroso [mailto:mbarroso@wfscorp.com] 
Sent: Wednesday, February 07, 2007 2:30 PM
To: Struts Users Mailing List
Subject: Re: Struts action call in a JS method returns blank page

When you post the form, after the action, struts will send a response, 
usually a page. Because you don't want to change the current page, you 
could do this by making an asynchronous request. I'm probably wrong, but

I don't think you can make a post, and stay on the same page (unless you

are returning the same page from the action of course).

regards
musachy

Christopher Loschen wrote:
> Hi all,
>
>  
>
> I'm honestly unsure if I'm having a problem with Struts (sadly, 1.1)
or
> with Javascript, or something else. But my best guess is it's a Struts
> issue, and anyway, there are a lot of very knowledgeable people on
both
> of those technologies here, so I hope someone can help. Bottom line:
I'm
> getting the popup with the correct values, but my main page under the
> popup becomes blank.
>
>  
>
> I'm adding some functionality to an existing application. The
> functionality I'm adding takes the values from some checkboxes on page
> A, gets the corresponding devices from the checkbox values, and saves
> the resulting List into the request. Later down the stream, other code
> gets those values again and uses them as a list of devices on which to
> perform an action. Pretty straightforward. 
>
>  
>
> All of the actual navigation is happening via Javascript calls,
starting
> with a link on page A, but outside the form where my checkboxes are
> declared. That link fires a Javascript function which pops up a small
> window with a list of actions which have been defined. If the user
then
> clicks on one of those actions, another Javascript function fires
which
> pops up another window to confirm that the user wants to perform the
> selected action on the selected devices. 
>
>  
>
> I have inserted my added functionality into that second script.
> Basically I need to submit the appropriate form on the page. I've
> defined it with the correct action and I've got a mapping in my
> struts-config.xml file:
>
>  
>
>     <form-bean
>
>      name="service.device.selected-devices-form"
>
>      type="com.xxx.webapp.common.CheckboxForm"/>
>
> ...
>
>     <action path="/service/device/actions/store-selected-devices"
>
>  
> type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
>
>             name="service.device.selected-devices-form" />
>
>  
>
> The mapping doesn't have any action forwards defined because it
doesn't
> actually need to go anywhere (though that might be part of my
problem).
> The JS function looks like this:
>
>  
>
> function popActionConfirm(url) {
>
>  
>
>   var form = document.forms['service.device.selected-devices-form'];
>
>   if (form!=null) form.submit();
>
>  
>
>   var winl = (screen.width - 500) / 2;
>
>  
>
>   var wint = (screen.height - 350) / 2;
>
>  
>
>     winprops =
>
'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable=
> 0';
>
>  
>
>   var child = window.open(url,"action_confirm", winprops);
>
>  
>
>   self.name="main_window";
>
>  
>
> }
>
>  
>
> I added the first two lines of the JS method - it worked correctly
> before I put those in (though of course it didn't have my added
> functionality in place). The popup window does appear, and it has the
> correct values in it (that is, the devices which were selected). But
the
> main window goes blank where before it remained unchanged. When I've
> seen blank pages like this before, it meant there was a bad action
> forward in the struts-config file, but I don't want the main page to
> change at all, so what I really want is for the main page to just stay
> in place as it was before the form was submitted.
>
>  
>
> How do I go about doing that? Thanks!
>
>  
>
> Chris Loschen
>
>  
>
>  
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts action call in a JS method returns blank page

Posted by Musachy Barroso <mb...@wfscorp.com>.
When you post the form, after the action, struts will send a response, 
usually a page. Because you don't want to change the current page, you 
could do this by making an asynchronous request. I'm probably wrong, but 
I don't think you can make a post, and stay on the same page (unless you 
are returning the same page from the action of course).

regards
musachy

Christopher Loschen wrote:
> Hi all,
>
>  
>
> I'm honestly unsure if I'm having a problem with Struts (sadly, 1.1) or
> with Javascript, or something else. But my best guess is it's a Struts
> issue, and anyway, there are a lot of very knowledgeable people on both
> of those technologies here, so I hope someone can help. Bottom line: I'm
> getting the popup with the correct values, but my main page under the
> popup becomes blank.
>
>  
>
> I'm adding some functionality to an existing application. The
> functionality I'm adding takes the values from some checkboxes on page
> A, gets the corresponding devices from the checkbox values, and saves
> the resulting List into the request. Later down the stream, other code
> gets those values again and uses them as a list of devices on which to
> perform an action. Pretty straightforward. 
>
>  
>
> All of the actual navigation is happening via Javascript calls, starting
> with a link on page A, but outside the form where my checkboxes are
> declared. That link fires a Javascript function which pops up a small
> window with a list of actions which have been defined. If the user then
> clicks on one of those actions, another Javascript function fires which
> pops up another window to confirm that the user wants to perform the
> selected action on the selected devices. 
>
>  
>
> I have inserted my added functionality into that second script.
> Basically I need to submit the appropriate form on the page. I've
> defined it with the correct action and I've got a mapping in my
> struts-config.xml file:
>
>  
>
>     <form-bean
>
>      name="service.device.selected-devices-form"
>
>      type="com.xxx.webapp.common.CheckboxForm"/>
>
> ...
>
>     <action path="/service/device/actions/store-selected-devices"
>
>  
> type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
>
>             name="service.device.selected-devices-form" />
>
>  
>
> The mapping doesn't have any action forwards defined because it doesn't
> actually need to go anywhere (though that might be part of my problem).
> The JS function looks like this:
>
>  
>
> function popActionConfirm(url) {
>
>  
>
>   var form = document.forms['service.device.selected-devices-form'];
>
>   if (form!=null) form.submit();
>
>  
>
>   var winl = (screen.width - 500) / 2;
>
>  
>
>   var wint = (screen.height - 350) / 2;
>
>  
>
>     winprops =
> 'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable=
> 0';
>
>  
>
>   var child = window.open(url,"action_confirm", winprops);
>
>  
>
>   self.name="main_window";
>
>  
>
> }
>
>  
>
> I added the first two lines of the JS method - it worked correctly
> before I put those in (though of course it didn't have my added
> functionality in place). The popup window does appear, and it has the
> correct values in it (that is, the devices which were selected). But the
> main window goes blank where before it remained unchanged. When I've
> seen blank pages like this before, it meant there was a bad action
> forward in the struts-config file, but I don't want the main page to
> change at all, so what I really want is for the main page to just stay
> in place as it was before the form was submitted.
>
>  
>
> How do I go about doing that? Thanks!
>
>  
>
> Chris Loschen
>
>  
>
>  
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: [OT] RE: Struts action call in a JS method returns blank page

Posted by Christopher Loschen <CL...@axeda.com>.
Thanks Dave,
 
I'm sure that innerHTML was my faulty memory since I didn't write that code and haven't touched it, but I will double-check tomorrow.
 
Thanks for the other ideas too -- I think all the relevant code is inside a function but I'm not entirely sure, so I'll double-check that too.
 
Chris

________________________________

From: Dave Newton [mailto:newton.dave@yahoo.com]
Sent: Sun 2/11/2007 9:21 AM
To: Struts Users Mailing List
Subject: [OT] RE: Struts action call in a JS method returns blank page



--- Christopher Loschen <CL...@axeda.com> wrote:
> parent.document.resultDiv.innerHtml =
> document.resultDivTemp.innerHtml;

I know that was from memory, but IIRC it's innerHTML,
so just in case.

> Another possibility is that the button I'm pressing
> to move from page to page appears on the page BEFORE
> the form appears (above it vertically) and so the
> form might not yet be fully defined at that point on
> the page, but that doesn't make sense to me either,
> because if that were a problem, then there's no way
> I could ever use a control that appears earlier on
> the page than a form, and I see that on websites all
> the time.

Just bear in mind that any Javascript that isn't
executing within a function is called in the order
it's loaded, so if you have "naked" Javascript before
the form is on the page it will fail:

<script>
  var foo = document.form.uhoh.value;
</script>

<form name="uhoh".../>

Nope.

In any case, what you're doing probably shouldn't
crash Firefox/Firebug, so I'd file a ticket once you
reproduce a minimal testcase.

I'd still like to know what happens if you ask for

var boxesAcross =
    checkForm.elements['checkbox_ids_across'].value;

in the Firebug console, though.

d.




____________________________________________________________________________________
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
http://videogames.yahoo.com/platform?platform=120121

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




[OT] RE: Struts action call in a JS method returns blank page

Posted by Dave Newton <ne...@yahoo.com>.
--- Christopher Loschen <CL...@axeda.com> wrote:
> parent.document.resultDiv.innerHtml =
> document.resultDivTemp.innerHtml;

I know that was from memory, but IIRC it's innerHTML,
so just in case.

> Another possibility is that the button I'm pressing
> to move from page to page appears on the page BEFORE
> the form appears (above it vertically) and so the
> form might not yet be fully defined at that point on
> the page, but that doesn't make sense to me either,
> because if that were a problem, then there's no way
> I could ever use a control that appears earlier on
> the page than a form, and I see that on websites all
> the time.

Just bear in mind that any Javascript that isn't
executing within a function is called in the order
it's loaded, so if you have "naked" Javascript before
the form is on the page it will fail:

<script>
  var foo = document.form.uhoh.value;
</script>

<form name="uhoh".../>

Nope.

In any case, what you're doing probably shouldn't
crash Firefox/Firebug, so I'd file a ticket once you
reproduce a minimal testcase.

I'd still like to know what happens if you ask for

var boxesAcross =
    checkForm.elements['checkbox_ids_across'].value;

in the Firebug console, though.

d.



 
____________________________________________________________________________________
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
http://videogames.yahoo.com/platform?platform=120121

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts action call in a JS method returns blank page

Posted by Christopher Loschen <CL...@axeda.com>.
I promised that I'd report back with the eventual solution, so here
goes.

There were quite a few problems that I ended up finding along the way,
but the most important one was that I was trying to feed form element
values as arguments to a JS function, and the form hadn't been submitted
yet at that point, so I was always getting null. Instead, I parsed the
query from the URL and got the values I needed from there and that did
what I needed.

I can provide some more details off-line if anyone wants them, but since
this was sort of an off-topic thread to begin with, I don't want to
waste everyone's time. 

Thanks again for everyone's help on this!

Chris

-----Original Message-----
From: Christopher Loschen [mailto:CLoschen@axeda.com] 
Sent: Monday, February 12, 2007 9:46 PM
To: Struts Users Mailing List
Subject: RE: Struts action call in a JS method returns blank page

Thanks again for your help. I checked the innerHTML code and it does
refer to innerHTML, not innerHtml as I mistakenly remembered. My code
all does appear to be inside functions.

What I've done at this point is reverted to the code that existed
before, and the JS is now working (I think -- more testing needed). The
difference there is that the code was manipulating strings and appending
them directly onto the URL and I was trying to do the same thing with
form elements. I still think my approach would be cleaner, but it isn't
working so I'm willing to admit defeat.

The next problem is actually getting these URL attributes into my Struts
action form, so I think I'm returning to a more or less on-topic
question! The script did just change the location without submitting the
form, so that wasn't working. I added a branch for the situation when I
did need to submit the form for Struts which takes the same data that
was being added to the URL and sets it up as form fields instead. That
is working for two of the three sets, but not the third. For that one, I
keep getting "[object]" or "[undefined]" or something like that instead
of the (possibly empty) string I expect. I tried setting up a hidden
field in the form to hold the property I needed, but that didn't help.
One thing I haven't tried yet is to initialize the value of the property
in that hidden field, something along the lines of 

<html:hidden property="checkboxes_across" value=""/>

I have the property now, but not the value attribute. Worth a try, I
guess. I feel like I'm almost there, but it's taking much longer than I
had hoped. Oh well.

Thanks again for your help, everyone. If you have any more suggestions,
I'm happy to hear them. I'll report back when I finally do figure it all
out.

Chris

-----Original Message-----
From: Christopher Loschen [mailto:CLoschen@axeda.com
<ma...@axeda.com> ]
Sent: Sunday, February 11, 2007 5:25 PM
To: Struts Users Mailing List
Subject: RE: Struts action call in a JS method returns blank page

Yeah, that's why I was suspicious. I'm not sure what the code is doing,
but it was there before I got there. On the other hand, before I started
mucking with the code, it was working enough that it usually kept the
correct boxes checked when I changed pages -- it just didn't get the
checked boxes that weren't on the current page saved to the Struts form.
My best bet might be to revert to the JS that was working and try to
figure out the other problems instead.

Chris

________________________________

From: Frank W. Zammetti [mailto:fzlists@omnytex.com
<ma...@omnytex.com> ]
Sent: Sun 2/11/2007 10:14 AM
To: Struts Users Mailing List
Subject: Re: Struts action call in a JS method returns blank page



Christopher Loschen wrote:
> I'm suspicious of some code elsewhere on the page that reloads the
entire page -- I don't have it in front of me right now, but it goes
something like:

Woah, are you saying the form your trying to work with was dynamically
inserted into the page via innerHTML?  If so, the problem you may be
encountering is that content inserted with innerHTML isn't necessarily
added to the DOM at all.  I've frankly never spent the time to determine
the pattern, but I know there are some instances, in one browser or
another, where the DOM isn't updated, and other times it is.  I
typically just avoid using innerHTML to insert anything I know I'm going
to want to access later :

Frank

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org







---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts action call in a JS method returns blank page

Posted by Christopher Loschen <CL...@axeda.com>.
Thanks again for your help. I checked the innerHTML code and it does refer to innerHTML, not innerHtml as I mistakenly remembered. My code all does appear to be inside functions.

What I've done at this point is reverted to the code that existed before, and the JS is now working (I think -- more testing needed). The difference there is that the code was manipulating strings and appending them directly onto the URL and I was trying to do the same thing with form elements. I still think my approach would be cleaner, but it isn't working so I'm willing to admit defeat.

The next problem is actually getting these URL attributes into my Struts action form, so I think I'm returning to a more or less on-topic question! The script did just change the location without submitting the form, so that wasn't working. I added a branch for the situation when I did need to submit the form for Struts which takes the same data that was being added to the URL and sets it up as form fields instead. That is working for two of the three sets, but not the third. For that one, I keep getting "[object]" or "[undefined]" or something like that instead of the (possibly empty) string I expect. I tried setting up a hidden field in the form to hold the property I needed, but that didn't help. One thing I haven't tried yet is to initialize the value of the property in that hidden field, something along the lines of 

<html:hidden property="checkboxes_across" value=""/>

I have the property now, but not the value attribute. Worth a try, I guess. I feel like I'm almost there, but it's taking much longer than I had hoped. Oh well.

Thanks again for your help, everyone. If you have any more suggestions, I'm happy to hear them. I'll report back when I finally do figure it all out.

Chris

-----Original Message-----
From: Christopher Loschen [mailto:CLoschen@axeda.com <ma...@axeda.com> ]
Sent: Sunday, February 11, 2007 5:25 PM
To: Struts Users Mailing List
Subject: RE: Struts action call in a JS method returns blank page

Yeah, that's why I was suspicious. I'm not sure what the code is doing, but it was there before I got there. On the other hand, before I started mucking with the code, it was working enough that it usually kept the correct boxes checked when I changed pages -- it just didn't get the checked boxes that weren't on the current page saved to the Struts form. My best bet might be to revert to the JS that was working and try to figure out the other problems instead.

Chris

________________________________

From: Frank W. Zammetti [mailto:fzlists@omnytex.com <ma...@omnytex.com> ]
Sent: Sun 2/11/2007 10:14 AM
To: Struts Users Mailing List
Subject: Re: Struts action call in a JS method returns blank page



Christopher Loschen wrote:
> I'm suspicious of some code elsewhere on the page that reloads the entire page -- I don't have it in front of me right now, but it goes something like:

Woah, are you saying the form your trying to work with was dynamically
inserted into the page via innerHTML?  If so, the problem you may be
encountering is that content inserted with innerHTML isn't necessarily
added to the DOM at all.  I've frankly never spent the time to determine
the pattern, but I know there are some instances, in one browser or
another, where the DOM isn't updated, and other times it is.  I
typically just avoid using innerHTML to insert anything I know I'm going
to want to access later :

Frank

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org







RE: Struts action call in a JS method returns blank page

Posted by Christopher Loschen <CL...@axeda.com>.
Yeah, that's why I was suspicious. I'm not sure what the code is doing, but it was there before I got there. On the other hand, before I started mucking with the code, it was working enough that it usually kept the correct boxes checked when I changed pages -- it just didn't get the checked boxes that weren't on the current page saved to the Struts form. My best bet might be to revert to the JS that was working and try to figure out the other problems instead.
 
Chris

________________________________

From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
Sent: Sun 2/11/2007 10:14 AM
To: Struts Users Mailing List
Subject: Re: Struts action call in a JS method returns blank page



Christopher Loschen wrote:
> I'm suspicious of some code elsewhere on the page that reloads the entire page -- I don't have it in front of me right now, but it goes something like:

Woah, are you saying the form your trying to work with was dynamically
inserted into the page via innerHTML?  If so, the problem you may be
encountering is that content inserted with innerHTML isn't necessarily
added to the DOM at all.  I've frankly never spent the time to determine
the pattern, but I know there are some instances, in one browser or
another, where the DOM isn't updated, and other times it is.  I
typically just avoid using innerHTML to insert anything I know I'm going
to want to access later :

Frank

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org





Re: Struts action call in a JS method returns blank page

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Christopher Loschen wrote:
> I'm suspicious of some code elsewhere on the page that reloads the entire page -- I don't have it in front of me right now, but it goes something like:

Woah, are you saying the form your trying to work with was dynamically 
inserted into the page via innerHTML?  If so, the problem you may be 
encountering is that content inserted with innerHTML isn't necessarily 
added to the DOM at all.  I've frankly never spent the time to determine 
the pattern, but I know there are some instances, in one browser or 
another, where the DOM isn't updated, and other times it is.  I 
typically just avoid using innerHTML to insert anything I know I'm going 
to want to access later :

Frank

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts action call in a JS method returns blank page

Posted by Christopher Loschen <CL...@axeda.com>.
Thanks, I'll try it. I did manage to get past crashing FF by changing
 
     var boxesAcross = checkForm.elements['checkbox_ids_across'].value;
 
to 
 
     var boxesAcross = checkForm.elements['checkbox_ids_across'];

I'm not quite sure why that helped, but it did. Now it gets through the method ok, but still doesn't produce any results because it still thinks that the form doesn't have any elements. I've actually already moved a lot closer to using string manipulation rather than arrays, but I don't seem to be able to get past that initial problem so that the changed code ever fires in the first place.

I'm suspicious of some code elsewhere on the page that reloads the entire page -- I don't have it in front of me right now, but it goes something like:

parent.document.resultDiv.innerHtml = document.resultDivTemp.innerHtml;

I wonder if that's screwing me up somehow so that I'm getting a form from the wrong document or something. 

Another possibility is that the button I'm pressing to move from page to page appears on the page BEFORE the form appears (above it vertically) and so the form might not yet be fully defined at that point on the page, but that doesn't make sense to me either, because if that were a problem, then there's no way I could ever use a control that appears earlier on the page than a form, and I see that on websites all the time.

A third possibility is that I need an onclick attribute on the checkboxes to capture them getting clicked, but that doesn't entirely make sense either. If that were the problem, I would expect to see the elements found in the form, just without values (as I do see in the other method), but I'm seeing a form with no elements at all.

I'll keep reading up on it today and see if I can come up with something else to try. Thanks for your help -- if you have any more suggestions, I'll be happy to give them a try.

Chris


________________________________

From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
Sent: Sun 2/11/2007 12:11 AM
To: Struts Users Mailing List
Subject: Re: Struts action call in a JS method returns blank page



Is there a reason you have to use the collection?  Could you rewrite
this to go after specific ID's?  If so, I'd suggest trying that.  Just a
hunch...

Christopher Loschen wrote:
> I may be getting way off-topic at this point -- sorry about that. I'm
> not sure where to ask these sorts of questions.
>
> I now seem to be crashing Firebug and Firefox underneath it every time I
> run it. I walk through the method line by line:
>
> function addCheckBoxValuesToForm(locationStr) {
>   var checkForm = document.forms['checkbox-form'];
>   if (checkForm) {
>     var checkboxes_across = new Array();
>     var selectedCheckBoxes = new Array();
>     var boxesAcross = checkForm.elements['checkbox_ids_across'].value;
>
> On that last line, everything crashes and I get the message that
> "Firefox has to close -- sorry for the inconvenience and tell Microsoft
> about it so we can gloat." (or something like that ;).
>
> On the previous lines, I did find a checkForm correctly, so it does find
> the correct form, but the array of elements for the form is showing up
> as empty. I suppose I could test if boxesAcross is null before trying to
> get its value, but it shouldn't be null to begin with.
>
> The especially strange thing is that this method is running fine:
>
> function checkSelectedCheckBoxes() {
>   var checkForm = document.forms['checkbox-form'];
>   if (checkForm) {
>     var selectedCheckBoxValues =
> checkForm.elements['checkbox_ids_across'].value;
>
>   // if there are no check boxes then just ignore
>     if(selectedCheckBoxValues == '') {
>         return ;
>     }
>
> This is called against the same form as the first one, and looks for the
> same input element inside it. When the second one is called, there isn't
> anything in that element yet so we just return, and the rest of the
> method (which I haven't included here) doesn't run, but that's correct.
>
> When the second method runs, it finds the same form in the same way, but
> it also finds all of the elements inside it. I'm not sure what could be
> different between them. I'm tearing my hair out!!!
>
> Any insights?
>
> Chris
>
> -----Original Message-----
> From: Christopher Loschen [mailto:CLoschen@axeda.com]
> Sent: Friday, February 09, 2007 4:32 PM
> To: Struts Users Mailing List
> Subject: RE: Struts action call in a JS method returns blank page
>
> OK, I've installed Firebug and also Firefox (a good thing since we
> support it anyway, so it's good to have it on my system). It did find
> some stuff I missed right away including the JS error on page load
> (which turned out to be in a method I hadn't showed you -- oops!).
>
> But I'm still not getting any results, and I'm not sure why. My JS
> function gets the form OK and the action, name, etc. are all correct.
> But the form in the debugger has no elements and no child nodes, while
> my form on the page has this code:
>
> <input type="hidden" name="checkbox_ids_across" value="">
> ...
> <input type="checkbox" name="checkboxes" value="32">
> Etc.
>
> So I would expect I would have at least a string for checkbox_ids_across
> and an array of strings for the checkboxes. Is that right? I must be
> missing something.
>
> The bit of code I'm looking at so far is:
>
> function addCheckBoxValuesToForm(locationStr)
> {
>  var form = document.forms['checkbox-form'];
>  if (form){
>  var checkboxes_across = new Array();
>  var selectedCheckBoxes = new Array();
>  var formCheckboxAcross = form.elements['checkbox_ids_across'];
>  if(formCheckboxAcross!=null && formCheckboxAcross!="") {
>  selectedCheckBoxes = formCheckboxAcross;
>  }
>  if (selectedCheckBoxes.length > 0) {
>  checkboxes_across.push(selectedCheckboxes);
>  }
>
>  var checkboxes = form.elements['checkboxes'];
>
> Chris
>
> -----Original Message-----
> From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
> Sent: Friday, February 09, 2007 3:35 PM
> To: Struts Users Mailing List
> Subject: Re: Struts action call in a JS method returns blank page
>
> Yeah, as musachy suggests, Firebug is your friend :)  I personally tend
> to code my JS to always go after specific IDs rather than using any of
> the common collections... that usually works just fine as long as you
> don't have multiple dynamic forms.
>
> Frank
>
> Christopher Loschen wrote:
>> Happy to provide an opportunity for self-promotion :-)!
>>
>> I think you're right about dropping the params somewhere. I've been
>> trying today to set up a new approach, which seems simpler to me, but
>> which is still fighting me. The basic idea is to use the form to hold
>> the array of values I need rather than just sticking them up onto the
>> URL. To that end, I rewrote the JS function like this:
>>
>> function addCheckBoxValuesToForm(locationStr)
>> {
>>   var form = document['checkbox-form'];
>>   if (form){
>>     var checkboxes_across = new Array();
>>     var selectedCheckBoxes = new Array();
>>     var formCheckboxAcross = form.elements['checkbox_ids_across'];
>>     if(formCheckboxAcross!=null && formCheckboxAcross!="") {
>>       selectedCheckBoxes = formCheckboxAcross;
>>     }
>>     if (selectedCheckBoxes.length > 0) {
>>       checkboxes_across.push(selectedCheckboxes);
>>     }
>>    
>>     var checkboxes = form.elements['checkboxes'];
>>     if (checkboxes)
>>     {
>>       var checkStr = new Array();
>>       var uncheckedStr = new Array();
>>      
>>       // If the no.of checkboxes is one then converting the checkbox
>> object to
>>       // Checkbox array.
>>       if(checkboxes.type == "checkbox")
>>       {
>>         checkboxes = [checkboxes];
>>       }
>>
>>       for (var i = 0; i < checkboxes.length; ++i)
>>       {
>>         if (checkboxes[i].checked)
>>         {
>>           checkStr.push(checkboxes[i].value);
>>         }
>>         else
>>         {
>>            uncheckedStr.push(checkboxes[i].value);
>>         }
>>       }
>>       if (checkStr.length > 0)
>>       {
>>         form.elements['checkbox_id'] = checkStr;
>>         checkboxes_across.push(checkStr);
>>       }
>>       if (uncheckedStr.length > 0)
>>       {
>>         form.elements['uncheckbox_id'] = uncheckedStr;
>>       }
>>     }
>>     form.elements['checkbox_ids_across'].value = checkboxes_across;
>>   }
>>  
>>   document.location.href = locationStr;
>> }
>>
>> I've got appropriate setters and getters in my Java form (I think,
>> though I have to use Identifier[] objects rather than String[], so I
>> might need to convert that), and I also added a hidden field
>> "checkbox_ids_across" into my form on the JSP form. But I'm still
>> getting a JS error when I open the page that "checkbox_ids_across" is
>> null or not an object, and it's still not doing what it's supposed to
>> do.
>>
>> Any suggestions? Thanks!
>>
>> Chris
>>
>> -----Original Message-----
>> From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
>> Sent: Thursday, February 08, 2007 5:30 PM
>> To: Struts Users Mailing List
>> Cc: Struts Users Mailing List
>> Subject: RE: Struts action call in a JS method returns blank page
>>
>> On Thu, February 8, 2007 4:46 pm, Christopher Loschen wrote:
>>> Thanks Frank -- I've been reading your posts on JWP with great
>> interest
>>> for quite a while, and I'll bet your book is another good resource.
>> *Of course* it is :) (what, you expected a different answer?!?)  FYI,
> my
>> new book, "Practical JavaScript, DOM Scripting and Ajax Projects", is
>> scheduled to hit shelves in mid-April (never pass up the chance for a
>> little shameless self-promotion I've been told!)
>>
>>> The current project (or at least this piece of it) has to be finished
>> by
>>> tomorrow, so I may not be able to introduce Ajax just yet. However,
>> I'm
>>> definitely interested in learning more about it, and will no doubt
> use
>>> it more as I learn more.
>> Sounds good.  I'd say it's not generally something you want to jump
> into
>> on a tight deadline if you have't done as much client-side
>> development...
>> many good Java developers have a bit of a rough time early on when
>> trying
>> to do more client-side stuff... seems like it should be simpler most
>> say,
>> but it isn't usually :)
>>
>>> Meanwhile, I'm looking at a possibly related problem. We've got
>>> checkboxes on multiple pages and a JS function which keeps track of
>>> which boxes are checked on which page so that we can go from page to
>>> page and retain the boxes checked on other pages. That works by
>> putting
>>> the checkbox ids into the URL for the page. It's working correctly,
>> more
>>> or less, but now I find that when I actually am ready to use the
> array
>>> of checkboxes, I'm getting only the ones on the current page, not the
>>> rest. My Java method is getting the correct request parameters, but
> it
>>> always returns null. Perhaps that's because the request parameters
> are
>>> associated with one action (which displays the appropriate page of
> the
>>> list) and my action class is associated with a different action (to
>>> store the checkbox values and process the result)? If that's right, I
>>> guess I need to get those values into my action too. Does that sound
>>> like a reasonable guess?
>> Hmm... I'm not sure I followed the whole thing, but it sure sounds
> like
>> your dropping the params somewhere... my guess is that you aren't
>> replicating the whole query string with each request, which you'd need
>> to
>> do.
>>
>> However, I'd definitely say you probably want to be storing that info
> in
>> session in the first place... then it's relatively easy to pass it
> along
>> with every single request for all pages that need it.
>>
>>> Chris
>>>
>>> -----Original Message-----
>>> From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
>>> Sent: Thursday, February 08, 2007 10:30 AM
>>> To: Struts Users Mailing List
>>> Cc: Struts Users Mailing List
>>> Subject: Re: Struts action call in a JS method returns blank page
>>>
>>> Theres a ton of choice on which AJAX library to use, many of them
> very
>>> good.  However, since your working in Java specifically, and since
> you
>>> say
>>> you are not all that familiar with JS, you may prefer a solution that
>>> will
>>> (in most cases) require ZERO Javascript coding, and such a thing
>> exists:
> http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/tagl
>>> ib/package-summary.html
>>>
>>> This is the AjaxParts Taglib (APT), which is a part of Java Web Parts
>>> (JWP):
>>>
>>> http://javawebparts.sourceforge.net <http://javawebparts.sourceforge.net/> 
>>>
>>> With this, let's say you want to update a specific <div> in response
>> to
>>> a
>>> button being clicked on a page with some data returned by the server
>>> without refreshing the page, in your JSP you would have:
>>>
>>> <div id="myDiv">Response will go here</div>
>>> <input type="button" value="Click for AJAX"><ajax:event
>>> ajaxRef="ajaxFunctions/button1" />
>>> <ajax:enable />
>>>
>>> That's it, no JavaScript at all!  The other piece to the puzzle is an
>>> XML
>>> file like so:
>>>
>>> <ajaxConfig>
>>>   <group ajaxRef="ajaxFunctions">
>>>     <element ajaxRef="button1">
>>>        <event type="onClick">
>>>          <requestHandler type="std:SimpleRequest" target="/myURL">
>>>            <parameter></parameter>
>>>         </requestHandler>
>>>         <responseHandler type="std:InnerHTML">
>>>           <parameter>myDiv</parameter>
>>>         </responseHandler>
>>>       </event>
>>>     </element>
>>>   </group>
>>> </ajaxConfig>
>>>
>>> The XML file maps via the ajaxRef values to the ajaxRef in the
>>> <ajax:event> tag, and it defines what's going to happen in response
> to
>>> some event (onClick in this case), which in this case is simply an
>> AJAX
>>> request to /myURL with no data passed, and then what happens when the
>>> response comes back, which is it will be inserted into myDiv via
>>> innerHTML.
>>>
>>> There's a whole bunch of request and response handlers available out
>> of
>>> the box which tend to cover most needs, things like submitting forms,
>>> executing some returned Javascript, sending XML automatically
>>> constructed
>>> from form data, transforming returned XML via XLT, and so on.  You
>> also
>>> have the ability to write your own handlers (just plain Javascript)
> if
>>> you
>>> need something that isn't covered.
>>>
>>> hth,
>>> Frank
>>>
>>>
>>> --
>>> Frank W. Zammetti
>>> Founder and Chief Software Architect
>>> Omnytex Technologies
>>> http://www.omnytex.com <http://www.omnytex.com/> 
>>> AIM/Yahoo: fzammetti
>>> MSN: fzammetti@hotmail.com
>>> Author of "Practical Ajax Projects With Java Technology"
>>>  (2006, Apress, ISBN 1-59059-695-1)
>>> Java Web Parts - http://javawebparts.sourceforge.net <http://javawebparts.sourceforge.net/> 
>>>  Supplying the wheel, so you don't have to reinvent it!
>>>
>>> On Thu, February 8, 2007 9:49 am, Musachy Barroso wrote:
>>>> Check Prototype out, here is a good tutorial:
>>>> http://www.sergiopereira.com/articles/prototype.js.html, basically
>>> what
>>>> you need is something like:
>>>>
>>>> |**var myAjax = new Ajax.Request(
>>>>                    url,
>>>>                    {
>>>>                            method: 'get',
>>>>                            parameters: Form.serialize("formid"),
>>>>                            onComplete: function() {
>>>>                                //do something here, or not :)
>>>>                            }
>>>>                    });**|
>>>>
>>>> regards
>>>> musachy
>>>>
>>>> Christopher Loschen wrote:
>>>>> I'm not all that familiar with JS, to be honest, and I've never had
>>> the
>>>>> chance to use Ajax (but want to learn). What I have now is working,
>>> but
>>>>> I'd be happy to learn how to do it without refreshing the page --
>>> that
>>>>> does seem like a more elegant solution to me. What do you suggest?
>> We
>>> do
>>>>> use JS for our app, but no JS framework as such as far as I can
>> tell.
>>>>> Chris
>>>>>
>>>>> -----Original Message-----
>>>>> From: Musachy Barroso [mailto:musachy@gmail.com]
>>>>> Sent: Thursday, February 08, 2007 8:03 AM
>>>>> To: Struts Users Mailing List
>>>>> Subject: Re: Struts action call in a JS method returns blank page
>>>>>
>>>>> Like I said before you can use Ajax to submit the form, and the
> page
>>>>> won't
>>>>> refresh, how to do it depends on what JS framework you are using,
> if
>>>>> any.
>>>>>
>>>>> regards
>>>>> musachy
>>>>>
>>>>> On 2/8/07, Christopher Loschen <CL...@axeda.com> wrote:
>>>>>
>>>>>> Yes, you're right that the form submit was causing the system to
>>>>>>
>>>>> forward
>>>>>
>>>>>> to whatever the action said, which in my case was the blank page.
>>>>>>
>>>>> You'll see
>>>>>
>>>>>> from the later emails in the thread yesterday that I solved that
> by
>>>>>> forwarding to the action which populated the original page.
>>>>>>
>>>>>> I need the form.submit because I need to get the checked boxes
> from
>>>>> the
>>>>>
>>>>>> form and I need to call the action specified in the action
>> attribute
>>>>> on that
>>>>>
>>>>>> form in order to put those checkbox values into the request in the
>>>>>>
>>>>> form that
>>>>>
>>>>>> my downstream code needs.
>>>>>>
>>>>>> Submitting the form is the only way I know to get the form values
>>> the
>>>>> user
>>>>>
>>>>>> submits from the HTML page to my Java code -- are you saying that
> I
>>>>> have
>>>>>
>>>>>> other alternatives?
>>>>>>
>>>>>> Chris
>>>>>>
>>>>>> ________________________________
>>>>>>
>>>>>> From: Yee Kai Lai [mailto:yeekai.lai@hotmail.com]
>>>>>> Sent: Thu 2/8/2007 12:24 AM
>>>>>> To: user@struts.apache.org
>>>>>> Subject: RE: Struts action call in a JS method returns blank page
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> It returns a blank page might be due to
>>>>>>
>>>>>> form.submit(); in your JS.
>>>>>>
>>>>>> I think if you have a form named
>>>>>>
>>>>> 'service.device.selected-devices-form'
>>>>>
>>>>>> then
>>>>>> it will never be null hence it will always submit.
>>>>>>
>>>>>> May you could enlightened why u need a form.submit() ?
>>>>>>
>>>>>>
>>>>>>
>>>>>>> From: "Christopher Loschen" <CL...@axeda.com>
>>>>>>> Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>>>>>>> To: <us...@struts.apache.org>
>>>>>>> Subject: Struts action call in a JS method returns blank page
>>>>>>> Date: Wed, 7 Feb 2007 14:14:35 -0500
>>>>>>>
>>>>>>> Hi all,
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> I'm honestly unsure if I'm having a problem with Struts (sadly,
>>> 1.1)
>>>>> or
>>>>>
>>>>>>> with Javascript, or something else. But my best guess is it's a
>>>>>>>
>>>>> Struts
>>>>>
>>>>>>> issue, and anyway, there are a lot of very knowledgeable people
> on
>>>>> both
>>>>>
>>>>>>> of those technologies here, so I hope someone can help. Bottom
>>> line:
>>>>> I'm
>>>>>
>>>>>>> getting the popup with the correct values, but my main page under
>>> the
>>>>>>> popup becomes blank.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> I'm adding some functionality to an existing application. The
>>>>>>> functionality I'm adding takes the values from some checkboxes on
>>>>>>>
>>>>> page
>>>>>
>>>>>>> A, gets the corresponding devices from the checkbox values, and
>>> saves
>>>>>>> the resulting List into the request. Later down the stream, other
>>>>>>>
>>>>> code
>>>>>
>>>>>>> gets those values again and uses them as a list of devices on
>> which
>>>>> to
>>>>>
>>>>>>> perform an action. Pretty straightforward.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> All of the actual navigation is happening via Javascript calls,
>>>>>>>
>>>>> starting
>>>>>
>>>>>>> with a link on page A, but outside the form where my checkboxes
>> are
>>>>>>> declared. That link fires a Javascript function which pops up a
>>> small
>>>>>>> window with a list of actions which have been defined. If the
> user
>>>>> then
>>>>>
>>>>>>> clicks on one of those actions, another Javascript function fires
>>>>>>>
>>>>> which
>>>>>
>>>>>>> pops up another window to confirm that the user wants to perform
>>> the
>>>>>>> selected action on the selected devices.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> I have inserted my added functionality into that second script.
>>>>>>> Basically I need to submit the appropriate form on the page. I've
>>>>>>> defined it with the correct action and I've got a mapping in my
>>>>>>> struts-config.xml file:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>     <form-bean
>>>>>>>
>>>>>>>      name="service.device.selected-devices-form"
>>>>>>>
>>>>>>>      type="com.xxx.webapp.common.CheckboxForm"/>
>>>>>>>
>>>>>>> ...
>>>>>>>
>>>>>>>     <action path="/service/device/actions/store-selected-devices"
>>>>>>>
>>>>>>>
>>>>>>> type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
>>>>>>>
>>>>>>>             name="service.device.selected-devices-form" />
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> The mapping doesn't have any action forwards defined because it
>>>>>>>
>>>>> doesn't
>>>>>
>>>>>>> actually need to go anywhere (though that might be part of my
>>>>>>>
>>>>> problem).
>>>>>
>>>>>>> The JS function looks like this:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> function popActionConfirm(url) {
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>   var form =
>>> document.forms['service.device.selected-devices-form'];
>>>>>>>   if (form!=null) form.submit();
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>   var winl = (screen.width - 500) / 2;
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>   var wint = (screen.height - 350) / 2;
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>     winprops =
>>>>>>>
> 'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable
>>>>> =
>>>>>
>>>>>>> 0';
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>   var child = window.open(url,"action_confirm", winprops);
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>   self.name="main_window";
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> I added the first two lines of the JS method - it worked
> correctly
>>>>>>> before I put those in (though of course it didn't have my added
>>>>>>> functionality in place). The popup window does appear, and it has
>>> the
>>>>>>> correct values in it (that is, the devices which were selected).
>>> But
>>>>> the
>>>>>
>>>>>>> main window goes blank where before it remained unchanged. When
>>> I've
>>>>>>> seen blank pages like this before, it meant there was a bad
> action
>>>>>>> forward in the struts-config file, but I don't want the main page
>>> to
>>>>>>> change at all, so what I really want is for the main page to just
>>>>>>>
>>>>> stay
>>>>>
>>>>>>> in place as it was before the form was submitted.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> How do I go about doing that? Thanks!
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Chris Loschen
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> _________________________________________________________________
>>>>>> Receive MSN Hotmail alerts over SMS!
>>>>>> http://en-asiasms.mobile.msn.com/ac.aspx?cid=1002
>>>>>>
>>>>>>
>>>>>>
>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>>
>

--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com <http://www.omnytex.com/> 
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
  (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net <http://javawebparts.sourceforge.net/> 
  Supplying the wheel, so you don't have to reinvent it!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org





Re: Struts action call in a JS method returns blank page

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Is there a reason you have to use the collection?  Could you rewrite 
this to go after specific ID's?  If so, I'd suggest trying that.  Just a 
hunch...

Christopher Loschen wrote:
> I may be getting way off-topic at this point -- sorry about that. I'm
> not sure where to ask these sorts of questions.
> 
> I now seem to be crashing Firebug and Firefox underneath it every time I
> run it. I walk through the method line by line:
> 
> function addCheckBoxValuesToForm(locationStr) {
>   var checkForm = document.forms['checkbox-form'];
>   if (checkForm) {
>     var checkboxes_across = new Array();
>     var selectedCheckBoxes = new Array();
>     var boxesAcross = checkForm.elements['checkbox_ids_across'].value;
> 
> On that last line, everything crashes and I get the message that
> "Firefox has to close -- sorry for the inconvenience and tell Microsoft
> about it so we can gloat." (or something like that ;).
> 
> On the previous lines, I did find a checkForm correctly, so it does find
> the correct form, but the array of elements for the form is showing up
> as empty. I suppose I could test if boxesAcross is null before trying to
> get its value, but it shouldn't be null to begin with.
> 
> The especially strange thing is that this method is running fine:
> 
> function checkSelectedCheckBoxes() {
>   var checkForm = document.forms['checkbox-form'];
>   if (checkForm) {
>     var selectedCheckBoxValues =
> checkForm.elements['checkbox_ids_across'].value;
> 
>   // if there are no check boxes then just ignore
>     if(selectedCheckBoxValues == '') {
>         return ;
>     }
> 
> This is called against the same form as the first one, and looks for the
> same input element inside it. When the second one is called, there isn't
> anything in that element yet so we just return, and the rest of the
> method (which I haven't included here) doesn't run, but that's correct.
> 
> When the second method runs, it finds the same form in the same way, but
> it also finds all of the elements inside it. I'm not sure what could be
> different between them. I'm tearing my hair out!!!
> 
> Any insights?
> 
> Chris
> 
> -----Original Message-----
> From: Christopher Loschen [mailto:CLoschen@axeda.com] 
> Sent: Friday, February 09, 2007 4:32 PM
> To: Struts Users Mailing List
> Subject: RE: Struts action call in a JS method returns blank page
> 
> OK, I've installed Firebug and also Firefox (a good thing since we
> support it anyway, so it's good to have it on my system). It did find
> some stuff I missed right away including the JS error on page load
> (which turned out to be in a method I hadn't showed you -- oops!). 
> 
> But I'm still not getting any results, and I'm not sure why. My JS
> function gets the form OK and the action, name, etc. are all correct.
> But the form in the debugger has no elements and no child nodes, while
> my form on the page has this code:
> 
> <input type="hidden" name="checkbox_ids_across" value="">
> ...
> <input type="checkbox" name="checkboxes" value="32">
> Etc.
> 
> So I would expect I would have at least a string for checkbox_ids_across
> and an array of strings for the checkboxes. Is that right? I must be
> missing something.
> 
> The bit of code I'm looking at so far is:
> 
> function addCheckBoxValuesToForm(locationStr)
> {
>  var form = document.forms['checkbox-form'];
>  if (form){
>  var checkboxes_across = new Array();
>  var selectedCheckBoxes = new Array();
>  var formCheckboxAcross = form.elements['checkbox_ids_across'];
>  if(formCheckboxAcross!=null && formCheckboxAcross!="") {
>  selectedCheckBoxes = formCheckboxAcross;
>  }
>  if (selectedCheckBoxes.length > 0) {
>  checkboxes_across.push(selectedCheckboxes);
>  }
> 
>  var checkboxes = form.elements['checkboxes'];
> 
> Chris
> 
> -----Original Message-----
> From: Frank W. Zammetti [mailto:fzlists@omnytex.com] 
> Sent: Friday, February 09, 2007 3:35 PM
> To: Struts Users Mailing List
> Subject: Re: Struts action call in a JS method returns blank page
> 
> Yeah, as musachy suggests, Firebug is your friend :)  I personally tend 
> to code my JS to always go after specific IDs rather than using any of 
> the common collections... that usually works just fine as long as you 
> don't have multiple dynamic forms.
> 
> Frank
> 
> Christopher Loschen wrote:
>> Happy to provide an opportunity for self-promotion :-)!
>>
>> I think you're right about dropping the params somewhere. I've been
>> trying today to set up a new approach, which seems simpler to me, but
>> which is still fighting me. The basic idea is to use the form to hold
>> the array of values I need rather than just sticking them up onto the
>> URL. To that end, I rewrote the JS function like this:
>>
>> function addCheckBoxValuesToForm(locationStr)
>> {
>>   var form = document['checkbox-form'];
>>   if (form){
>>     var checkboxes_across = new Array();
>>     var selectedCheckBoxes = new Array();
>>     var formCheckboxAcross = form.elements['checkbox_ids_across'];
>>     if(formCheckboxAcross!=null && formCheckboxAcross!="") {
>>       selectedCheckBoxes = formCheckboxAcross;
>>     }
>>     if (selectedCheckBoxes.length > 0) {
>>       checkboxes_across.push(selectedCheckboxes);
>>     }
>>     
>>     var checkboxes = form.elements['checkboxes'];
>>     if (checkboxes)
>>     {
>>       var checkStr = new Array();
>>       var uncheckedStr = new Array();
>>       
>>       // If the no.of checkboxes is one then converting the checkbox
>> object to
>>       // Checkbox array.
>>       if(checkboxes.type == "checkbox")
>>       {
>>         checkboxes = [checkboxes];
>>       }
>>
>>       for (var i = 0; i < checkboxes.length; ++i)
>>       {
>>         if (checkboxes[i].checked)
>>         {
>>           checkStr.push(checkboxes[i].value);
>>         }
>>         else
>>         {
>>            uncheckedStr.push(checkboxes[i].value);
>>         }
>>       }
>>       if (checkStr.length > 0)
>>       {
>>         form.elements['checkbox_id'] = checkStr;
>>         checkboxes_across.push(checkStr);
>>       }
>>       if (uncheckedStr.length > 0)
>>       {
>>         form.elements['uncheckbox_id'] = uncheckedStr;
>>       }
>>     }
>>     form.elements['checkbox_ids_across'].value = checkboxes_across;
>>   }
>>   
>>   document.location.href = locationStr;
>> }
>>
>> I've got appropriate setters and getters in my Java form (I think,
>> though I have to use Identifier[] objects rather than String[], so I
>> might need to convert that), and I also added a hidden field
>> "checkbox_ids_across" into my form on the JSP form. But I'm still
>> getting a JS error when I open the page that "checkbox_ids_across" is
>> null or not an object, and it's still not doing what it's supposed to
>> do.
>>
>> Any suggestions? Thanks!
>>
>> Chris
>>
>> -----Original Message-----
>> From: Frank W. Zammetti [mailto:fzlists@omnytex.com] 
>> Sent: Thursday, February 08, 2007 5:30 PM
>> To: Struts Users Mailing List
>> Cc: Struts Users Mailing List
>> Subject: RE: Struts action call in a JS method returns blank page
>>
>> On Thu, February 8, 2007 4:46 pm, Christopher Loschen wrote:
>>> Thanks Frank -- I've been reading your posts on JWP with great
>> interest
>>> for quite a while, and I'll bet your book is another good resource.
>> *Of course* it is :) (what, you expected a different answer?!?)  FYI,
> my
>> new book, "Practical JavaScript, DOM Scripting and Ajax Projects", is
>> scheduled to hit shelves in mid-April (never pass up the chance for a
>> little shameless self-promotion I've been told!)
>>
>>> The current project (or at least this piece of it) has to be finished
>> by
>>> tomorrow, so I may not be able to introduce Ajax just yet. However,
>> I'm
>>> definitely interested in learning more about it, and will no doubt
> use
>>> it more as I learn more.
>> Sounds good.  I'd say it's not generally something you want to jump
> into
>> on a tight deadline if you have't done as much client-side
>> development...
>> many good Java developers have a bit of a rough time early on when
>> trying
>> to do more client-side stuff... seems like it should be simpler most
>> say,
>> but it isn't usually :)
>>
>>> Meanwhile, I'm looking at a possibly related problem. We've got
>>> checkboxes on multiple pages and a JS function which keeps track of
>>> which boxes are checked on which page so that we can go from page to
>>> page and retain the boxes checked on other pages. That works by
>> putting
>>> the checkbox ids into the URL for the page. It's working correctly,
>> more
>>> or less, but now I find that when I actually am ready to use the
> array
>>> of checkboxes, I'm getting only the ones on the current page, not the
>>> rest. My Java method is getting the correct request parameters, but
> it
>>> always returns null. Perhaps that's because the request parameters
> are
>>> associated with one action (which displays the appropriate page of
> the
>>> list) and my action class is associated with a different action (to
>>> store the checkbox values and process the result)? If that's right, I
>>> guess I need to get those values into my action too. Does that sound
>>> like a reasonable guess?
>> Hmm... I'm not sure I followed the whole thing, but it sure sounds
> like
>> your dropping the params somewhere... my guess is that you aren't
>> replicating the whole query string with each request, which you'd need
>> to
>> do.
>>
>> However, I'd definitely say you probably want to be storing that info
> in
>> session in the first place... then it's relatively easy to pass it
> along
>> with every single request for all pages that need it.
>>
>>> Chris
>>>
>>> -----Original Message-----
>>> From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
>>> Sent: Thursday, February 08, 2007 10:30 AM
>>> To: Struts Users Mailing List
>>> Cc: Struts Users Mailing List
>>> Subject: Re: Struts action call in a JS method returns blank page
>>>
>>> Theres a ton of choice on which AJAX library to use, many of them
> very
>>> good.  However, since your working in Java specifically, and since
> you
>>> say
>>> you are not all that familiar with JS, you may prefer a solution that
>>> will
>>> (in most cases) require ZERO Javascript coding, and such a thing
>> exists:
> http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/tagl
>>> ib/package-summary.html
>>>
>>> This is the AjaxParts Taglib (APT), which is a part of Java Web Parts
>>> (JWP):
>>>
>>> http://javawebparts.sourceforge.net
>>>
>>> With this, let's say you want to update a specific <div> in response
>> to
>>> a
>>> button being clicked on a page with some data returned by the server
>>> without refreshing the page, in your JSP you would have:
>>>
>>> <div id="myDiv">Response will go here</div>
>>> <input type="button" value="Click for AJAX"><ajax:event
>>> ajaxRef="ajaxFunctions/button1" />
>>> <ajax:enable />
>>>
>>> That's it, no JavaScript at all!  The other piece to the puzzle is an
>>> XML
>>> file like so:
>>>
>>> <ajaxConfig>
>>>   <group ajaxRef="ajaxFunctions">
>>>     <element ajaxRef="button1">
>>>        <event type="onClick">
>>>          <requestHandler type="std:SimpleRequest" target="/myURL">
>>>            <parameter></parameter>
>>>         </requestHandler>
>>>         <responseHandler type="std:InnerHTML">
>>>           <parameter>myDiv</parameter>
>>>         </responseHandler>
>>>       </event>
>>>     </element>
>>>   </group>
>>> </ajaxConfig>
>>>
>>> The XML file maps via the ajaxRef values to the ajaxRef in the
>>> <ajax:event> tag, and it defines what's going to happen in response
> to
>>> some event (onClick in this case), which in this case is simply an
>> AJAX
>>> request to /myURL with no data passed, and then what happens when the
>>> response comes back, which is it will be inserted into myDiv via
>>> innerHTML.
>>>
>>> There's a whole bunch of request and response handlers available out
>> of
>>> the box which tend to cover most needs, things like submitting forms,
>>> executing some returned Javascript, sending XML automatically
>>> constructed
>>> from form data, transforming returned XML via XLT, and so on.  You
>> also
>>> have the ability to write your own handlers (just plain Javascript)
> if
>>> you
>>> need something that isn't covered.
>>>
>>> hth,
>>> Frank
>>>
>>>
>>> --
>>> Frank W. Zammetti
>>> Founder and Chief Software Architect
>>> Omnytex Technologies
>>> http://www.omnytex.com
>>> AIM/Yahoo: fzammetti
>>> MSN: fzammetti@hotmail.com
>>> Author of "Practical Ajax Projects With Java Technology"
>>>  (2006, Apress, ISBN 1-59059-695-1)
>>> Java Web Parts - http://javawebparts.sourceforge.net
>>>  Supplying the wheel, so you don't have to reinvent it!
>>>
>>> On Thu, February 8, 2007 9:49 am, Musachy Barroso wrote:
>>>> Check Prototype out, here is a good tutorial:
>>>> http://www.sergiopereira.com/articles/prototype.js.html, basically
>>> what
>>>> you need is something like:
>>>>
>>>> |**var myAjax = new Ajax.Request(
>>>> 			url,
>>>> 			{
>>>> 				method: 'get',
>>>> 				parameters: Form.serialize("formid"),
>>>> 				onComplete: function() {
>>>> 				    //do something here, or not :)
>>>> 				}
>>>> 			});**|
>>>>
>>>> regards
>>>> musachy
>>>>
>>>> Christopher Loschen wrote:
>>>>> I'm not all that familiar with JS, to be honest, and I've never had
>>> the
>>>>> chance to use Ajax (but want to learn). What I have now is working,
>>> but
>>>>> I'd be happy to learn how to do it without refreshing the page --
>>> that
>>>>> does seem like a more elegant solution to me. What do you suggest?
>> We
>>> do
>>>>> use JS for our app, but no JS framework as such as far as I can
>> tell.
>>>>> Chris
>>>>>
>>>>> -----Original Message-----
>>>>> From: Musachy Barroso [mailto:musachy@gmail.com]
>>>>> Sent: Thursday, February 08, 2007 8:03 AM
>>>>> To: Struts Users Mailing List
>>>>> Subject: Re: Struts action call in a JS method returns blank page
>>>>>
>>>>> Like I said before you can use Ajax to submit the form, and the
> page
>>>>> won't
>>>>> refresh, how to do it depends on what JS framework you are using,
> if
>>>>> any.
>>>>>
>>>>> regards
>>>>> musachy
>>>>>
>>>>> On 2/8/07, Christopher Loschen <CL...@axeda.com> wrote:
>>>>>
>>>>>> Yes, you're right that the form submit was causing the system to
>>>>>>
>>>>> forward
>>>>>
>>>>>> to whatever the action said, which in my case was the blank page.
>>>>>>
>>>>> You'll see
>>>>>
>>>>>> from the later emails in the thread yesterday that I solved that
> by
>>>>>> forwarding to the action which populated the original page.
>>>>>>
>>>>>> I need the form.submit because I need to get the checked boxes
> from
>>>>> the
>>>>>
>>>>>> form and I need to call the action specified in the action
>> attribute
>>>>> on that
>>>>>
>>>>>> form in order to put those checkbox values into the request in the
>>>>>>
>>>>> form that
>>>>>
>>>>>> my downstream code needs.
>>>>>>
>>>>>> Submitting the form is the only way I know to get the form values
>>> the
>>>>> user
>>>>>
>>>>>> submits from the HTML page to my Java code -- are you saying that
> I
>>>>> have
>>>>>
>>>>>> other alternatives?
>>>>>>
>>>>>> Chris
>>>>>>
>>>>>> ________________________________
>>>>>>
>>>>>> From: Yee Kai Lai [mailto:yeekai.lai@hotmail.com]
>>>>>> Sent: Thu 2/8/2007 12:24 AM
>>>>>> To: user@struts.apache.org
>>>>>> Subject: RE: Struts action call in a JS method returns blank page
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> It returns a blank page might be due to
>>>>>>
>>>>>> form.submit(); in your JS.
>>>>>>
>>>>>> I think if you have a form named
>>>>>>
>>>>> 'service.device.selected-devices-form'
>>>>>
>>>>>> then
>>>>>> it will never be null hence it will always submit.
>>>>>>
>>>>>> May you could enlightened why u need a form.submit() ?
>>>>>>
>>>>>>
>>>>>>
>>>>>>> From: "Christopher Loschen" <CL...@axeda.com>
>>>>>>> Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>>>>>>> To: <us...@struts.apache.org>
>>>>>>> Subject: Struts action call in a JS method returns blank page
>>>>>>> Date: Wed, 7 Feb 2007 14:14:35 -0500
>>>>>>>
>>>>>>> Hi all,
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> I'm honestly unsure if I'm having a problem with Struts (sadly,
>>> 1.1)
>>>>> or
>>>>>
>>>>>>> with Javascript, or something else. But my best guess is it's a
>>>>>>>
>>>>> Struts
>>>>>
>>>>>>> issue, and anyway, there are a lot of very knowledgeable people
> on
>>>>> both
>>>>>
>>>>>>> of those technologies here, so I hope someone can help. Bottom
>>> line:
>>>>> I'm
>>>>>
>>>>>>> getting the popup with the correct values, but my main page under
>>> the
>>>>>>> popup becomes blank.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> I'm adding some functionality to an existing application. The
>>>>>>> functionality I'm adding takes the values from some checkboxes on
>>>>>>>
>>>>> page
>>>>>
>>>>>>> A, gets the corresponding devices from the checkbox values, and
>>> saves
>>>>>>> the resulting List into the request. Later down the stream, other
>>>>>>>
>>>>> code
>>>>>
>>>>>>> gets those values again and uses them as a list of devices on
>> which
>>>>> to
>>>>>
>>>>>>> perform an action. Pretty straightforward.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> All of the actual navigation is happening via Javascript calls,
>>>>>>>
>>>>> starting
>>>>>
>>>>>>> with a link on page A, but outside the form where my checkboxes
>> are
>>>>>>> declared. That link fires a Javascript function which pops up a
>>> small
>>>>>>> window with a list of actions which have been defined. If the
> user
>>>>> then
>>>>>
>>>>>>> clicks on one of those actions, another Javascript function fires
>>>>>>>
>>>>> which
>>>>>
>>>>>>> pops up another window to confirm that the user wants to perform
>>> the
>>>>>>> selected action on the selected devices.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> I have inserted my added functionality into that second script.
>>>>>>> Basically I need to submit the appropriate form on the page. I've
>>>>>>> defined it with the correct action and I've got a mapping in my
>>>>>>> struts-config.xml file:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>     <form-bean
>>>>>>>
>>>>>>>      name="service.device.selected-devices-form"
>>>>>>>
>>>>>>>      type="com.xxx.webapp.common.CheckboxForm"/>
>>>>>>>
>>>>>>> ...
>>>>>>>
>>>>>>>     <action path="/service/device/actions/store-selected-devices"
>>>>>>>
>>>>>>>
>>>>>>> type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
>>>>>>>
>>>>>>>             name="service.device.selected-devices-form" />
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> The mapping doesn't have any action forwards defined because it
>>>>>>>
>>>>> doesn't
>>>>>
>>>>>>> actually need to go anywhere (though that might be part of my
>>>>>>>
>>>>> problem).
>>>>>
>>>>>>> The JS function looks like this:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> function popActionConfirm(url) {
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>   var form =
>>> document.forms['service.device.selected-devices-form'];
>>>>>>>   if (form!=null) form.submit();
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>   var winl = (screen.width - 500) / 2;
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>   var wint = (screen.height - 350) / 2;
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>     winprops =
>>>>>>>
> 'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable
>>>>> =
>>>>>
>>>>>>> 0';
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>   var child = window.open(url,"action_confirm", winprops);
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>   self.name="main_window";
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> I added the first two lines of the JS method - it worked
> correctly
>>>>>>> before I put those in (though of course it didn't have my added
>>>>>>> functionality in place). The popup window does appear, and it has
>>> the
>>>>>>> correct values in it (that is, the devices which were selected).
>>> But
>>>>> the
>>>>>
>>>>>>> main window goes blank where before it remained unchanged. When
>>> I've
>>>>>>> seen blank pages like this before, it meant there was a bad
> action
>>>>>>> forward in the struts-config file, but I don't want the main page
>>> to
>>>>>>> change at all, so what I really want is for the main page to just
>>>>>>>
>>>>> stay
>>>>>
>>>>>>> in place as it was before the form was submitted.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> How do I go about doing that? Thanks!
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Chris Loschen
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> _________________________________________________________________
>>>>>> Receive MSN Hotmail alerts over SMS!
>>>>>> http://en-asiasms.mobile.msn.com/ac.aspx?cid=1002
>>>>>>
>>>>>>
>>>>>>
>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>>
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
  (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
  Supplying the wheel, so you don't have to reinvent it!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts action call in a JS method returns blank page

Posted by Christopher Loschen <CL...@axeda.com>.
I may be getting way off-topic at this point -- sorry about that. I'm
not sure where to ask these sorts of questions.

I now seem to be crashing Firebug and Firefox underneath it every time I
run it. I walk through the method line by line:

function addCheckBoxValuesToForm(locationStr) {
  var checkForm = document.forms['checkbox-form'];
  if (checkForm) {
    var checkboxes_across = new Array();
    var selectedCheckBoxes = new Array();
    var boxesAcross = checkForm.elements['checkbox_ids_across'].value;

On that last line, everything crashes and I get the message that
"Firefox has to close -- sorry for the inconvenience and tell Microsoft
about it so we can gloat." (or something like that ;).

On the previous lines, I did find a checkForm correctly, so it does find
the correct form, but the array of elements for the form is showing up
as empty. I suppose I could test if boxesAcross is null before trying to
get its value, but it shouldn't be null to begin with.

The especially strange thing is that this method is running fine:

function checkSelectedCheckBoxes() {
  var checkForm = document.forms['checkbox-form'];
  if (checkForm) {
    var selectedCheckBoxValues =
checkForm.elements['checkbox_ids_across'].value;

  // if there are no check boxes then just ignore
    if(selectedCheckBoxValues == '') {
        return ;
    }

This is called against the same form as the first one, and looks for the
same input element inside it. When the second one is called, there isn't
anything in that element yet so we just return, and the rest of the
method (which I haven't included here) doesn't run, but that's correct.

When the second method runs, it finds the same form in the same way, but
it also finds all of the elements inside it. I'm not sure what could be
different between them. I'm tearing my hair out!!!

Any insights?

Chris

-----Original Message-----
From: Christopher Loschen [mailto:CLoschen@axeda.com] 
Sent: Friday, February 09, 2007 4:32 PM
To: Struts Users Mailing List
Subject: RE: Struts action call in a JS method returns blank page

OK, I've installed Firebug and also Firefox (a good thing since we
support it anyway, so it's good to have it on my system). It did find
some stuff I missed right away including the JS error on page load
(which turned out to be in a method I hadn't showed you -- oops!). 

But I'm still not getting any results, and I'm not sure why. My JS
function gets the form OK and the action, name, etc. are all correct.
But the form in the debugger has no elements and no child nodes, while
my form on the page has this code:

<input type="hidden" name="checkbox_ids_across" value="">
...
<input type="checkbox" name="checkboxes" value="32">
Etc.

So I would expect I would have at least a string for checkbox_ids_across
and an array of strings for the checkboxes. Is that right? I must be
missing something.

The bit of code I'm looking at so far is:

function addCheckBoxValuesToForm(locationStr)
{
 var form = document.forms['checkbox-form'];
 if (form){
 var checkboxes_across = new Array();
 var selectedCheckBoxes = new Array();
 var formCheckboxAcross = form.elements['checkbox_ids_across'];
 if(formCheckboxAcross!=null && formCheckboxAcross!="") {
 selectedCheckBoxes = formCheckboxAcross;
 }
 if (selectedCheckBoxes.length > 0) {
 checkboxes_across.push(selectedCheckboxes);
 }

 var checkboxes = form.elements['checkboxes'];

Chris

-----Original Message-----
From: Frank W. Zammetti [mailto:fzlists@omnytex.com] 
Sent: Friday, February 09, 2007 3:35 PM
To: Struts Users Mailing List
Subject: Re: Struts action call in a JS method returns blank page

Yeah, as musachy suggests, Firebug is your friend :)  I personally tend 
to code my JS to always go after specific IDs rather than using any of 
the common collections... that usually works just fine as long as you 
don't have multiple dynamic forms.

Frank

Christopher Loschen wrote:
> Happy to provide an opportunity for self-promotion :-)!
> 
> I think you're right about dropping the params somewhere. I've been
> trying today to set up a new approach, which seems simpler to me, but
> which is still fighting me. The basic idea is to use the form to hold
> the array of values I need rather than just sticking them up onto the
> URL. To that end, I rewrote the JS function like this:
> 
> function addCheckBoxValuesToForm(locationStr)
> {
>   var form = document['checkbox-form'];
>   if (form){
>     var checkboxes_across = new Array();
>     var selectedCheckBoxes = new Array();
>     var formCheckboxAcross = form.elements['checkbox_ids_across'];
>     if(formCheckboxAcross!=null && formCheckboxAcross!="") {
>       selectedCheckBoxes = formCheckboxAcross;
>     }
>     if (selectedCheckBoxes.length > 0) {
>       checkboxes_across.push(selectedCheckboxes);
>     }
>     
>     var checkboxes = form.elements['checkboxes'];
>     if (checkboxes)
>     {
>       var checkStr = new Array();
>       var uncheckedStr = new Array();
>       
>       // If the no.of checkboxes is one then converting the checkbox
> object to
>       // Checkbox array.
>       if(checkboxes.type == "checkbox")
>       {
>         checkboxes = [checkboxes];
>       }
> 
>       for (var i = 0; i < checkboxes.length; ++i)
>       {
>         if (checkboxes[i].checked)
>         {
>           checkStr.push(checkboxes[i].value);
>         }
>         else
>         {
>            uncheckedStr.push(checkboxes[i].value);
>         }
>       }
>       if (checkStr.length > 0)
>       {
>         form.elements['checkbox_id'] = checkStr;
>         checkboxes_across.push(checkStr);
>       }
>       if (uncheckedStr.length > 0)
>       {
>         form.elements['uncheckbox_id'] = uncheckedStr;
>       }
>     }
>     form.elements['checkbox_ids_across'].value = checkboxes_across;
>   }
>   
>   document.location.href = locationStr;
> }
> 
> I've got appropriate setters and getters in my Java form (I think,
> though I have to use Identifier[] objects rather than String[], so I
> might need to convert that), and I also added a hidden field
> "checkbox_ids_across" into my form on the JSP form. But I'm still
> getting a JS error when I open the page that "checkbox_ids_across" is
> null or not an object, and it's still not doing what it's supposed to
> do.
> 
> Any suggestions? Thanks!
> 
> Chris
> 
> -----Original Message-----
> From: Frank W. Zammetti [mailto:fzlists@omnytex.com] 
> Sent: Thursday, February 08, 2007 5:30 PM
> To: Struts Users Mailing List
> Cc: Struts Users Mailing List
> Subject: RE: Struts action call in a JS method returns blank page
> 
> On Thu, February 8, 2007 4:46 pm, Christopher Loschen wrote:
>> Thanks Frank -- I've been reading your posts on JWP with great
> interest
>> for quite a while, and I'll bet your book is another good resource.
> 
> *Of course* it is :) (what, you expected a different answer?!?)  FYI,
my
> new book, "Practical JavaScript, DOM Scripting and Ajax Projects", is
> scheduled to hit shelves in mid-April (never pass up the chance for a
> little shameless self-promotion I've been told!)
> 
>> The current project (or at least this piece of it) has to be finished
> by
>> tomorrow, so I may not be able to introduce Ajax just yet. However,
> I'm
>> definitely interested in learning more about it, and will no doubt
use
>> it more as I learn more.
> 
> Sounds good.  I'd say it's not generally something you want to jump
into
> on a tight deadline if you have't done as much client-side
> development...
> many good Java developers have a bit of a rough time early on when
> trying
> to do more client-side stuff... seems like it should be simpler most
> say,
> but it isn't usually :)
> 
>> Meanwhile, I'm looking at a possibly related problem. We've got
>> checkboxes on multiple pages and a JS function which keeps track of
>> which boxes are checked on which page so that we can go from page to
>> page and retain the boxes checked on other pages. That works by
> putting
>> the checkbox ids into the URL for the page. It's working correctly,
> more
>> or less, but now I find that when I actually am ready to use the
array
>> of checkboxes, I'm getting only the ones on the current page, not the
>> rest. My Java method is getting the correct request parameters, but
it
>> always returns null. Perhaps that's because the request parameters
are
>> associated with one action (which displays the appropriate page of
the
>> list) and my action class is associated with a different action (to
>> store the checkbox values and process the result)? If that's right, I
>> guess I need to get those values into my action too. Does that sound
>> like a reasonable guess?
> 
> Hmm... I'm not sure I followed the whole thing, but it sure sounds
like
> your dropping the params somewhere... my guess is that you aren't
> replicating the whole query string with each request, which you'd need
> to
> do.
> 
> However, I'd definitely say you probably want to be storing that info
in
> session in the first place... then it's relatively easy to pass it
along
> with every single request for all pages that need it.
> 
>> Chris
>>
>> -----Original Message-----
>> From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
>> Sent: Thursday, February 08, 2007 10:30 AM
>> To: Struts Users Mailing List
>> Cc: Struts Users Mailing List
>> Subject: Re: Struts action call in a JS method returns blank page
>>
>> Theres a ton of choice on which AJAX library to use, many of them
very
>> good.  However, since your working in Java specifically, and since
you
>> say
>> you are not all that familiar with JS, you may prefer a solution that
>> will
>> (in most cases) require ZERO Javascript coding, and such a thing
> exists:
>>
>
http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/tagl
>> ib/package-summary.html
>>
>> This is the AjaxParts Taglib (APT), which is a part of Java Web Parts
>> (JWP):
>>
>> http://javawebparts.sourceforge.net
>>
>> With this, let's say you want to update a specific <div> in response
> to
>> a
>> button being clicked on a page with some data returned by the server
>> without refreshing the page, in your JSP you would have:
>>
>> <div id="myDiv">Response will go here</div>
>> <input type="button" value="Click for AJAX"><ajax:event
>> ajaxRef="ajaxFunctions/button1" />
>> <ajax:enable />
>>
>> That's it, no JavaScript at all!  The other piece to the puzzle is an
>> XML
>> file like so:
>>
>> <ajaxConfig>
>>   <group ajaxRef="ajaxFunctions">
>>     <element ajaxRef="button1">
>>        <event type="onClick">
>>          <requestHandler type="std:SimpleRequest" target="/myURL">
>>            <parameter></parameter>
>>         </requestHandler>
>>         <responseHandler type="std:InnerHTML">
>>           <parameter>myDiv</parameter>
>>         </responseHandler>
>>       </event>
>>     </element>
>>   </group>
>> </ajaxConfig>
>>
>> The XML file maps via the ajaxRef values to the ajaxRef in the
>> <ajax:event> tag, and it defines what's going to happen in response
to
>> some event (onClick in this case), which in this case is simply an
> AJAX
>> request to /myURL with no data passed, and then what happens when the
>> response comes back, which is it will be inserted into myDiv via
>> innerHTML.
>>
>> There's a whole bunch of request and response handlers available out
> of
>> the box which tend to cover most needs, things like submitting forms,
>> executing some returned Javascript, sending XML automatically
>> constructed
>> from form data, transforming returned XML via XLT, and so on.  You
> also
>> have the ability to write your own handlers (just plain Javascript)
if
>> you
>> need something that isn't covered.
>>
>> hth,
>> Frank
>>
>>
>> --
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>> AIM/Yahoo: fzammetti
>> MSN: fzammetti@hotmail.com
>> Author of "Practical Ajax Projects With Java Technology"
>>  (2006, Apress, ISBN 1-59059-695-1)
>> Java Web Parts - http://javawebparts.sourceforge.net
>>  Supplying the wheel, so you don't have to reinvent it!
>>
>> On Thu, February 8, 2007 9:49 am, Musachy Barroso wrote:
>>> Check Prototype out, here is a good tutorial:
>>> http://www.sergiopereira.com/articles/prototype.js.html, basically
>> what
>>> you need is something like:
>>>
>>> |**var myAjax = new Ajax.Request(
>>> 			url,
>>> 			{
>>> 				method: 'get',
>>> 				parameters: Form.serialize("formid"),
>>> 				onComplete: function() {
>>> 				    //do something here, or not :)
>>> 				}
>>> 			});**|
>>>
>>> regards
>>> musachy
>>>
>>> Christopher Loschen wrote:
>>>> I'm not all that familiar with JS, to be honest, and I've never had
>> the
>>>> chance to use Ajax (but want to learn). What I have now is working,
>> but
>>>> I'd be happy to learn how to do it without refreshing the page --
>> that
>>>> does seem like a more elegant solution to me. What do you suggest?
> We
>> do
>>>> use JS for our app, but no JS framework as such as far as I can
> tell.
>>>> Chris
>>>>
>>>> -----Original Message-----
>>>> From: Musachy Barroso [mailto:musachy@gmail.com]
>>>> Sent: Thursday, February 08, 2007 8:03 AM
>>>> To: Struts Users Mailing List
>>>> Subject: Re: Struts action call in a JS method returns blank page
>>>>
>>>> Like I said before you can use Ajax to submit the form, and the
page
>>>> won't
>>>> refresh, how to do it depends on what JS framework you are using,
if
>>>> any.
>>>>
>>>> regards
>>>> musachy
>>>>
>>>> On 2/8/07, Christopher Loschen <CL...@axeda.com> wrote:
>>>>
>>>>> Yes, you're right that the form submit was causing the system to
>>>>>
>>>> forward
>>>>
>>>>> to whatever the action said, which in my case was the blank page.
>>>>>
>>>> You'll see
>>>>
>>>>> from the later emails in the thread yesterday that I solved that
by
>>>>> forwarding to the action which populated the original page.
>>>>>
>>>>> I need the form.submit because I need to get the checked boxes
from
>>>>>
>>>> the
>>>>
>>>>> form and I need to call the action specified in the action
> attribute
>>>> on that
>>>>
>>>>> form in order to put those checkbox values into the request in the
>>>>>
>>>> form that
>>>>
>>>>> my downstream code needs.
>>>>>
>>>>> Submitting the form is the only way I know to get the form values
>> the
>>>> user
>>>>
>>>>> submits from the HTML page to my Java code -- are you saying that
I
>>>>>
>>>> have
>>>>
>>>>> other alternatives?
>>>>>
>>>>> Chris
>>>>>
>>>>> ________________________________
>>>>>
>>>>> From: Yee Kai Lai [mailto:yeekai.lai@hotmail.com]
>>>>> Sent: Thu 2/8/2007 12:24 AM
>>>>> To: user@struts.apache.org
>>>>> Subject: RE: Struts action call in a JS method returns blank page
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> It returns a blank page might be due to
>>>>>
>>>>> form.submit(); in your JS.
>>>>>
>>>>> I think if you have a form named
>>>>>
>>>> 'service.device.selected-devices-form'
>>>>
>>>>> then
>>>>> it will never be null hence it will always submit.
>>>>>
>>>>> May you could enlightened why u need a form.submit() ?
>>>>>
>>>>>
>>>>>
>>>>>> From: "Christopher Loschen" <CL...@axeda.com>
>>>>>> Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>>>>>> To: <us...@struts.apache.org>
>>>>>> Subject: Struts action call in a JS method returns blank page
>>>>>> Date: Wed, 7 Feb 2007 14:14:35 -0500
>>>>>>
>>>>>> Hi all,
>>>>>>
>>>>>>
>>>>>>
>>>>>> I'm honestly unsure if I'm having a problem with Struts (sadly,
>> 1.1)
>>>> or
>>>>
>>>>>> with Javascript, or something else. But my best guess is it's a
>>>>>>
>>>> Struts
>>>>
>>>>>> issue, and anyway, there are a lot of very knowledgeable people
on
>>>>>>
>>>> both
>>>>
>>>>>> of those technologies here, so I hope someone can help. Bottom
>> line:
>>>> I'm
>>>>
>>>>>> getting the popup with the correct values, but my main page under
>> the
>>>>>> popup becomes blank.
>>>>>>
>>>>>>
>>>>>>
>>>>>> I'm adding some functionality to an existing application. The
>>>>>> functionality I'm adding takes the values from some checkboxes on
>>>>>>
>>>> page
>>>>
>>>>>> A, gets the corresponding devices from the checkbox values, and
>> saves
>>>>>> the resulting List into the request. Later down the stream, other
>>>>>>
>>>> code
>>>>
>>>>>> gets those values again and uses them as a list of devices on
> which
>>>> to
>>>>
>>>>>> perform an action. Pretty straightforward.
>>>>>>
>>>>>>
>>>>>>
>>>>>> All of the actual navigation is happening via Javascript calls,
>>>>>>
>>>> starting
>>>>
>>>>>> with a link on page A, but outside the form where my checkboxes
> are
>>>>>> declared. That link fires a Javascript function which pops up a
>> small
>>>>>> window with a list of actions which have been defined. If the
user
>>>>>>
>>>> then
>>>>
>>>>>> clicks on one of those actions, another Javascript function fires
>>>>>>
>>>> which
>>>>
>>>>>> pops up another window to confirm that the user wants to perform
>> the
>>>>>> selected action on the selected devices.
>>>>>>
>>>>>>
>>>>>>
>>>>>> I have inserted my added functionality into that second script.
>>>>>> Basically I need to submit the appropriate form on the page. I've
>>>>>> defined it with the correct action and I've got a mapping in my
>>>>>> struts-config.xml file:
>>>>>>
>>>>>>
>>>>>>
>>>>>>     <form-bean
>>>>>>
>>>>>>      name="service.device.selected-devices-form"
>>>>>>
>>>>>>      type="com.xxx.webapp.common.CheckboxForm"/>
>>>>>>
>>>>>> ...
>>>>>>
>>>>>>     <action path="/service/device/actions/store-selected-devices"
>>>>>>
>>>>>>
>>>>>> type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
>>>>>>
>>>>>>             name="service.device.selected-devices-form" />
>>>>>>
>>>>>>
>>>>>>
>>>>>> The mapping doesn't have any action forwards defined because it
>>>>>>
>>>> doesn't
>>>>
>>>>>> actually need to go anywhere (though that might be part of my
>>>>>>
>>>> problem).
>>>>
>>>>>> The JS function looks like this:
>>>>>>
>>>>>>
>>>>>>
>>>>>> function popActionConfirm(url) {
>>>>>>
>>>>>>
>>>>>>
>>>>>>   var form =
>> document.forms['service.device.selected-devices-form'];
>>>>>>   if (form!=null) form.submit();
>>>>>>
>>>>>>
>>>>>>
>>>>>>   var winl = (screen.width - 500) / 2;
>>>>>>
>>>>>>
>>>>>>
>>>>>>   var wint = (screen.height - 350) / 2;
>>>>>>
>>>>>>
>>>>>>
>>>>>>     winprops =
>>>>>>
>
'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable
>>>> =
>>>>
>>>>>> 0';
>>>>>>
>>>>>>
>>>>>>
>>>>>>   var child = window.open(url,"action_confirm", winprops);
>>>>>>
>>>>>>
>>>>>>
>>>>>>   self.name="main_window";
>>>>>>
>>>>>>
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>> I added the first two lines of the JS method - it worked
correctly
>>>>>> before I put those in (though of course it didn't have my added
>>>>>> functionality in place). The popup window does appear, and it has
>> the
>>>>>> correct values in it (that is, the devices which were selected).
>> But
>>>> the
>>>>
>>>>>> main window goes blank where before it remained unchanged. When
>> I've
>>>>>> seen blank pages like this before, it meant there was a bad
action
>>>>>> forward in the struts-config file, but I don't want the main page
>> to
>>>>>> change at all, so what I really want is for the main page to just
>>>>>>
>>>> stay
>>>>
>>>>>> in place as it was before the form was submitted.
>>>>>>
>>>>>>
>>>>>>
>>>>>> How do I go about doing that? Thanks!
>>>>>>
>>>>>>
>>>>>>
>>>>>> Chris Loschen
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>> _________________________________________________________________
>>>>> Receive MSN Hotmail alerts over SMS!
>>>>> http://en-asiasms.mobile.msn.com/ac.aspx?cid=1002
>>>>>
>>>>>
>>>>>
>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
  (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
  Supplying the wheel, so you don't have to reinvent it!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts action call in a JS method returns blank page

Posted by Christopher Loschen <CL...@axeda.com>.
OK, I've installed Firebug and also Firefox (a good thing since we
support it anyway, so it's good to have it on my system). It did find
some stuff I missed right away including the JS error on page load
(which turned out to be in a method I hadn't showed you -- oops!). 

But I'm still not getting any results, and I'm not sure why. My JS
function gets the form OK and the action, name, etc. are all correct.
But the form in the debugger has no elements and no child nodes, while
my form on the page has this code:

<input type="hidden" name="checkbox_ids_across" value="">
...
<input type="checkbox" name="checkboxes" value="32">
Etc.

So I would expect I would have at least a string for checkbox_ids_across
and an array of strings for the checkboxes. Is that right? I must be
missing something.

The bit of code I'm looking at so far is:

function addCheckBoxValuesToForm(locationStr)
{
 var form = document.forms['checkbox-form'];
 if (form){
 var checkboxes_across = new Array();
 var selectedCheckBoxes = new Array();
 var formCheckboxAcross = form.elements['checkbox_ids_across'];
 if(formCheckboxAcross!=null && formCheckboxAcross!="") {
 selectedCheckBoxes = formCheckboxAcross;
 }
 if (selectedCheckBoxes.length > 0) {
 checkboxes_across.push(selectedCheckboxes);
 }

 var checkboxes = form.elements['checkboxes'];

Chris

-----Original Message-----
From: Frank W. Zammetti [mailto:fzlists@omnytex.com] 
Sent: Friday, February 09, 2007 3:35 PM
To: Struts Users Mailing List
Subject: Re: Struts action call in a JS method returns blank page

Yeah, as musachy suggests, Firebug is your friend :)  I personally tend 
to code my JS to always go after specific IDs rather than using any of 
the common collections... that usually works just fine as long as you 
don't have multiple dynamic forms.

Frank

Christopher Loschen wrote:
> Happy to provide an opportunity for self-promotion :-)!
> 
> I think you're right about dropping the params somewhere. I've been
> trying today to set up a new approach, which seems simpler to me, but
> which is still fighting me. The basic idea is to use the form to hold
> the array of values I need rather than just sticking them up onto the
> URL. To that end, I rewrote the JS function like this:
> 
> function addCheckBoxValuesToForm(locationStr)
> {
>   var form = document['checkbox-form'];
>   if (form){
>     var checkboxes_across = new Array();
>     var selectedCheckBoxes = new Array();
>     var formCheckboxAcross = form.elements['checkbox_ids_across'];
>     if(formCheckboxAcross!=null && formCheckboxAcross!="") {
>       selectedCheckBoxes = formCheckboxAcross;
>     }
>     if (selectedCheckBoxes.length > 0) {
>       checkboxes_across.push(selectedCheckboxes);
>     }
>     
>     var checkboxes = form.elements['checkboxes'];
>     if (checkboxes)
>     {
>       var checkStr = new Array();
>       var uncheckedStr = new Array();
>       
>       // If the no.of checkboxes is one then converting the checkbox
> object to
>       // Checkbox array.
>       if(checkboxes.type == "checkbox")
>       {
>         checkboxes = [checkboxes];
>       }
> 
>       for (var i = 0; i < checkboxes.length; ++i)
>       {
>         if (checkboxes[i].checked)
>         {
>           checkStr.push(checkboxes[i].value);
>         }
>         else
>         {
>            uncheckedStr.push(checkboxes[i].value);
>         }
>       }
>       if (checkStr.length > 0)
>       {
>         form.elements['checkbox_id'] = checkStr;
>         checkboxes_across.push(checkStr);
>       }
>       if (uncheckedStr.length > 0)
>       {
>         form.elements['uncheckbox_id'] = uncheckedStr;
>       }
>     }
>     form.elements['checkbox_ids_across'].value = checkboxes_across;
>   }
>   
>   document.location.href = locationStr;
> }
> 
> I've got appropriate setters and getters in my Java form (I think,
> though I have to use Identifier[] objects rather than String[], so I
> might need to convert that), and I also added a hidden field
> "checkbox_ids_across" into my form on the JSP form. But I'm still
> getting a JS error when I open the page that "checkbox_ids_across" is
> null or not an object, and it's still not doing what it's supposed to
> do.
> 
> Any suggestions? Thanks!
> 
> Chris
> 
> -----Original Message-----
> From: Frank W. Zammetti [mailto:fzlists@omnytex.com] 
> Sent: Thursday, February 08, 2007 5:30 PM
> To: Struts Users Mailing List
> Cc: Struts Users Mailing List
> Subject: RE: Struts action call in a JS method returns blank page
> 
> On Thu, February 8, 2007 4:46 pm, Christopher Loschen wrote:
>> Thanks Frank -- I've been reading your posts on JWP with great
> interest
>> for quite a while, and I'll bet your book is another good resource.
> 
> *Of course* it is :) (what, you expected a different answer?!?)  FYI,
my
> new book, "Practical JavaScript, DOM Scripting and Ajax Projects", is
> scheduled to hit shelves in mid-April (never pass up the chance for a
> little shameless self-promotion I've been told!)
> 
>> The current project (or at least this piece of it) has to be finished
> by
>> tomorrow, so I may not be able to introduce Ajax just yet. However,
> I'm
>> definitely interested in learning more about it, and will no doubt
use
>> it more as I learn more.
> 
> Sounds good.  I'd say it's not generally something you want to jump
into
> on a tight deadline if you have't done as much client-side
> development...
> many good Java developers have a bit of a rough time early on when
> trying
> to do more client-side stuff... seems like it should be simpler most
> say,
> but it isn't usually :)
> 
>> Meanwhile, I'm looking at a possibly related problem. We've got
>> checkboxes on multiple pages and a JS function which keeps track of
>> which boxes are checked on which page so that we can go from page to
>> page and retain the boxes checked on other pages. That works by
> putting
>> the checkbox ids into the URL for the page. It's working correctly,
> more
>> or less, but now I find that when I actually am ready to use the
array
>> of checkboxes, I'm getting only the ones on the current page, not the
>> rest. My Java method is getting the correct request parameters, but
it
>> always returns null. Perhaps that's because the request parameters
are
>> associated with one action (which displays the appropriate page of
the
>> list) and my action class is associated with a different action (to
>> store the checkbox values and process the result)? If that's right, I
>> guess I need to get those values into my action too. Does that sound
>> like a reasonable guess?
> 
> Hmm... I'm not sure I followed the whole thing, but it sure sounds
like
> your dropping the params somewhere... my guess is that you aren't
> replicating the whole query string with each request, which you'd need
> to
> do.
> 
> However, I'd definitely say you probably want to be storing that info
in
> session in the first place... then it's relatively easy to pass it
along
> with every single request for all pages that need it.
> 
>> Chris
>>
>> -----Original Message-----
>> From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
>> Sent: Thursday, February 08, 2007 10:30 AM
>> To: Struts Users Mailing List
>> Cc: Struts Users Mailing List
>> Subject: Re: Struts action call in a JS method returns blank page
>>
>> Theres a ton of choice on which AJAX library to use, many of them
very
>> good.  However, since your working in Java specifically, and since
you
>> say
>> you are not all that familiar with JS, you may prefer a solution that
>> will
>> (in most cases) require ZERO Javascript coding, and such a thing
> exists:
>>
>
http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/tagl
>> ib/package-summary.html
>>
>> This is the AjaxParts Taglib (APT), which is a part of Java Web Parts
>> (JWP):
>>
>> http://javawebparts.sourceforge.net
>>
>> With this, let's say you want to update a specific <div> in response
> to
>> a
>> button being clicked on a page with some data returned by the server
>> without refreshing the page, in your JSP you would have:
>>
>> <div id="myDiv">Response will go here</div>
>> <input type="button" value="Click for AJAX"><ajax:event
>> ajaxRef="ajaxFunctions/button1" />
>> <ajax:enable />
>>
>> That's it, no JavaScript at all!  The other piece to the puzzle is an
>> XML
>> file like so:
>>
>> <ajaxConfig>
>>   <group ajaxRef="ajaxFunctions">
>>     <element ajaxRef="button1">
>>        <event type="onClick">
>>          <requestHandler type="std:SimpleRequest" target="/myURL">
>>            <parameter></parameter>
>>         </requestHandler>
>>         <responseHandler type="std:InnerHTML">
>>           <parameter>myDiv</parameter>
>>         </responseHandler>
>>       </event>
>>     </element>
>>   </group>
>> </ajaxConfig>
>>
>> The XML file maps via the ajaxRef values to the ajaxRef in the
>> <ajax:event> tag, and it defines what's going to happen in response
to
>> some event (onClick in this case), which in this case is simply an
> AJAX
>> request to /myURL with no data passed, and then what happens when the
>> response comes back, which is it will be inserted into myDiv via
>> innerHTML.
>>
>> There's a whole bunch of request and response handlers available out
> of
>> the box which tend to cover most needs, things like submitting forms,
>> executing some returned Javascript, sending XML automatically
>> constructed
>> from form data, transforming returned XML via XLT, and so on.  You
> also
>> have the ability to write your own handlers (just plain Javascript)
if
>> you
>> need something that isn't covered.
>>
>> hth,
>> Frank
>>
>>
>> --
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>> AIM/Yahoo: fzammetti
>> MSN: fzammetti@hotmail.com
>> Author of "Practical Ajax Projects With Java Technology"
>>  (2006, Apress, ISBN 1-59059-695-1)
>> Java Web Parts - http://javawebparts.sourceforge.net
>>  Supplying the wheel, so you don't have to reinvent it!
>>
>> On Thu, February 8, 2007 9:49 am, Musachy Barroso wrote:
>>> Check Prototype out, here is a good tutorial:
>>> http://www.sergiopereira.com/articles/prototype.js.html, basically
>> what
>>> you need is something like:
>>>
>>> |**var myAjax = new Ajax.Request(
>>> 			url,
>>> 			{
>>> 				method: 'get',
>>> 				parameters: Form.serialize("formid"),
>>> 				onComplete: function() {
>>> 				    //do something here, or not :)
>>> 				}
>>> 			});**|
>>>
>>> regards
>>> musachy
>>>
>>> Christopher Loschen wrote:
>>>> I'm not all that familiar with JS, to be honest, and I've never had
>> the
>>>> chance to use Ajax (but want to learn). What I have now is working,
>> but
>>>> I'd be happy to learn how to do it without refreshing the page --
>> that
>>>> does seem like a more elegant solution to me. What do you suggest?
> We
>> do
>>>> use JS for our app, but no JS framework as such as far as I can
> tell.
>>>> Chris
>>>>
>>>> -----Original Message-----
>>>> From: Musachy Barroso [mailto:musachy@gmail.com]
>>>> Sent: Thursday, February 08, 2007 8:03 AM
>>>> To: Struts Users Mailing List
>>>> Subject: Re: Struts action call in a JS method returns blank page
>>>>
>>>> Like I said before you can use Ajax to submit the form, and the
page
>>>> won't
>>>> refresh, how to do it depends on what JS framework you are using,
if
>>>> any.
>>>>
>>>> regards
>>>> musachy
>>>>
>>>> On 2/8/07, Christopher Loschen <CL...@axeda.com> wrote:
>>>>
>>>>> Yes, you're right that the form submit was causing the system to
>>>>>
>>>> forward
>>>>
>>>>> to whatever the action said, which in my case was the blank page.
>>>>>
>>>> You'll see
>>>>
>>>>> from the later emails in the thread yesterday that I solved that
by
>>>>> forwarding to the action which populated the original page.
>>>>>
>>>>> I need the form.submit because I need to get the checked boxes
from
>>>>>
>>>> the
>>>>
>>>>> form and I need to call the action specified in the action
> attribute
>>>> on that
>>>>
>>>>> form in order to put those checkbox values into the request in the
>>>>>
>>>> form that
>>>>
>>>>> my downstream code needs.
>>>>>
>>>>> Submitting the form is the only way I know to get the form values
>> the
>>>> user
>>>>
>>>>> submits from the HTML page to my Java code -- are you saying that
I
>>>>>
>>>> have
>>>>
>>>>> other alternatives?
>>>>>
>>>>> Chris
>>>>>
>>>>> ________________________________
>>>>>
>>>>> From: Yee Kai Lai [mailto:yeekai.lai@hotmail.com]
>>>>> Sent: Thu 2/8/2007 12:24 AM
>>>>> To: user@struts.apache.org
>>>>> Subject: RE: Struts action call in a JS method returns blank page
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> It returns a blank page might be due to
>>>>>
>>>>> form.submit(); in your JS.
>>>>>
>>>>> I think if you have a form named
>>>>>
>>>> 'service.device.selected-devices-form'
>>>>
>>>>> then
>>>>> it will never be null hence it will always submit.
>>>>>
>>>>> May you could enlightened why u need a form.submit() ?
>>>>>
>>>>>
>>>>>
>>>>>> From: "Christopher Loschen" <CL...@axeda.com>
>>>>>> Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>>>>>> To: <us...@struts.apache.org>
>>>>>> Subject: Struts action call in a JS method returns blank page
>>>>>> Date: Wed, 7 Feb 2007 14:14:35 -0500
>>>>>>
>>>>>> Hi all,
>>>>>>
>>>>>>
>>>>>>
>>>>>> I'm honestly unsure if I'm having a problem with Struts (sadly,
>> 1.1)
>>>> or
>>>>
>>>>>> with Javascript, or something else. But my best guess is it's a
>>>>>>
>>>> Struts
>>>>
>>>>>> issue, and anyway, there are a lot of very knowledgeable people
on
>>>>>>
>>>> both
>>>>
>>>>>> of those technologies here, so I hope someone can help. Bottom
>> line:
>>>> I'm
>>>>
>>>>>> getting the popup with the correct values, but my main page under
>> the
>>>>>> popup becomes blank.
>>>>>>
>>>>>>
>>>>>>
>>>>>> I'm adding some functionality to an existing application. The
>>>>>> functionality I'm adding takes the values from some checkboxes on
>>>>>>
>>>> page
>>>>
>>>>>> A, gets the corresponding devices from the checkbox values, and
>> saves
>>>>>> the resulting List into the request. Later down the stream, other
>>>>>>
>>>> code
>>>>
>>>>>> gets those values again and uses them as a list of devices on
> which
>>>> to
>>>>
>>>>>> perform an action. Pretty straightforward.
>>>>>>
>>>>>>
>>>>>>
>>>>>> All of the actual navigation is happening via Javascript calls,
>>>>>>
>>>> starting
>>>>
>>>>>> with a link on page A, but outside the form where my checkboxes
> are
>>>>>> declared. That link fires a Javascript function which pops up a
>> small
>>>>>> window with a list of actions which have been defined. If the
user
>>>>>>
>>>> then
>>>>
>>>>>> clicks on one of those actions, another Javascript function fires
>>>>>>
>>>> which
>>>>
>>>>>> pops up another window to confirm that the user wants to perform
>> the
>>>>>> selected action on the selected devices.
>>>>>>
>>>>>>
>>>>>>
>>>>>> I have inserted my added functionality into that second script.
>>>>>> Basically I need to submit the appropriate form on the page. I've
>>>>>> defined it with the correct action and I've got a mapping in my
>>>>>> struts-config.xml file:
>>>>>>
>>>>>>
>>>>>>
>>>>>>     <form-bean
>>>>>>
>>>>>>      name="service.device.selected-devices-form"
>>>>>>
>>>>>>      type="com.xxx.webapp.common.CheckboxForm"/>
>>>>>>
>>>>>> ...
>>>>>>
>>>>>>     <action path="/service/device/actions/store-selected-devices"
>>>>>>
>>>>>>
>>>>>> type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
>>>>>>
>>>>>>             name="service.device.selected-devices-form" />
>>>>>>
>>>>>>
>>>>>>
>>>>>> The mapping doesn't have any action forwards defined because it
>>>>>>
>>>> doesn't
>>>>
>>>>>> actually need to go anywhere (though that might be part of my
>>>>>>
>>>> problem).
>>>>
>>>>>> The JS function looks like this:
>>>>>>
>>>>>>
>>>>>>
>>>>>> function popActionConfirm(url) {
>>>>>>
>>>>>>
>>>>>>
>>>>>>   var form =
>> document.forms['service.device.selected-devices-form'];
>>>>>>   if (form!=null) form.submit();
>>>>>>
>>>>>>
>>>>>>
>>>>>>   var winl = (screen.width - 500) / 2;
>>>>>>
>>>>>>
>>>>>>
>>>>>>   var wint = (screen.height - 350) / 2;
>>>>>>
>>>>>>
>>>>>>
>>>>>>     winprops =
>>>>>>
>
'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable
>>>> =
>>>>
>>>>>> 0';
>>>>>>
>>>>>>
>>>>>>
>>>>>>   var child = window.open(url,"action_confirm", winprops);
>>>>>>
>>>>>>
>>>>>>
>>>>>>   self.name="main_window";
>>>>>>
>>>>>>
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>> I added the first two lines of the JS method - it worked
correctly
>>>>>> before I put those in (though of course it didn't have my added
>>>>>> functionality in place). The popup window does appear, and it has
>> the
>>>>>> correct values in it (that is, the devices which were selected).
>> But
>>>> the
>>>>
>>>>>> main window goes blank where before it remained unchanged. When
>> I've
>>>>>> seen blank pages like this before, it meant there was a bad
action
>>>>>> forward in the struts-config file, but I don't want the main page
>> to
>>>>>> change at all, so what I really want is for the main page to just
>>>>>>
>>>> stay
>>>>
>>>>>> in place as it was before the form was submitted.
>>>>>>
>>>>>>
>>>>>>
>>>>>> How do I go about doing that? Thanks!
>>>>>>
>>>>>>
>>>>>>
>>>>>> Chris Loschen
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>> _________________________________________________________________
>>>>> Receive MSN Hotmail alerts over SMS!
>>>>> http://en-asiasms.mobile.msn.com/ac.aspx?cid=1002
>>>>>
>>>>>
>>>>>
>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
  (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
  Supplying the wheel, so you don't have to reinvent it!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts action call in a JS method returns blank page

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Yeah, as musachy suggests, Firebug is your friend :)  I personally tend 
to code my JS to always go after specific IDs rather than using any of 
the common collections... that usually works just fine as long as you 
don't have multiple dynamic forms.

Frank

Christopher Loschen wrote:
> Happy to provide an opportunity for self-promotion :-)!
> 
> I think you're right about dropping the params somewhere. I've been
> trying today to set up a new approach, which seems simpler to me, but
> which is still fighting me. The basic idea is to use the form to hold
> the array of values I need rather than just sticking them up onto the
> URL. To that end, I rewrote the JS function like this:
> 
> function addCheckBoxValuesToForm(locationStr)
> {
>   var form = document['checkbox-form'];
>   if (form){
>     var checkboxes_across = new Array();
>     var selectedCheckBoxes = new Array();
>     var formCheckboxAcross = form.elements['checkbox_ids_across'];
>     if(formCheckboxAcross!=null && formCheckboxAcross!="") {
>       selectedCheckBoxes = formCheckboxAcross;
>     }
>     if (selectedCheckBoxes.length > 0) {
>       checkboxes_across.push(selectedCheckboxes);
>     }
>     
>     var checkboxes = form.elements['checkboxes'];
>     if (checkboxes)
>     {
>       var checkStr = new Array();
>       var uncheckedStr = new Array();
>       
>       // If the no.of checkboxes is one then converting the checkbox
> object to
>       // Checkbox array.
>       if(checkboxes.type == "checkbox")
>       {
>         checkboxes = [checkboxes];
>       }
> 
>       for (var i = 0; i < checkboxes.length; ++i)
>       {
>         if (checkboxes[i].checked)
>         {
>           checkStr.push(checkboxes[i].value);
>         }
>         else
>         {
>            uncheckedStr.push(checkboxes[i].value);
>         }
>       }
>       if (checkStr.length > 0)
>       {
>         form.elements['checkbox_id'] = checkStr;
>         checkboxes_across.push(checkStr);
>       }
>       if (uncheckedStr.length > 0)
>       {
>         form.elements['uncheckbox_id'] = uncheckedStr;
>       }
>     }
>     form.elements['checkbox_ids_across'].value = checkboxes_across;
>   }
>   
>   document.location.href = locationStr;
> }
> 
> I've got appropriate setters and getters in my Java form (I think,
> though I have to use Identifier[] objects rather than String[], so I
> might need to convert that), and I also added a hidden field
> "checkbox_ids_across" into my form on the JSP form. But I'm still
> getting a JS error when I open the page that "checkbox_ids_across" is
> null or not an object, and it's still not doing what it's supposed to
> do.
> 
> Any suggestions? Thanks!
> 
> Chris
> 
> -----Original Message-----
> From: Frank W. Zammetti [mailto:fzlists@omnytex.com] 
> Sent: Thursday, February 08, 2007 5:30 PM
> To: Struts Users Mailing List
> Cc: Struts Users Mailing List
> Subject: RE: Struts action call in a JS method returns blank page
> 
> On Thu, February 8, 2007 4:46 pm, Christopher Loschen wrote:
>> Thanks Frank -- I've been reading your posts on JWP with great
> interest
>> for quite a while, and I'll bet your book is another good resource.
> 
> *Of course* it is :) (what, you expected a different answer?!?)  FYI, my
> new book, "Practical JavaScript, DOM Scripting and Ajax Projects", is
> scheduled to hit shelves in mid-April (never pass up the chance for a
> little shameless self-promotion I've been told!)
> 
>> The current project (or at least this piece of it) has to be finished
> by
>> tomorrow, so I may not be able to introduce Ajax just yet. However,
> I'm
>> definitely interested in learning more about it, and will no doubt use
>> it more as I learn more.
> 
> Sounds good.  I'd say it's not generally something you want to jump into
> on a tight deadline if you have't done as much client-side
> development...
> many good Java developers have a bit of a rough time early on when
> trying
> to do more client-side stuff... seems like it should be simpler most
> say,
> but it isn't usually :)
> 
>> Meanwhile, I'm looking at a possibly related problem. We've got
>> checkboxes on multiple pages and a JS function which keeps track of
>> which boxes are checked on which page so that we can go from page to
>> page and retain the boxes checked on other pages. That works by
> putting
>> the checkbox ids into the URL for the page. It's working correctly,
> more
>> or less, but now I find that when I actually am ready to use the array
>> of checkboxes, I'm getting only the ones on the current page, not the
>> rest. My Java method is getting the correct request parameters, but it
>> always returns null. Perhaps that's because the request parameters are
>> associated with one action (which displays the appropriate page of the
>> list) and my action class is associated with a different action (to
>> store the checkbox values and process the result)? If that's right, I
>> guess I need to get those values into my action too. Does that sound
>> like a reasonable guess?
> 
> Hmm... I'm not sure I followed the whole thing, but it sure sounds like
> your dropping the params somewhere... my guess is that you aren't
> replicating the whole query string with each request, which you'd need
> to
> do.
> 
> However, I'd definitely say you probably want to be storing that info in
> session in the first place... then it's relatively easy to pass it along
> with every single request for all pages that need it.
> 
>> Chris
>>
>> -----Original Message-----
>> From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
>> Sent: Thursday, February 08, 2007 10:30 AM
>> To: Struts Users Mailing List
>> Cc: Struts Users Mailing List
>> Subject: Re: Struts action call in a JS method returns blank page
>>
>> Theres a ton of choice on which AJAX library to use, many of them very
>> good.  However, since your working in Java specifically, and since you
>> say
>> you are not all that familiar with JS, you may prefer a solution that
>> will
>> (in most cases) require ZERO Javascript coding, and such a thing
> exists:
>>
> http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/tagl
>> ib/package-summary.html
>>
>> This is the AjaxParts Taglib (APT), which is a part of Java Web Parts
>> (JWP):
>>
>> http://javawebparts.sourceforge.net
>>
>> With this, let's say you want to update a specific <div> in response
> to
>> a
>> button being clicked on a page with some data returned by the server
>> without refreshing the page, in your JSP you would have:
>>
>> <div id="myDiv">Response will go here</div>
>> <input type="button" value="Click for AJAX"><ajax:event
>> ajaxRef="ajaxFunctions/button1" />
>> <ajax:enable />
>>
>> That's it, no JavaScript at all!  The other piece to the puzzle is an
>> XML
>> file like so:
>>
>> <ajaxConfig>
>>   <group ajaxRef="ajaxFunctions">
>>     <element ajaxRef="button1">
>>        <event type="onClick">
>>          <requestHandler type="std:SimpleRequest" target="/myURL">
>>            <parameter></parameter>
>>         </requestHandler>
>>         <responseHandler type="std:InnerHTML">
>>           <parameter>myDiv</parameter>
>>         </responseHandler>
>>       </event>
>>     </element>
>>   </group>
>> </ajaxConfig>
>>
>> The XML file maps via the ajaxRef values to the ajaxRef in the
>> <ajax:event> tag, and it defines what's going to happen in response to
>> some event (onClick in this case), which in this case is simply an
> AJAX
>> request to /myURL with no data passed, and then what happens when the
>> response comes back, which is it will be inserted into myDiv via
>> innerHTML.
>>
>> There's a whole bunch of request and response handlers available out
> of
>> the box which tend to cover most needs, things like submitting forms,
>> executing some returned Javascript, sending XML automatically
>> constructed
>> from form data, transforming returned XML via XLT, and so on.  You
> also
>> have the ability to write your own handlers (just plain Javascript) if
>> you
>> need something that isn't covered.
>>
>> hth,
>> Frank
>>
>>
>> --
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>> AIM/Yahoo: fzammetti
>> MSN: fzammetti@hotmail.com
>> Author of "Practical Ajax Projects With Java Technology"
>>  (2006, Apress, ISBN 1-59059-695-1)
>> Java Web Parts - http://javawebparts.sourceforge.net
>>  Supplying the wheel, so you don't have to reinvent it!
>>
>> On Thu, February 8, 2007 9:49 am, Musachy Barroso wrote:
>>> Check Prototype out, here is a good tutorial:
>>> http://www.sergiopereira.com/articles/prototype.js.html, basically
>> what
>>> you need is something like:
>>>
>>> |**var myAjax = new Ajax.Request(
>>> 			url,
>>> 			{
>>> 				method: 'get',
>>> 				parameters: Form.serialize("formid"),
>>> 				onComplete: function() {
>>> 				    //do something here, or not :)
>>> 				}
>>> 			});**|
>>>
>>> regards
>>> musachy
>>>
>>> Christopher Loschen wrote:
>>>> I'm not all that familiar with JS, to be honest, and I've never had
>> the
>>>> chance to use Ajax (but want to learn). What I have now is working,
>> but
>>>> I'd be happy to learn how to do it without refreshing the page --
>> that
>>>> does seem like a more elegant solution to me. What do you suggest?
> We
>> do
>>>> use JS for our app, but no JS framework as such as far as I can
> tell.
>>>> Chris
>>>>
>>>> -----Original Message-----
>>>> From: Musachy Barroso [mailto:musachy@gmail.com]
>>>> Sent: Thursday, February 08, 2007 8:03 AM
>>>> To: Struts Users Mailing List
>>>> Subject: Re: Struts action call in a JS method returns blank page
>>>>
>>>> Like I said before you can use Ajax to submit the form, and the page
>>>> won't
>>>> refresh, how to do it depends on what JS framework you are using, if
>>>> any.
>>>>
>>>> regards
>>>> musachy
>>>>
>>>> On 2/8/07, Christopher Loschen <CL...@axeda.com> wrote:
>>>>
>>>>> Yes, you're right that the form submit was causing the system to
>>>>>
>>>> forward
>>>>
>>>>> to whatever the action said, which in my case was the blank page.
>>>>>
>>>> You'll see
>>>>
>>>>> from the later emails in the thread yesterday that I solved that by
>>>>> forwarding to the action which populated the original page.
>>>>>
>>>>> I need the form.submit because I need to get the checked boxes from
>>>>>
>>>> the
>>>>
>>>>> form and I need to call the action specified in the action
> attribute
>>>> on that
>>>>
>>>>> form in order to put those checkbox values into the request in the
>>>>>
>>>> form that
>>>>
>>>>> my downstream code needs.
>>>>>
>>>>> Submitting the form is the only way I know to get the form values
>> the
>>>> user
>>>>
>>>>> submits from the HTML page to my Java code -- are you saying that I
>>>>>
>>>> have
>>>>
>>>>> other alternatives?
>>>>>
>>>>> Chris
>>>>>
>>>>> ________________________________
>>>>>
>>>>> From: Yee Kai Lai [mailto:yeekai.lai@hotmail.com]
>>>>> Sent: Thu 2/8/2007 12:24 AM
>>>>> To: user@struts.apache.org
>>>>> Subject: RE: Struts action call in a JS method returns blank page
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> It returns a blank page might be due to
>>>>>
>>>>> form.submit(); in your JS.
>>>>>
>>>>> I think if you have a form named
>>>>>
>>>> 'service.device.selected-devices-form'
>>>>
>>>>> then
>>>>> it will never be null hence it will always submit.
>>>>>
>>>>> May you could enlightened why u need a form.submit() ?
>>>>>
>>>>>
>>>>>
>>>>>> From: "Christopher Loschen" <CL...@axeda.com>
>>>>>> Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>>>>>> To: <us...@struts.apache.org>
>>>>>> Subject: Struts action call in a JS method returns blank page
>>>>>> Date: Wed, 7 Feb 2007 14:14:35 -0500
>>>>>>
>>>>>> Hi all,
>>>>>>
>>>>>>
>>>>>>
>>>>>> I'm honestly unsure if I'm having a problem with Struts (sadly,
>> 1.1)
>>>> or
>>>>
>>>>>> with Javascript, or something else. But my best guess is it's a
>>>>>>
>>>> Struts
>>>>
>>>>>> issue, and anyway, there are a lot of very knowledgeable people on
>>>>>>
>>>> both
>>>>
>>>>>> of those technologies here, so I hope someone can help. Bottom
>> line:
>>>> I'm
>>>>
>>>>>> getting the popup with the correct values, but my main page under
>> the
>>>>>> popup becomes blank.
>>>>>>
>>>>>>
>>>>>>
>>>>>> I'm adding some functionality to an existing application. The
>>>>>> functionality I'm adding takes the values from some checkboxes on
>>>>>>
>>>> page
>>>>
>>>>>> A, gets the corresponding devices from the checkbox values, and
>> saves
>>>>>> the resulting List into the request. Later down the stream, other
>>>>>>
>>>> code
>>>>
>>>>>> gets those values again and uses them as a list of devices on
> which
>>>> to
>>>>
>>>>>> perform an action. Pretty straightforward.
>>>>>>
>>>>>>
>>>>>>
>>>>>> All of the actual navigation is happening via Javascript calls,
>>>>>>
>>>> starting
>>>>
>>>>>> with a link on page A, but outside the form where my checkboxes
> are
>>>>>> declared. That link fires a Javascript function which pops up a
>> small
>>>>>> window with a list of actions which have been defined. If the user
>>>>>>
>>>> then
>>>>
>>>>>> clicks on one of those actions, another Javascript function fires
>>>>>>
>>>> which
>>>>
>>>>>> pops up another window to confirm that the user wants to perform
>> the
>>>>>> selected action on the selected devices.
>>>>>>
>>>>>>
>>>>>>
>>>>>> I have inserted my added functionality into that second script.
>>>>>> Basically I need to submit the appropriate form on the page. I've
>>>>>> defined it with the correct action and I've got a mapping in my
>>>>>> struts-config.xml file:
>>>>>>
>>>>>>
>>>>>>
>>>>>>     <form-bean
>>>>>>
>>>>>>      name="service.device.selected-devices-form"
>>>>>>
>>>>>>      type="com.xxx.webapp.common.CheckboxForm"/>
>>>>>>
>>>>>> ...
>>>>>>
>>>>>>     <action path="/service/device/actions/store-selected-devices"
>>>>>>
>>>>>>
>>>>>> type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
>>>>>>
>>>>>>             name="service.device.selected-devices-form" />
>>>>>>
>>>>>>
>>>>>>
>>>>>> The mapping doesn't have any action forwards defined because it
>>>>>>
>>>> doesn't
>>>>
>>>>>> actually need to go anywhere (though that might be part of my
>>>>>>
>>>> problem).
>>>>
>>>>>> The JS function looks like this:
>>>>>>
>>>>>>
>>>>>>
>>>>>> function popActionConfirm(url) {
>>>>>>
>>>>>>
>>>>>>
>>>>>>   var form =
>> document.forms['service.device.selected-devices-form'];
>>>>>>   if (form!=null) form.submit();
>>>>>>
>>>>>>
>>>>>>
>>>>>>   var winl = (screen.width - 500) / 2;
>>>>>>
>>>>>>
>>>>>>
>>>>>>   var wint = (screen.height - 350) / 2;
>>>>>>
>>>>>>
>>>>>>
>>>>>>     winprops =
>>>>>>
> 'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable
>>>> =
>>>>
>>>>>> 0';
>>>>>>
>>>>>>
>>>>>>
>>>>>>   var child = window.open(url,"action_confirm", winprops);
>>>>>>
>>>>>>
>>>>>>
>>>>>>   self.name="main_window";
>>>>>>
>>>>>>
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>> I added the first two lines of the JS method - it worked correctly
>>>>>> before I put those in (though of course it didn't have my added
>>>>>> functionality in place). The popup window does appear, and it has
>> the
>>>>>> correct values in it (that is, the devices which were selected).
>> But
>>>> the
>>>>
>>>>>> main window goes blank where before it remained unchanged. When
>> I've
>>>>>> seen blank pages like this before, it meant there was a bad action
>>>>>> forward in the struts-config file, but I don't want the main page
>> to
>>>>>> change at all, so what I really want is for the main page to just
>>>>>>
>>>> stay
>>>>
>>>>>> in place as it was before the form was submitted.
>>>>>>
>>>>>>
>>>>>>
>>>>>> How do I go about doing that? Thanks!
>>>>>>
>>>>>>
>>>>>>
>>>>>> Chris Loschen
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>> _________________________________________________________________
>>>>> Receive MSN Hotmail alerts over SMS!
>>>>> http://en-asiasms.mobile.msn.com/ac.aspx?cid=1002
>>>>>
>>>>>
>>>>>
>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
  (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
  Supplying the wheel, so you don't have to reinvent it!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts action call in a JS method returns blank page

Posted by Musachy Barroso <mb...@wfscorp.com>.
You should try debugging it. If you have Firebug installed (if you 
don't, you should :) ), click on "scripts", and under "Options" select 
"Break on All Errors". Or just set breakpoints inside the js code.

regards
musachy

Christopher Loschen wrote:
> Happy to provide an opportunity for self-promotion :-)!
>
> I think you're right about dropping the params somewhere. I've been
> trying today to set up a new approach, which seems simpler to me, but
> which is still fighting me. The basic idea is to use the form to hold
> the array of values I need rather than just sticking them up onto the
> URL. To that end, I rewrote the JS function like this:
>
> function addCheckBoxValuesToForm(locationStr)
> {
>   var form = document['checkbox-form'];
>   if (form){
>     var checkboxes_across = new Array();
>     var selectedCheckBoxes = new Array();
>     var formCheckboxAcross = form.elements['checkbox_ids_across'];
>     if(formCheckboxAcross!=null && formCheckboxAcross!="") {
>       selectedCheckBoxes = formCheckboxAcross;
>     }
>     if (selectedCheckBoxes.length > 0) {
>       checkboxes_across.push(selectedCheckboxes);
>     }
>     
>     var checkboxes = form.elements['checkboxes'];
>     if (checkboxes)
>     {
>       var checkStr = new Array();
>       var uncheckedStr = new Array();
>       
>       // If the no.of checkboxes is one then converting the checkbox
> object to
>       // Checkbox array.
>       if(checkboxes.type == "checkbox")
>       {
>         checkboxes = [checkboxes];
>       }
>
>       for (var i = 0; i < checkboxes.length; ++i)
>       {
>         if (checkboxes[i].checked)
>         {
>           checkStr.push(checkboxes[i].value);
>         }
>         else
>         {
>            uncheckedStr.push(checkboxes[i].value);
>         }
>       }
>       if (checkStr.length > 0)
>       {
>         form.elements['checkbox_id'] = checkStr;
>         checkboxes_across.push(checkStr);
>       }
>       if (uncheckedStr.length > 0)
>       {
>         form.elements['uncheckbox_id'] = uncheckedStr;
>       }
>     }
>     form.elements['checkbox_ids_across'].value = checkboxes_across;
>   }
>   
>   document.location.href = locationStr;
> }
>
> I've got appropriate setters and getters in my Java form (I think,
> though I have to use Identifier[] objects rather than String[], so I
> might need to convert that), and I also added a hidden field
> "checkbox_ids_across" into my form on the JSP form. But I'm still
> getting a JS error when I open the page that "checkbox_ids_across" is
> null or not an object, and it's still not doing what it's supposed to
> do.
>
> Any suggestions? Thanks!
>
> Chris
>
> -----Original Message-----
> From: Frank W. Zammetti [mailto:fzlists@omnytex.com] 
> Sent: Thursday, February 08, 2007 5:30 PM
> To: Struts Users Mailing List
> Cc: Struts Users Mailing List
> Subject: RE: Struts action call in a JS method returns blank page
>
> On Thu, February 8, 2007 4:46 pm, Christopher Loschen wrote:
>   
>> Thanks Frank -- I've been reading your posts on JWP with great
>>     
> interest
>   
>> for quite a while, and I'll bet your book is another good resource.
>>     
>
> *Of course* it is :) (what, you expected a different answer?!?)  FYI, my
> new book, "Practical JavaScript, DOM Scripting and Ajax Projects", is
> scheduled to hit shelves in mid-April (never pass up the chance for a
> little shameless self-promotion I've been told!)
>
>   
>> The current project (or at least this piece of it) has to be finished
>>     
> by
>   
>> tomorrow, so I may not be able to introduce Ajax just yet. However,
>>     
> I'm
>   
>> definitely interested in learning more about it, and will no doubt use
>> it more as I learn more.
>>     
>
> Sounds good.  I'd say it's not generally something you want to jump into
> on a tight deadline if you have't done as much client-side
> development...
> many good Java developers have a bit of a rough time early on when
> trying
> to do more client-side stuff... seems like it should be simpler most
> say,
> but it isn't usually :)
>
>   
>> Meanwhile, I'm looking at a possibly related problem. We've got
>> checkboxes on multiple pages and a JS function which keeps track of
>> which boxes are checked on which page so that we can go from page to
>> page and retain the boxes checked on other pages. That works by
>>     
> putting
>   
>> the checkbox ids into the URL for the page. It's working correctly,
>>     
> more
>   
>> or less, but now I find that when I actually am ready to use the array
>> of checkboxes, I'm getting only the ones on the current page, not the
>> rest. My Java method is getting the correct request parameters, but it
>> always returns null. Perhaps that's because the request parameters are
>> associated with one action (which displays the appropriate page of the
>> list) and my action class is associated with a different action (to
>> store the checkbox values and process the result)? If that's right, I
>> guess I need to get those values into my action too. Does that sound
>> like a reasonable guess?
>>     
>
> Hmm... I'm not sure I followed the whole thing, but it sure sounds like
> your dropping the params somewhere... my guess is that you aren't
> replicating the whole query string with each request, which you'd need
> to
> do.
>
> However, I'd definitely say you probably want to be storing that info in
> session in the first place... then it's relatively easy to pass it along
> with every single request for all pages that need it.
>
>   
>> Chris
>>
>> -----Original Message-----
>> From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
>> Sent: Thursday, February 08, 2007 10:30 AM
>> To: Struts Users Mailing List
>> Cc: Struts Users Mailing List
>> Subject: Re: Struts action call in a JS method returns blank page
>>
>> Theres a ton of choice on which AJAX library to use, many of them very
>> good.  However, since your working in Java specifically, and since you
>> say
>> you are not all that familiar with JS, you may prefer a solution that
>> will
>> (in most cases) require ZERO Javascript coding, and such a thing
>>     
> exists:
>   
>>     
> http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/tagl
>   
>> ib/package-summary.html
>>
>> This is the AjaxParts Taglib (APT), which is a part of Java Web Parts
>> (JWP):
>>
>> http://javawebparts.sourceforge.net
>>
>> With this, let's say you want to update a specific <div> in response
>>     
> to
>   
>> a
>> button being clicked on a page with some data returned by the server
>> without refreshing the page, in your JSP you would have:
>>
>> <div id="myDiv">Response will go here</div>
>> <input type="button" value="Click for AJAX"><ajax:event
>> ajaxRef="ajaxFunctions/button1" />
>> <ajax:enable />
>>
>> That's it, no JavaScript at all!  The other piece to the puzzle is an
>> XML
>> file like so:
>>
>> <ajaxConfig>
>>   <group ajaxRef="ajaxFunctions">
>>     <element ajaxRef="button1">
>>        <event type="onClick">
>>          <requestHandler type="std:SimpleRequest" target="/myURL">
>>            <parameter></parameter>
>>         </requestHandler>
>>         <responseHandler type="std:InnerHTML">
>>           <parameter>myDiv</parameter>
>>         </responseHandler>
>>       </event>
>>     </element>
>>   </group>
>> </ajaxConfig>
>>
>> The XML file maps via the ajaxRef values to the ajaxRef in the
>> <ajax:event> tag, and it defines what's going to happen in response to
>> some event (onClick in this case), which in this case is simply an
>>     
> AJAX
>   
>> request to /myURL with no data passed, and then what happens when the
>> response comes back, which is it will be inserted into myDiv via
>> innerHTML.
>>
>> There's a whole bunch of request and response handlers available out
>>     
> of
>   
>> the box which tend to cover most needs, things like submitting forms,
>> executing some returned Javascript, sending XML automatically
>> constructed
>> from form data, transforming returned XML via XLT, and so on.  You
>>     
> also
>   
>> have the ability to write your own handlers (just plain Javascript) if
>> you
>> need something that isn't covered.
>>
>> hth,
>> Frank
>>
>>
>> --
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>> AIM/Yahoo: fzammetti
>> MSN: fzammetti@hotmail.com
>> Author of "Practical Ajax Projects With Java Technology"
>>  (2006, Apress, ISBN 1-59059-695-1)
>> Java Web Parts - http://javawebparts.sourceforge.net
>>  Supplying the wheel, so you don't have to reinvent it!
>>
>> On Thu, February 8, 2007 9:49 am, Musachy Barroso wrote:
>>     
>>> Check Prototype out, here is a good tutorial:
>>> http://www.sergiopereira.com/articles/prototype.js.html, basically
>>>       
>> what
>>     
>>> you need is something like:
>>>
>>> |**var myAjax = new Ajax.Request(
>>> 			url,
>>> 			{
>>> 				method: 'get',
>>> 				parameters: Form.serialize("formid"),
>>> 				onComplete: function() {
>>> 				    //do something here, or not :)
>>> 				}
>>> 			});**|
>>>
>>> regards
>>> musachy
>>>
>>> Christopher Loschen wrote:
>>>       
>>>> I'm not all that familiar with JS, to be honest, and I've never had
>>>>         
>> the
>>     
>>>> chance to use Ajax (but want to learn). What I have now is working,
>>>>         
>> but
>>     
>>>> I'd be happy to learn how to do it without refreshing the page --
>>>>         
>> that
>>     
>>>> does seem like a more elegant solution to me. What do you suggest?
>>>>         
> We
>   
>> do
>>     
>>>> use JS for our app, but no JS framework as such as far as I can
>>>>         
> tell.
>   
>>>> Chris
>>>>
>>>> -----Original Message-----
>>>> From: Musachy Barroso [mailto:musachy@gmail.com]
>>>> Sent: Thursday, February 08, 2007 8:03 AM
>>>> To: Struts Users Mailing List
>>>> Subject: Re: Struts action call in a JS method returns blank page
>>>>
>>>> Like I said before you can use Ajax to submit the form, and the page
>>>> won't
>>>> refresh, how to do it depends on what JS framework you are using, if
>>>> any.
>>>>
>>>> regards
>>>> musachy
>>>>
>>>> On 2/8/07, Christopher Loschen <CL...@axeda.com> wrote:
>>>>
>>>>         
>>>>> Yes, you're right that the form submit was causing the system to
>>>>>
>>>>>           
>>>> forward
>>>>
>>>>         
>>>>> to whatever the action said, which in my case was the blank page.
>>>>>
>>>>>           
>>>> You'll see
>>>>
>>>>         
>>>>> from the later emails in the thread yesterday that I solved that by
>>>>> forwarding to the action which populated the original page.
>>>>>
>>>>> I need the form.submit because I need to get the checked boxes from
>>>>>
>>>>>           
>>>> the
>>>>
>>>>         
>>>>> form and I need to call the action specified in the action
>>>>>           
> attribute
>   
>>>> on that
>>>>
>>>>         
>>>>> form in order to put those checkbox values into the request in the
>>>>>
>>>>>           
>>>> form that
>>>>
>>>>         
>>>>> my downstream code needs.
>>>>>
>>>>> Submitting the form is the only way I know to get the form values
>>>>>           
>> the
>>     
>>>> user
>>>>
>>>>         
>>>>> submits from the HTML page to my Java code -- are you saying that I
>>>>>
>>>>>           
>>>> have
>>>>
>>>>         
>>>>> other alternatives?
>>>>>
>>>>> Chris
>>>>>
>>>>> ________________________________
>>>>>
>>>>> From: Yee Kai Lai [mailto:yeekai.lai@hotmail.com]
>>>>> Sent: Thu 2/8/2007 12:24 AM
>>>>> To: user@struts.apache.org
>>>>> Subject: RE: Struts action call in a JS method returns blank page
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> It returns a blank page might be due to
>>>>>
>>>>> form.submit(); in your JS.
>>>>>
>>>>> I think if you have a form named
>>>>>
>>>>>           
>>>> 'service.device.selected-devices-form'
>>>>
>>>>         
>>>>> then
>>>>> it will never be null hence it will always submit.
>>>>>
>>>>> May you could enlightened why u need a form.submit() ?
>>>>>
>>>>>
>>>>>
>>>>>           
>>>>>> From: "Christopher Loschen" <CL...@axeda.com>
>>>>>> Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>>>>>> To: <us...@struts.apache.org>
>>>>>> Subject: Struts action call in a JS method returns blank page
>>>>>> Date: Wed, 7 Feb 2007 14:14:35 -0500
>>>>>>
>>>>>> Hi all,
>>>>>>
>>>>>>
>>>>>>
>>>>>> I'm honestly unsure if I'm having a problem with Struts (sadly,
>>>>>>             
>> 1.1)
>>     
>>>> or
>>>>
>>>>         
>>>>>> with Javascript, or something else. But my best guess is it's a
>>>>>>
>>>>>>             
>>>> Struts
>>>>
>>>>         
>>>>>> issue, and anyway, there are a lot of very knowledgeable people on
>>>>>>
>>>>>>             
>>>> both
>>>>
>>>>         
>>>>>> of those technologies here, so I hope someone can help. Bottom
>>>>>>             
>> line:
>>     
>>>> I'm
>>>>
>>>>         
>>>>>> getting the popup with the correct values, but my main page under
>>>>>>             
>> the
>>     
>>>>>> popup becomes blank.
>>>>>>
>>>>>>
>>>>>>
>>>>>> I'm adding some functionality to an existing application. The
>>>>>> functionality I'm adding takes the values from some checkboxes on
>>>>>>
>>>>>>             
>>>> page
>>>>
>>>>         
>>>>>> A, gets the corresponding devices from the checkbox values, and
>>>>>>             
>> saves
>>     
>>>>>> the resulting List into the request. Later down the stream, other
>>>>>>
>>>>>>             
>>>> code
>>>>
>>>>         
>>>>>> gets those values again and uses them as a list of devices on
>>>>>>             
> which
>   
>>>> to
>>>>
>>>>         
>>>>>> perform an action. Pretty straightforward.
>>>>>>
>>>>>>
>>>>>>
>>>>>> All of the actual navigation is happening via Javascript calls,
>>>>>>
>>>>>>             
>>>> starting
>>>>
>>>>         
>>>>>> with a link on page A, but outside the form where my checkboxes
>>>>>>             
> are
>   
>>>>>> declared. That link fires a Javascript function which pops up a
>>>>>>             
>> small
>>     
>>>>>> window with a list of actions which have been defined. If the user
>>>>>>
>>>>>>             
>>>> then
>>>>
>>>>         
>>>>>> clicks on one of those actions, another Javascript function fires
>>>>>>
>>>>>>             
>>>> which
>>>>
>>>>         
>>>>>> pops up another window to confirm that the user wants to perform
>>>>>>             
>> the
>>     
>>>>>> selected action on the selected devices.
>>>>>>
>>>>>>
>>>>>>
>>>>>> I have inserted my added functionality into that second script.
>>>>>> Basically I need to submit the appropriate form on the page. I've
>>>>>> defined it with the correct action and I've got a mapping in my
>>>>>> struts-config.xml file:
>>>>>>
>>>>>>
>>>>>>
>>>>>>     <form-bean
>>>>>>
>>>>>>      name="service.device.selected-devices-form"
>>>>>>
>>>>>>      type="com.xxx.webapp.common.CheckboxForm"/>
>>>>>>
>>>>>> ...
>>>>>>
>>>>>>     <action path="/service/device/actions/store-selected-devices"
>>>>>>
>>>>>>
>>>>>> type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
>>>>>>
>>>>>>             name="service.device.selected-devices-form" />
>>>>>>
>>>>>>
>>>>>>
>>>>>> The mapping doesn't have any action forwards defined because it
>>>>>>
>>>>>>             
>>>> doesn't
>>>>
>>>>         
>>>>>> actually need to go anywhere (though that might be part of my
>>>>>>
>>>>>>             
>>>> problem).
>>>>
>>>>         
>>>>>> The JS function looks like this:
>>>>>>
>>>>>>
>>>>>>
>>>>>> function popActionConfirm(url) {
>>>>>>
>>>>>>
>>>>>>
>>>>>>   var form =
>>>>>>             
>> document.forms['service.device.selected-devices-form'];
>>     
>>>>>>   if (form!=null) form.submit();
>>>>>>
>>>>>>
>>>>>>
>>>>>>   var winl = (screen.width - 500) / 2;
>>>>>>
>>>>>>
>>>>>>
>>>>>>   var wint = (screen.height - 350) / 2;
>>>>>>
>>>>>>
>>>>>>
>>>>>>     winprops =
>>>>>>
>>>>>>             
> 'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable
>   
>>>> =
>>>>
>>>>         
>>>>>> 0';
>>>>>>
>>>>>>
>>>>>>
>>>>>>   var child = window.open(url,"action_confirm", winprops);
>>>>>>
>>>>>>
>>>>>>
>>>>>>   self.name="main_window";
>>>>>>
>>>>>>
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>> I added the first two lines of the JS method - it worked correctly
>>>>>> before I put those in (though of course it didn't have my added
>>>>>> functionality in place). The popup window does appear, and it has
>>>>>>             
>> the
>>     
>>>>>> correct values in it (that is, the devices which were selected).
>>>>>>             
>> But
>>     
>>>> the
>>>>
>>>>         
>>>>>> main window goes blank where before it remained unchanged. When
>>>>>>             
>> I've
>>     
>>>>>> seen blank pages like this before, it meant there was a bad action
>>>>>> forward in the struts-config file, but I don't want the main page
>>>>>>             
>> to
>>     
>>>>>> change at all, so what I really want is for the main page to just
>>>>>>
>>>>>>             
>>>> stay
>>>>
>>>>         
>>>>>> in place as it was before the form was submitted.
>>>>>>
>>>>>>
>>>>>>
>>>>>> How do I go about doing that? Thanks!
>>>>>>
>>>>>>
>>>>>>
>>>>>> Chris Loschen
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>             
>>>>> _________________________________________________________________
>>>>> Receive MSN Hotmail alerts over SMS!
>>>>> http://en-asiasms.mobile.msn.com/ac.aspx?cid=1002
>>>>>
>>>>>
>>>>>
>>>>>           
>> ---------------------------------------------------------------------
>>     
>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>           
>>>>
>>>>         
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>     
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts action call in a JS method returns blank page

Posted by Christopher Loschen <CL...@axeda.com>.
Happy to provide an opportunity for self-promotion :-)!

I think you're right about dropping the params somewhere. I've been
trying today to set up a new approach, which seems simpler to me, but
which is still fighting me. The basic idea is to use the form to hold
the array of values I need rather than just sticking them up onto the
URL. To that end, I rewrote the JS function like this:

function addCheckBoxValuesToForm(locationStr)
{
  var form = document['checkbox-form'];
  if (form){
    var checkboxes_across = new Array();
    var selectedCheckBoxes = new Array();
    var formCheckboxAcross = form.elements['checkbox_ids_across'];
    if(formCheckboxAcross!=null && formCheckboxAcross!="") {
      selectedCheckBoxes = formCheckboxAcross;
    }
    if (selectedCheckBoxes.length > 0) {
      checkboxes_across.push(selectedCheckboxes);
    }
    
    var checkboxes = form.elements['checkboxes'];
    if (checkboxes)
    {
      var checkStr = new Array();
      var uncheckedStr = new Array();
      
      // If the no.of checkboxes is one then converting the checkbox
object to
      // Checkbox array.
      if(checkboxes.type == "checkbox")
      {
        checkboxes = [checkboxes];
      }

      for (var i = 0; i < checkboxes.length; ++i)
      {
        if (checkboxes[i].checked)
        {
          checkStr.push(checkboxes[i].value);
        }
        else
        {
           uncheckedStr.push(checkboxes[i].value);
        }
      }
      if (checkStr.length > 0)
      {
        form.elements['checkbox_id'] = checkStr;
        checkboxes_across.push(checkStr);
      }
      if (uncheckedStr.length > 0)
      {
        form.elements['uncheckbox_id'] = uncheckedStr;
      }
    }
    form.elements['checkbox_ids_across'].value = checkboxes_across;
  }
  
  document.location.href = locationStr;
}

I've got appropriate setters and getters in my Java form (I think,
though I have to use Identifier[] objects rather than String[], so I
might need to convert that), and I also added a hidden field
"checkbox_ids_across" into my form on the JSP form. But I'm still
getting a JS error when I open the page that "checkbox_ids_across" is
null or not an object, and it's still not doing what it's supposed to
do.

Any suggestions? Thanks!

Chris

-----Original Message-----
From: Frank W. Zammetti [mailto:fzlists@omnytex.com] 
Sent: Thursday, February 08, 2007 5:30 PM
To: Struts Users Mailing List
Cc: Struts Users Mailing List
Subject: RE: Struts action call in a JS method returns blank page

On Thu, February 8, 2007 4:46 pm, Christopher Loschen wrote:
> Thanks Frank -- I've been reading your posts on JWP with great
interest
> for quite a while, and I'll bet your book is another good resource.

*Of course* it is :) (what, you expected a different answer?!?)  FYI, my
new book, "Practical JavaScript, DOM Scripting and Ajax Projects", is
scheduled to hit shelves in mid-April (never pass up the chance for a
little shameless self-promotion I've been told!)

> The current project (or at least this piece of it) has to be finished
by
> tomorrow, so I may not be able to introduce Ajax just yet. However,
I'm
> definitely interested in learning more about it, and will no doubt use
> it more as I learn more.

Sounds good.  I'd say it's not generally something you want to jump into
on a tight deadline if you have't done as much client-side
development...
many good Java developers have a bit of a rough time early on when
trying
to do more client-side stuff... seems like it should be simpler most
say,
but it isn't usually :)

> Meanwhile, I'm looking at a possibly related problem. We've got
> checkboxes on multiple pages and a JS function which keeps track of
> which boxes are checked on which page so that we can go from page to
> page and retain the boxes checked on other pages. That works by
putting
> the checkbox ids into the URL for the page. It's working correctly,
more
> or less, but now I find that when I actually am ready to use the array
> of checkboxes, I'm getting only the ones on the current page, not the
> rest. My Java method is getting the correct request parameters, but it
> always returns null. Perhaps that's because the request parameters are
> associated with one action (which displays the appropriate page of the
> list) and my action class is associated with a different action (to
> store the checkbox values and process the result)? If that's right, I
> guess I need to get those values into my action too. Does that sound
> like a reasonable guess?

Hmm... I'm not sure I followed the whole thing, but it sure sounds like
your dropping the params somewhere... my guess is that you aren't
replicating the whole query string with each request, which you'd need
to
do.

However, I'd definitely say you probably want to be storing that info in
session in the first place... then it's relatively easy to pass it along
with every single request for all pages that need it.

> Chris
>
> -----Original Message-----
> From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
> Sent: Thursday, February 08, 2007 10:30 AM
> To: Struts Users Mailing List
> Cc: Struts Users Mailing List
> Subject: Re: Struts action call in a JS method returns blank page
>
> Theres a ton of choice on which AJAX library to use, many of them very
> good.  However, since your working in Java specifically, and since you
> say
> you are not all that familiar with JS, you may prefer a solution that
> will
> (in most cases) require ZERO Javascript coding, and such a thing
exists:
>
>
http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/tagl
> ib/package-summary.html
>
> This is the AjaxParts Taglib (APT), which is a part of Java Web Parts
> (JWP):
>
> http://javawebparts.sourceforge.net
>
> With this, let's say you want to update a specific <div> in response
to
> a
> button being clicked on a page with some data returned by the server
> without refreshing the page, in your JSP you would have:
>
> <div id="myDiv">Response will go here</div>
> <input type="button" value="Click for AJAX"><ajax:event
> ajaxRef="ajaxFunctions/button1" />
> <ajax:enable />
>
> That's it, no JavaScript at all!  The other piece to the puzzle is an
> XML
> file like so:
>
> <ajaxConfig>
>   <group ajaxRef="ajaxFunctions">
>     <element ajaxRef="button1">
>        <event type="onClick">
>          <requestHandler type="std:SimpleRequest" target="/myURL">
>            <parameter></parameter>
>         </requestHandler>
>         <responseHandler type="std:InnerHTML">
>           <parameter>myDiv</parameter>
>         </responseHandler>
>       </event>
>     </element>
>   </group>
> </ajaxConfig>
>
> The XML file maps via the ajaxRef values to the ajaxRef in the
> <ajax:event> tag, and it defines what's going to happen in response to
> some event (onClick in this case), which in this case is simply an
AJAX
> request to /myURL with no data passed, and then what happens when the
> response comes back, which is it will be inserted into myDiv via
> innerHTML.
>
> There's a whole bunch of request and response handlers available out
of
> the box which tend to cover most needs, things like submitting forms,
> executing some returned Javascript, sending XML automatically
> constructed
> from form data, transforming returned XML via XLT, and so on.  You
also
> have the ability to write your own handlers (just plain Javascript) if
> you
> need something that isn't covered.
>
> hth,
> Frank
>
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> AIM/Yahoo: fzammetti
> MSN: fzammetti@hotmail.com
> Author of "Practical Ajax Projects With Java Technology"
>  (2006, Apress, ISBN 1-59059-695-1)
> Java Web Parts - http://javawebparts.sourceforge.net
>  Supplying the wheel, so you don't have to reinvent it!
>
> On Thu, February 8, 2007 9:49 am, Musachy Barroso wrote:
>> Check Prototype out, here is a good tutorial:
>> http://www.sergiopereira.com/articles/prototype.js.html, basically
> what
>> you need is something like:
>>
>> |**var myAjax = new Ajax.Request(
>> 			url,
>> 			{
>> 				method: 'get',
>> 				parameters: Form.serialize("formid"),
>> 				onComplete: function() {
>> 				    //do something here, or not :)
>> 				}
>> 			});**|
>>
>> regards
>> musachy
>>
>> Christopher Loschen wrote:
>>> I'm not all that familiar with JS, to be honest, and I've never had
> the
>>> chance to use Ajax (but want to learn). What I have now is working,
> but
>>> I'd be happy to learn how to do it without refreshing the page --
> that
>>> does seem like a more elegant solution to me. What do you suggest?
We
> do
>>> use JS for our app, but no JS framework as such as far as I can
tell.
>>>
>>> Chris
>>>
>>> -----Original Message-----
>>> From: Musachy Barroso [mailto:musachy@gmail.com]
>>> Sent: Thursday, February 08, 2007 8:03 AM
>>> To: Struts Users Mailing List
>>> Subject: Re: Struts action call in a JS method returns blank page
>>>
>>> Like I said before you can use Ajax to submit the form, and the page
>>> won't
>>> refresh, how to do it depends on what JS framework you are using, if
>>> any.
>>>
>>> regards
>>> musachy
>>>
>>> On 2/8/07, Christopher Loschen <CL...@axeda.com> wrote:
>>>
>>>> Yes, you're right that the form submit was causing the system to
>>>>
>>> forward
>>>
>>>> to whatever the action said, which in my case was the blank page.
>>>>
>>> You'll see
>>>
>>>> from the later emails in the thread yesterday that I solved that by
>>>> forwarding to the action which populated the original page.
>>>>
>>>> I need the form.submit because I need to get the checked boxes from
>>>>
>>> the
>>>
>>>> form and I need to call the action specified in the action
attribute
>>>>
>>> on that
>>>
>>>> form in order to put those checkbox values into the request in the
>>>>
>>> form that
>>>
>>>> my downstream code needs.
>>>>
>>>> Submitting the form is the only way I know to get the form values
> the
>>>>
>>> user
>>>
>>>> submits from the HTML page to my Java code -- are you saying that I
>>>>
>>> have
>>>
>>>> other alternatives?
>>>>
>>>> Chris
>>>>
>>>> ________________________________
>>>>
>>>> From: Yee Kai Lai [mailto:yeekai.lai@hotmail.com]
>>>> Sent: Thu 2/8/2007 12:24 AM
>>>> To: user@struts.apache.org
>>>> Subject: RE: Struts action call in a JS method returns blank page
>>>>
>>>>
>>>>
>>>>
>>>> It returns a blank page might be due to
>>>>
>>>> form.submit(); in your JS.
>>>>
>>>> I think if you have a form named
>>>>
>>> 'service.device.selected-devices-form'
>>>
>>>> then
>>>> it will never be null hence it will always submit.
>>>>
>>>> May you could enlightened why u need a form.submit() ?
>>>>
>>>>
>>>>
>>>>> From: "Christopher Loschen" <CL...@axeda.com>
>>>>> Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>>>>> To: <us...@struts.apache.org>
>>>>> Subject: Struts action call in a JS method returns blank page
>>>>> Date: Wed, 7 Feb 2007 14:14:35 -0500
>>>>>
>>>>> Hi all,
>>>>>
>>>>>
>>>>>
>>>>> I'm honestly unsure if I'm having a problem with Struts (sadly,
> 1.1)
>>>>>
>>> or
>>>
>>>>> with Javascript, or something else. But my best guess is it's a
>>>>>
>>> Struts
>>>
>>>>> issue, and anyway, there are a lot of very knowledgeable people on
>>>>>
>>> both
>>>
>>>>> of those technologies here, so I hope someone can help. Bottom
> line:
>>>>>
>>> I'm
>>>
>>>>> getting the popup with the correct values, but my main page under
> the
>>>>> popup becomes blank.
>>>>>
>>>>>
>>>>>
>>>>> I'm adding some functionality to an existing application. The
>>>>> functionality I'm adding takes the values from some checkboxes on
>>>>>
>>> page
>>>
>>>>> A, gets the corresponding devices from the checkbox values, and
> saves
>>>>> the resulting List into the request. Later down the stream, other
>>>>>
>>> code
>>>
>>>>> gets those values again and uses them as a list of devices on
which
>>>>>
>>> to
>>>
>>>>> perform an action. Pretty straightforward.
>>>>>
>>>>>
>>>>>
>>>>> All of the actual navigation is happening via Javascript calls,
>>>>>
>>> starting
>>>
>>>>> with a link on page A, but outside the form where my checkboxes
are
>>>>> declared. That link fires a Javascript function which pops up a
> small
>>>>> window with a list of actions which have been defined. If the user
>>>>>
>>> then
>>>
>>>>> clicks on one of those actions, another Javascript function fires
>>>>>
>>> which
>>>
>>>>> pops up another window to confirm that the user wants to perform
> the
>>>>> selected action on the selected devices.
>>>>>
>>>>>
>>>>>
>>>>> I have inserted my added functionality into that second script.
>>>>> Basically I need to submit the appropriate form on the page. I've
>>>>> defined it with the correct action and I've got a mapping in my
>>>>> struts-config.xml file:
>>>>>
>>>>>
>>>>>
>>>>>     <form-bean
>>>>>
>>>>>      name="service.device.selected-devices-form"
>>>>>
>>>>>      type="com.xxx.webapp.common.CheckboxForm"/>
>>>>>
>>>>> ...
>>>>>
>>>>>     <action path="/service/device/actions/store-selected-devices"
>>>>>
>>>>>
>>>>> type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
>>>>>
>>>>>             name="service.device.selected-devices-form" />
>>>>>
>>>>>
>>>>>
>>>>> The mapping doesn't have any action forwards defined because it
>>>>>
>>> doesn't
>>>
>>>>> actually need to go anywhere (though that might be part of my
>>>>>
>>> problem).
>>>
>>>>> The JS function looks like this:
>>>>>
>>>>>
>>>>>
>>>>> function popActionConfirm(url) {
>>>>>
>>>>>
>>>>>
>>>>>   var form =
> document.forms['service.device.selected-devices-form'];
>>>>>
>>>>>   if (form!=null) form.submit();
>>>>>
>>>>>
>>>>>
>>>>>   var winl = (screen.width - 500) / 2;
>>>>>
>>>>>
>>>>>
>>>>>   var wint = (screen.height - 350) / 2;
>>>>>
>>>>>
>>>>>
>>>>>     winprops =
>>>>>
>>>>
>
'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable
>>>>
>>> =
>>>
>>>>> 0';
>>>>>
>>>>>
>>>>>
>>>>>   var child = window.open(url,"action_confirm", winprops);
>>>>>
>>>>>
>>>>>
>>>>>   self.name="main_window";
>>>>>
>>>>>
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> I added the first two lines of the JS method - it worked correctly
>>>>> before I put those in (though of course it didn't have my added
>>>>> functionality in place). The popup window does appear, and it has
> the
>>>>> correct values in it (that is, the devices which were selected).
> But
>>>>>
>>> the
>>>
>>>>> main window goes blank where before it remained unchanged. When
> I've
>>>>> seen blank pages like this before, it meant there was a bad action
>>>>> forward in the struts-config file, but I don't want the main page
> to
>>>>> change at all, so what I really want is for the main page to just
>>>>>
>>> stay
>>>
>>>>> in place as it was before the form was submitted.
>>>>>
>>>>>
>>>>>
>>>>> How do I go about doing that? Thanks!
>>>>>
>>>>>
>>>>>
>>>>> Chris Loschen
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>> _________________________________________________________________
>>>> Receive MSN Hotmail alerts over SMS!
>>>> http://en-asiasms.mobile.msn.com/ac.aspx?cid=1002
>>>>
>>>>
>>>>
> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts action call in a JS method returns blank page

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
On Thu, February 8, 2007 4:46 pm, Christopher Loschen wrote:
> Thanks Frank -- I've been reading your posts on JWP with great interest
> for quite a while, and I'll bet your book is another good resource.

*Of course* it is :) (what, you expected a different answer?!?)  FYI, my
new book, "Practical JavaScript, DOM Scripting and Ajax Projects", is
scheduled to hit shelves in mid-April (never pass up the chance for a
little shameless self-promotion I've been told!)

> The current project (or at least this piece of it) has to be finished by
> tomorrow, so I may not be able to introduce Ajax just yet. However, I'm
> definitely interested in learning more about it, and will no doubt use
> it more as I learn more.

Sounds good.  I'd say it's not generally something you want to jump into
on a tight deadline if you have't done as much client-side development...
many good Java developers have a bit of a rough time early on when trying
to do more client-side stuff... seems like it should be simpler most say,
but it isn't usually :)

> Meanwhile, I'm looking at a possibly related problem. We've got
> checkboxes on multiple pages and a JS function which keeps track of
> which boxes are checked on which page so that we can go from page to
> page and retain the boxes checked on other pages. That works by putting
> the checkbox ids into the URL for the page. It's working correctly, more
> or less, but now I find that when I actually am ready to use the array
> of checkboxes, I'm getting only the ones on the current page, not the
> rest. My Java method is getting the correct request parameters, but it
> always returns null. Perhaps that's because the request parameters are
> associated with one action (which displays the appropriate page of the
> list) and my action class is associated with a different action (to
> store the checkbox values and process the result)? If that's right, I
> guess I need to get those values into my action too. Does that sound
> like a reasonable guess?

Hmm... I'm not sure I followed the whole thing, but it sure sounds like
your dropping the params somewhere... my guess is that you aren't
replicating the whole query string with each request, which you'd need to
do.

However, I'd definitely say you probably want to be storing that info in
session in the first place... then it's relatively easy to pass it along
with every single request for all pages that need it.

> Chris
>
> -----Original Message-----
> From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
> Sent: Thursday, February 08, 2007 10:30 AM
> To: Struts Users Mailing List
> Cc: Struts Users Mailing List
> Subject: Re: Struts action call in a JS method returns blank page
>
> Theres a ton of choice on which AJAX library to use, many of them very
> good.  However, since your working in Java specifically, and since you
> say
> you are not all that familiar with JS, you may prefer a solution that
> will
> (in most cases) require ZERO Javascript coding, and such a thing exists:
>
> http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/tagl
> ib/package-summary.html
>
> This is the AjaxParts Taglib (APT), which is a part of Java Web Parts
> (JWP):
>
> http://javawebparts.sourceforge.net
>
> With this, let's say you want to update a specific <div> in response to
> a
> button being clicked on a page with some data returned by the server
> without refreshing the page, in your JSP you would have:
>
> <div id="myDiv">Response will go here</div>
> <input type="button" value="Click for AJAX"><ajax:event
> ajaxRef="ajaxFunctions/button1" />
> <ajax:enable />
>
> That's it, no JavaScript at all!  The other piece to the puzzle is an
> XML
> file like so:
>
> <ajaxConfig>
>   <group ajaxRef="ajaxFunctions">
>     <element ajaxRef="button1">
>        <event type="onClick">
>          <requestHandler type="std:SimpleRequest" target="/myURL">
>            <parameter></parameter>
>         </requestHandler>
>         <responseHandler type="std:InnerHTML">
>           <parameter>myDiv</parameter>
>         </responseHandler>
>       </event>
>     </element>
>   </group>
> </ajaxConfig>
>
> The XML file maps via the ajaxRef values to the ajaxRef in the
> <ajax:event> tag, and it defines what's going to happen in response to
> some event (onClick in this case), which in this case is simply an AJAX
> request to /myURL with no data passed, and then what happens when the
> response comes back, which is it will be inserted into myDiv via
> innerHTML.
>
> There's a whole bunch of request and response handlers available out of
> the box which tend to cover most needs, things like submitting forms,
> executing some returned Javascript, sending XML automatically
> constructed
> from form data, transforming returned XML via XLT, and so on.  You also
> have the ability to write your own handlers (just plain Javascript) if
> you
> need something that isn't covered.
>
> hth,
> Frank
>
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> AIM/Yahoo: fzammetti
> MSN: fzammetti@hotmail.com
> Author of "Practical Ajax Projects With Java Technology"
>  (2006, Apress, ISBN 1-59059-695-1)
> Java Web Parts - http://javawebparts.sourceforge.net
>  Supplying the wheel, so you don't have to reinvent it!
>
> On Thu, February 8, 2007 9:49 am, Musachy Barroso wrote:
>> Check Prototype out, here is a good tutorial:
>> http://www.sergiopereira.com/articles/prototype.js.html, basically
> what
>> you need is something like:
>>
>> |**var myAjax = new Ajax.Request(
>> 			url,
>> 			{
>> 				method: 'get',
>> 				parameters: Form.serialize("formid"),
>> 				onComplete: function() {
>> 				    //do something here, or not :)
>> 				}
>> 			});**|
>>
>> regards
>> musachy
>>
>> Christopher Loschen wrote:
>>> I'm not all that familiar with JS, to be honest, and I've never had
> the
>>> chance to use Ajax (but want to learn). What I have now is working,
> but
>>> I'd be happy to learn how to do it without refreshing the page --
> that
>>> does seem like a more elegant solution to me. What do you suggest? We
> do
>>> use JS for our app, but no JS framework as such as far as I can tell.
>>>
>>> Chris
>>>
>>> -----Original Message-----
>>> From: Musachy Barroso [mailto:musachy@gmail.com]
>>> Sent: Thursday, February 08, 2007 8:03 AM
>>> To: Struts Users Mailing List
>>> Subject: Re: Struts action call in a JS method returns blank page
>>>
>>> Like I said before you can use Ajax to submit the form, and the page
>>> won't
>>> refresh, how to do it depends on what JS framework you are using, if
>>> any.
>>>
>>> regards
>>> musachy
>>>
>>> On 2/8/07, Christopher Loschen <CL...@axeda.com> wrote:
>>>
>>>> Yes, you're right that the form submit was causing the system to
>>>>
>>> forward
>>>
>>>> to whatever the action said, which in my case was the blank page.
>>>>
>>> You'll see
>>>
>>>> from the later emails in the thread yesterday that I solved that by
>>>> forwarding to the action which populated the original page.
>>>>
>>>> I need the form.submit because I need to get the checked boxes from
>>>>
>>> the
>>>
>>>> form and I need to call the action specified in the action attribute
>>>>
>>> on that
>>>
>>>> form in order to put those checkbox values into the request in the
>>>>
>>> form that
>>>
>>>> my downstream code needs.
>>>>
>>>> Submitting the form is the only way I know to get the form values
> the
>>>>
>>> user
>>>
>>>> submits from the HTML page to my Java code -- are you saying that I
>>>>
>>> have
>>>
>>>> other alternatives?
>>>>
>>>> Chris
>>>>
>>>> ________________________________
>>>>
>>>> From: Yee Kai Lai [mailto:yeekai.lai@hotmail.com]
>>>> Sent: Thu 2/8/2007 12:24 AM
>>>> To: user@struts.apache.org
>>>> Subject: RE: Struts action call in a JS method returns blank page
>>>>
>>>>
>>>>
>>>>
>>>> It returns a blank page might be due to
>>>>
>>>> form.submit(); in your JS.
>>>>
>>>> I think if you have a form named
>>>>
>>> 'service.device.selected-devices-form'
>>>
>>>> then
>>>> it will never be null hence it will always submit.
>>>>
>>>> May you could enlightened why u need a form.submit() ?
>>>>
>>>>
>>>>
>>>>> From: "Christopher Loschen" <CL...@axeda.com>
>>>>> Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>>>>> To: <us...@struts.apache.org>
>>>>> Subject: Struts action call in a JS method returns blank page
>>>>> Date: Wed, 7 Feb 2007 14:14:35 -0500
>>>>>
>>>>> Hi all,
>>>>>
>>>>>
>>>>>
>>>>> I'm honestly unsure if I'm having a problem with Struts (sadly,
> 1.1)
>>>>>
>>> or
>>>
>>>>> with Javascript, or something else. But my best guess is it's a
>>>>>
>>> Struts
>>>
>>>>> issue, and anyway, there are a lot of very knowledgeable people on
>>>>>
>>> both
>>>
>>>>> of those technologies here, so I hope someone can help. Bottom
> line:
>>>>>
>>> I'm
>>>
>>>>> getting the popup with the correct values, but my main page under
> the
>>>>> popup becomes blank.
>>>>>
>>>>>
>>>>>
>>>>> I'm adding some functionality to an existing application. The
>>>>> functionality I'm adding takes the values from some checkboxes on
>>>>>
>>> page
>>>
>>>>> A, gets the corresponding devices from the checkbox values, and
> saves
>>>>> the resulting List into the request. Later down the stream, other
>>>>>
>>> code
>>>
>>>>> gets those values again and uses them as a list of devices on which
>>>>>
>>> to
>>>
>>>>> perform an action. Pretty straightforward.
>>>>>
>>>>>
>>>>>
>>>>> All of the actual navigation is happening via Javascript calls,
>>>>>
>>> starting
>>>
>>>>> with a link on page A, but outside the form where my checkboxes are
>>>>> declared. That link fires a Javascript function which pops up a
> small
>>>>> window with a list of actions which have been defined. If the user
>>>>>
>>> then
>>>
>>>>> clicks on one of those actions, another Javascript function fires
>>>>>
>>> which
>>>
>>>>> pops up another window to confirm that the user wants to perform
> the
>>>>> selected action on the selected devices.
>>>>>
>>>>>
>>>>>
>>>>> I have inserted my added functionality into that second script.
>>>>> Basically I need to submit the appropriate form on the page. I've
>>>>> defined it with the correct action and I've got a mapping in my
>>>>> struts-config.xml file:
>>>>>
>>>>>
>>>>>
>>>>>     <form-bean
>>>>>
>>>>>      name="service.device.selected-devices-form"
>>>>>
>>>>>      type="com.xxx.webapp.common.CheckboxForm"/>
>>>>>
>>>>> ...
>>>>>
>>>>>     <action path="/service/device/actions/store-selected-devices"
>>>>>
>>>>>
>>>>> type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
>>>>>
>>>>>             name="service.device.selected-devices-form" />
>>>>>
>>>>>
>>>>>
>>>>> The mapping doesn't have any action forwards defined because it
>>>>>
>>> doesn't
>>>
>>>>> actually need to go anywhere (though that might be part of my
>>>>>
>>> problem).
>>>
>>>>> The JS function looks like this:
>>>>>
>>>>>
>>>>>
>>>>> function popActionConfirm(url) {
>>>>>
>>>>>
>>>>>
>>>>>   var form =
> document.forms['service.device.selected-devices-form'];
>>>>>
>>>>>   if (form!=null) form.submit();
>>>>>
>>>>>
>>>>>
>>>>>   var winl = (screen.width - 500) / 2;
>>>>>
>>>>>
>>>>>
>>>>>   var wint = (screen.height - 350) / 2;
>>>>>
>>>>>
>>>>>
>>>>>     winprops =
>>>>>
>>>>
> 'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable
>>>>
>>> =
>>>
>>>>> 0';
>>>>>
>>>>>
>>>>>
>>>>>   var child = window.open(url,"action_confirm", winprops);
>>>>>
>>>>>
>>>>>
>>>>>   self.name="main_window";
>>>>>
>>>>>
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> I added the first two lines of the JS method - it worked correctly
>>>>> before I put those in (though of course it didn't have my added
>>>>> functionality in place). The popup window does appear, and it has
> the
>>>>> correct values in it (that is, the devices which were selected).
> But
>>>>>
>>> the
>>>
>>>>> main window goes blank where before it remained unchanged. When
> I've
>>>>> seen blank pages like this before, it meant there was a bad action
>>>>> forward in the struts-config file, but I don't want the main page
> to
>>>>> change at all, so what I really want is for the main page to just
>>>>>
>>> stay
>>>
>>>>> in place as it was before the form was submitted.
>>>>>
>>>>>
>>>>>
>>>>> How do I go about doing that? Thanks!
>>>>>
>>>>>
>>>>>
>>>>> Chris Loschen
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>> _________________________________________________________________
>>>> Receive MSN Hotmail alerts over SMS!
>>>> http://en-asiasms.mobile.msn.com/ac.aspx?cid=1002
>>>>
>>>>
>>>>
> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts action call in a JS method returns blank page

Posted by Christopher Loschen <CL...@axeda.com>.
Thanks Frank -- I've been reading your posts on JWP with great interest
for quite a while, and I'll bet your book is another good resource.

The current project (or at least this piece of it) has to be finished by
tomorrow, so I may not be able to introduce Ajax just yet. However, I'm
definitely interested in learning more about it, and will no doubt use
it more as I learn more.

Meanwhile, I'm looking at a possibly related problem. We've got
checkboxes on multiple pages and a JS function which keeps track of
which boxes are checked on which page so that we can go from page to
page and retain the boxes checked on other pages. That works by putting
the checkbox ids into the URL for the page. It's working correctly, more
or less, but now I find that when I actually am ready to use the array
of checkboxes, I'm getting only the ones on the current page, not the
rest. My Java method is getting the correct request parameters, but it
always returns null. Perhaps that's because the request parameters are
associated with one action (which displays the appropriate page of the
list) and my action class is associated with a different action (to
store the checkbox values and process the result)? If that's right, I
guess I need to get those values into my action too. Does that sound
like a reasonable guess?

Chris

-----Original Message-----
From: Frank W. Zammetti [mailto:fzlists@omnytex.com] 
Sent: Thursday, February 08, 2007 10:30 AM
To: Struts Users Mailing List
Cc: Struts Users Mailing List
Subject: Re: Struts action call in a JS method returns blank page

Theres a ton of choice on which AJAX library to use, many of them very
good.  However, since your working in Java specifically, and since you
say
you are not all that familiar with JS, you may prefer a solution that
will
(in most cases) require ZERO Javascript coding, and such a thing exists:

http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/tagl
ib/package-summary.html

This is the AjaxParts Taglib (APT), which is a part of Java Web Parts
(JWP):

http://javawebparts.sourceforge.net

With this, let's say you want to update a specific <div> in response to
a
button being clicked on a page with some data returned by the server
without refreshing the page, in your JSP you would have:

<div id="myDiv">Response will go here</div>
<input type="button" value="Click for AJAX"><ajax:event
ajaxRef="ajaxFunctions/button1" />
<ajax:enable />

That's it, no JavaScript at all!  The other piece to the puzzle is an
XML
file like so:

<ajaxConfig>
  <group ajaxRef="ajaxFunctions">
    <element ajaxRef="button1">
       <event type="onClick">
         <requestHandler type="std:SimpleRequest" target="/myURL">
           <parameter></parameter>
        </requestHandler>
        <responseHandler type="std:InnerHTML">
          <parameter>myDiv</parameter>
        </responseHandler>
      </event>
    </element>
  </group>
</ajaxConfig>

The XML file maps via the ajaxRef values to the ajaxRef in the
<ajax:event> tag, and it defines what's going to happen in response to
some event (onClick in this case), which in this case is simply an AJAX
request to /myURL with no data passed, and then what happens when the
response comes back, which is it will be inserted into myDiv via
innerHTML.

There's a whole bunch of request and response handlers available out of
the box which tend to cover most needs, things like submitting forms,
executing some returned Javascript, sending XML automatically
constructed
from form data, transforming returned XML via XLT, and so on.  You also
have the ability to write your own handlers (just plain Javascript) if
you
need something that isn't covered.

hth,
Frank


-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
 (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
 Supplying the wheel, so you don't have to reinvent it!

On Thu, February 8, 2007 9:49 am, Musachy Barroso wrote:
> Check Prototype out, here is a good tutorial:
> http://www.sergiopereira.com/articles/prototype.js.html, basically
what
> you need is something like:
>
> |**var myAjax = new Ajax.Request(
> 			url,
> 			{
> 				method: 'get',
> 				parameters: Form.serialize("formid"),
> 				onComplete: function() {
> 				    //do something here, or not :)
> 				}
> 			});**|
>
> regards
> musachy
>
> Christopher Loschen wrote:
>> I'm not all that familiar with JS, to be honest, and I've never had
the
>> chance to use Ajax (but want to learn). What I have now is working,
but
>> I'd be happy to learn how to do it without refreshing the page --
that
>> does seem like a more elegant solution to me. What do you suggest? We
do
>> use JS for our app, but no JS framework as such as far as I can tell.
>>
>> Chris
>>
>> -----Original Message-----
>> From: Musachy Barroso [mailto:musachy@gmail.com]
>> Sent: Thursday, February 08, 2007 8:03 AM
>> To: Struts Users Mailing List
>> Subject: Re: Struts action call in a JS method returns blank page
>>
>> Like I said before you can use Ajax to submit the form, and the page
>> won't
>> refresh, how to do it depends on what JS framework you are using, if
>> any.
>>
>> regards
>> musachy
>>
>> On 2/8/07, Christopher Loschen <CL...@axeda.com> wrote:
>>
>>> Yes, you're right that the form submit was causing the system to
>>>
>> forward
>>
>>> to whatever the action said, which in my case was the blank page.
>>>
>> You'll see
>>
>>> from the later emails in the thread yesterday that I solved that by
>>> forwarding to the action which populated the original page.
>>>
>>> I need the form.submit because I need to get the checked boxes from
>>>
>> the
>>
>>> form and I need to call the action specified in the action attribute
>>>
>> on that
>>
>>> form in order to put those checkbox values into the request in the
>>>
>> form that
>>
>>> my downstream code needs.
>>>
>>> Submitting the form is the only way I know to get the form values
the
>>>
>> user
>>
>>> submits from the HTML page to my Java code -- are you saying that I
>>>
>> have
>>
>>> other alternatives?
>>>
>>> Chris
>>>
>>> ________________________________
>>>
>>> From: Yee Kai Lai [mailto:yeekai.lai@hotmail.com]
>>> Sent: Thu 2/8/2007 12:24 AM
>>> To: user@struts.apache.org
>>> Subject: RE: Struts action call in a JS method returns blank page
>>>
>>>
>>>
>>>
>>> It returns a blank page might be due to
>>>
>>> form.submit(); in your JS.
>>>
>>> I think if you have a form named
>>>
>> 'service.device.selected-devices-form'
>>
>>> then
>>> it will never be null hence it will always submit.
>>>
>>> May you could enlightened why u need a form.submit() ?
>>>
>>>
>>>
>>>> From: "Christopher Loschen" <CL...@axeda.com>
>>>> Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>>>> To: <us...@struts.apache.org>
>>>> Subject: Struts action call in a JS method returns blank page
>>>> Date: Wed, 7 Feb 2007 14:14:35 -0500
>>>>
>>>> Hi all,
>>>>
>>>>
>>>>
>>>> I'm honestly unsure if I'm having a problem with Struts (sadly,
1.1)
>>>>
>> or
>>
>>>> with Javascript, or something else. But my best guess is it's a
>>>>
>> Struts
>>
>>>> issue, and anyway, there are a lot of very knowledgeable people on
>>>>
>> both
>>
>>>> of those technologies here, so I hope someone can help. Bottom
line:
>>>>
>> I'm
>>
>>>> getting the popup with the correct values, but my main page under
the
>>>> popup becomes blank.
>>>>
>>>>
>>>>
>>>> I'm adding some functionality to an existing application. The
>>>> functionality I'm adding takes the values from some checkboxes on
>>>>
>> page
>>
>>>> A, gets the corresponding devices from the checkbox values, and
saves
>>>> the resulting List into the request. Later down the stream, other
>>>>
>> code
>>
>>>> gets those values again and uses them as a list of devices on which
>>>>
>> to
>>
>>>> perform an action. Pretty straightforward.
>>>>
>>>>
>>>>
>>>> All of the actual navigation is happening via Javascript calls,
>>>>
>> starting
>>
>>>> with a link on page A, but outside the form where my checkboxes are
>>>> declared. That link fires a Javascript function which pops up a
small
>>>> window with a list of actions which have been defined. If the user
>>>>
>> then
>>
>>>> clicks on one of those actions, another Javascript function fires
>>>>
>> which
>>
>>>> pops up another window to confirm that the user wants to perform
the
>>>> selected action on the selected devices.
>>>>
>>>>
>>>>
>>>> I have inserted my added functionality into that second script.
>>>> Basically I need to submit the appropriate form on the page. I've
>>>> defined it with the correct action and I've got a mapping in my
>>>> struts-config.xml file:
>>>>
>>>>
>>>>
>>>>     <form-bean
>>>>
>>>>      name="service.device.selected-devices-form"
>>>>
>>>>      type="com.xxx.webapp.common.CheckboxForm"/>
>>>>
>>>> ...
>>>>
>>>>     <action path="/service/device/actions/store-selected-devices"
>>>>
>>>>
>>>> type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
>>>>
>>>>             name="service.device.selected-devices-form" />
>>>>
>>>>
>>>>
>>>> The mapping doesn't have any action forwards defined because it
>>>>
>> doesn't
>>
>>>> actually need to go anywhere (though that might be part of my
>>>>
>> problem).
>>
>>>> The JS function looks like this:
>>>>
>>>>
>>>>
>>>> function popActionConfirm(url) {
>>>>
>>>>
>>>>
>>>>   var form =
document.forms['service.device.selected-devices-form'];
>>>>
>>>>   if (form!=null) form.submit();
>>>>
>>>>
>>>>
>>>>   var winl = (screen.width - 500) / 2;
>>>>
>>>>
>>>>
>>>>   var wint = (screen.height - 350) / 2;
>>>>
>>>>
>>>>
>>>>     winprops =
>>>>
>>>
'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable
>>>
>> =
>>
>>>> 0';
>>>>
>>>>
>>>>
>>>>   var child = window.open(url,"action_confirm", winprops);
>>>>
>>>>
>>>>
>>>>   self.name="main_window";
>>>>
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> I added the first two lines of the JS method - it worked correctly
>>>> before I put those in (though of course it didn't have my added
>>>> functionality in place). The popup window does appear, and it has
the
>>>> correct values in it (that is, the devices which were selected).
But
>>>>
>> the
>>
>>>> main window goes blank where before it remained unchanged. When
I've
>>>> seen blank pages like this before, it meant there was a bad action
>>>> forward in the struts-config file, but I don't want the main page
to
>>>> change at all, so what I really want is for the main page to just
>>>>
>> stay
>>
>>>> in place as it was before the form was submitted.
>>>>
>>>>
>>>>
>>>> How do I go about doing that? Thanks!
>>>>
>>>>
>>>>
>>>> Chris Loschen
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>> _________________________________________________________________
>>> Receive MSN Hotmail alerts over SMS!
>>> http://en-asiasms.mobile.msn.com/ac.aspx?cid=1002
>>>
>>>
>>>
---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts action call in a JS method returns blank page

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Theres a ton of choice on which AJAX library to use, many of them very
good.  However, since your working in Java specifically, and since you say
you are not all that familiar with JS, you may prefer a solution that will
(in most cases) require ZERO Javascript coding, and such a thing exists:

http://javawebparts.sourceforge.net/javadocs/javawebparts/ajaxparts/taglib/package-summary.html

This is the AjaxParts Taglib (APT), which is a part of Java Web Parts (JWP):

http://javawebparts.sourceforge.net

With this, let's say you want to update a specific <div> in response to a
button being clicked on a page with some data returned by the server
without refreshing the page, in your JSP you would have:

<div id="myDiv">Response will go here</div>
<input type="button" value="Click for AJAX"><ajax:event
ajaxRef="ajaxFunctions/button1" />
<ajax:enable />

That's it, no JavaScript at all!  The other piece to the puzzle is an XML
file like so:

<ajaxConfig>
  <group ajaxRef="ajaxFunctions">
    <element ajaxRef="button1">
       <event type="onClick">
         <requestHandler type="std:SimpleRequest" target="/myURL">
           <parameter></parameter>
        </requestHandler>
        <responseHandler type="std:InnerHTML">
          <parameter>myDiv</parameter>
        </responseHandler>
      </event>
    </element>
  </group>
</ajaxConfig>

The XML file maps via the ajaxRef values to the ajaxRef in the
<ajax:event> tag, and it defines what's going to happen in response to
some event (onClick in this case), which in this case is simply an AJAX
request to /myURL with no data passed, and then what happens when the
response comes back, which is it will be inserted into myDiv via
innerHTML.

There's a whole bunch of request and response handlers available out of
the box which tend to cover most needs, things like submitting forms,
executing some returned Javascript, sending XML automatically constructed
from form data, transforming returned XML via XLT, and so on.  You also
have the ability to write your own handlers (just plain Javascript) if you
need something that isn't covered.

hth,
Frank


-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
 (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
 Supplying the wheel, so you don't have to reinvent it!

On Thu, February 8, 2007 9:49 am, Musachy Barroso wrote:
> Check Prototype out, here is a good tutorial:
> http://www.sergiopereira.com/articles/prototype.js.html, basically what
> you need is something like:
>
> |**var myAjax = new Ajax.Request(
> 			url,
> 			{
> 				method: 'get',
> 				parameters: Form.serialize("formid"),
> 				onComplete: function() {
> 				    //do something here, or not :)
> 				}
> 			});**|
>
> regards
> musachy
>
> Christopher Loschen wrote:
>> I'm not all that familiar with JS, to be honest, and I've never had the
>> chance to use Ajax (but want to learn). What I have now is working, but
>> I'd be happy to learn how to do it without refreshing the page -- that
>> does seem like a more elegant solution to me. What do you suggest? We do
>> use JS for our app, but no JS framework as such as far as I can tell.
>>
>> Chris
>>
>> -----Original Message-----
>> From: Musachy Barroso [mailto:musachy@gmail.com]
>> Sent: Thursday, February 08, 2007 8:03 AM
>> To: Struts Users Mailing List
>> Subject: Re: Struts action call in a JS method returns blank page
>>
>> Like I said before you can use Ajax to submit the form, and the page
>> won't
>> refresh, how to do it depends on what JS framework you are using, if
>> any.
>>
>> regards
>> musachy
>>
>> On 2/8/07, Christopher Loschen <CL...@axeda.com> wrote:
>>
>>> Yes, you're right that the form submit was causing the system to
>>>
>> forward
>>
>>> to whatever the action said, which in my case was the blank page.
>>>
>> You'll see
>>
>>> from the later emails in the thread yesterday that I solved that by
>>> forwarding to the action which populated the original page.
>>>
>>> I need the form.submit because I need to get the checked boxes from
>>>
>> the
>>
>>> form and I need to call the action specified in the action attribute
>>>
>> on that
>>
>>> form in order to put those checkbox values into the request in the
>>>
>> form that
>>
>>> my downstream code needs.
>>>
>>> Submitting the form is the only way I know to get the form values the
>>>
>> user
>>
>>> submits from the HTML page to my Java code -- are you saying that I
>>>
>> have
>>
>>> other alternatives?
>>>
>>> Chris
>>>
>>> ________________________________
>>>
>>> From: Yee Kai Lai [mailto:yeekai.lai@hotmail.com]
>>> Sent: Thu 2/8/2007 12:24 AM
>>> To: user@struts.apache.org
>>> Subject: RE: Struts action call in a JS method returns blank page
>>>
>>>
>>>
>>>
>>> It returns a blank page might be due to
>>>
>>> form.submit(); in your JS.
>>>
>>> I think if you have a form named
>>>
>> 'service.device.selected-devices-form'
>>
>>> then
>>> it will never be null hence it will always submit.
>>>
>>> May you could enlightened why u need a form.submit() ?
>>>
>>>
>>>
>>>> From: "Christopher Loschen" <CL...@axeda.com>
>>>> Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>>>> To: <us...@struts.apache.org>
>>>> Subject: Struts action call in a JS method returns blank page
>>>> Date: Wed, 7 Feb 2007 14:14:35 -0500
>>>>
>>>> Hi all,
>>>>
>>>>
>>>>
>>>> I'm honestly unsure if I'm having a problem with Struts (sadly, 1.1)
>>>>
>> or
>>
>>>> with Javascript, or something else. But my best guess is it's a
>>>>
>> Struts
>>
>>>> issue, and anyway, there are a lot of very knowledgeable people on
>>>>
>> both
>>
>>>> of those technologies here, so I hope someone can help. Bottom line:
>>>>
>> I'm
>>
>>>> getting the popup with the correct values, but my main page under the
>>>> popup becomes blank.
>>>>
>>>>
>>>>
>>>> I'm adding some functionality to an existing application. The
>>>> functionality I'm adding takes the values from some checkboxes on
>>>>
>> page
>>
>>>> A, gets the corresponding devices from the checkbox values, and saves
>>>> the resulting List into the request. Later down the stream, other
>>>>
>> code
>>
>>>> gets those values again and uses them as a list of devices on which
>>>>
>> to
>>
>>>> perform an action. Pretty straightforward.
>>>>
>>>>
>>>>
>>>> All of the actual navigation is happening via Javascript calls,
>>>>
>> starting
>>
>>>> with a link on page A, but outside the form where my checkboxes are
>>>> declared. That link fires a Javascript function which pops up a small
>>>> window with a list of actions which have been defined. If the user
>>>>
>> then
>>
>>>> clicks on one of those actions, another Javascript function fires
>>>>
>> which
>>
>>>> pops up another window to confirm that the user wants to perform the
>>>> selected action on the selected devices.
>>>>
>>>>
>>>>
>>>> I have inserted my added functionality into that second script.
>>>> Basically I need to submit the appropriate form on the page. I've
>>>> defined it with the correct action and I've got a mapping in my
>>>> struts-config.xml file:
>>>>
>>>>
>>>>
>>>>     <form-bean
>>>>
>>>>      name="service.device.selected-devices-form"
>>>>
>>>>      type="com.xxx.webapp.common.CheckboxForm"/>
>>>>
>>>> ...
>>>>
>>>>     <action path="/service/device/actions/store-selected-devices"
>>>>
>>>>
>>>> type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
>>>>
>>>>             name="service.device.selected-devices-form" />
>>>>
>>>>
>>>>
>>>> The mapping doesn't have any action forwards defined because it
>>>>
>> doesn't
>>
>>>> actually need to go anywhere (though that might be part of my
>>>>
>> problem).
>>
>>>> The JS function looks like this:
>>>>
>>>>
>>>>
>>>> function popActionConfirm(url) {
>>>>
>>>>
>>>>
>>>>   var form = document.forms['service.device.selected-devices-form'];
>>>>
>>>>   if (form!=null) form.submit();
>>>>
>>>>
>>>>
>>>>   var winl = (screen.width - 500) / 2;
>>>>
>>>>
>>>>
>>>>   var wint = (screen.height - 350) / 2;
>>>>
>>>>
>>>>
>>>>     winprops =
>>>>
>>> 'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable
>>>
>> =
>>
>>>> 0';
>>>>
>>>>
>>>>
>>>>   var child = window.open(url,"action_confirm", winprops);
>>>>
>>>>
>>>>
>>>>   self.name="main_window";
>>>>
>>>>
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> I added the first two lines of the JS method - it worked correctly
>>>> before I put those in (though of course it didn't have my added
>>>> functionality in place). The popup window does appear, and it has the
>>>> correct values in it (that is, the devices which were selected). But
>>>>
>> the
>>
>>>> main window goes blank where before it remained unchanged. When I've
>>>> seen blank pages like this before, it meant there was a bad action
>>>> forward in the struts-config file, but I don't want the main page to
>>>> change at all, so what I really want is for the main page to just
>>>>
>> stay
>>
>>>> in place as it was before the form was submitted.
>>>>
>>>>
>>>>
>>>> How do I go about doing that? Thanks!
>>>>
>>>>
>>>>
>>>> Chris Loschen
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>> _________________________________________________________________
>>> Receive MSN Hotmail alerts over SMS!
>>> http://en-asiasms.mobile.msn.com/ac.aspx?cid=1002
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts action call in a JS method returns blank page

Posted by Musachy Barroso <mb...@wfscorp.com>.
Check Prototype out, here is a good tutorial: 
http://www.sergiopereira.com/articles/prototype.js.html, basically what 
you need is something like:

|**var myAjax = new Ajax.Request(
			url, 
			{
				method: 'get', 
				parameters: Form.serialize("formid"), 
				onComplete: function() {
				    //do something here, or not :)
				}
			});**|

regards
musachy

Christopher Loschen wrote:
> I'm not all that familiar with JS, to be honest, and I've never had the
> chance to use Ajax (but want to learn). What I have now is working, but
> I'd be happy to learn how to do it without refreshing the page -- that
> does seem like a more elegant solution to me. What do you suggest? We do
> use JS for our app, but no JS framework as such as far as I can tell. 
>
> Chris
>
> -----Original Message-----
> From: Musachy Barroso [mailto:musachy@gmail.com] 
> Sent: Thursday, February 08, 2007 8:03 AM
> To: Struts Users Mailing List
> Subject: Re: Struts action call in a JS method returns blank page
>
> Like I said before you can use Ajax to submit the form, and the page
> won't
> refresh, how to do it depends on what JS framework you are using, if
> any.
>
> regards
> musachy
>
> On 2/8/07, Christopher Loschen <CL...@axeda.com> wrote:
>   
>> Yes, you're right that the form submit was causing the system to
>>     
> forward
>   
>> to whatever the action said, which in my case was the blank page.
>>     
> You'll see
>   
>> from the later emails in the thread yesterday that I solved that by
>> forwarding to the action which populated the original page.
>>
>> I need the form.submit because I need to get the checked boxes from
>>     
> the
>   
>> form and I need to call the action specified in the action attribute
>>     
> on that
>   
>> form in order to put those checkbox values into the request in the
>>     
> form that
>   
>> my downstream code needs.
>>
>> Submitting the form is the only way I know to get the form values the
>>     
> user
>   
>> submits from the HTML page to my Java code -- are you saying that I
>>     
> have
>   
>> other alternatives?
>>
>> Chris
>>
>> ________________________________
>>
>> From: Yee Kai Lai [mailto:yeekai.lai@hotmail.com]
>> Sent: Thu 2/8/2007 12:24 AM
>> To: user@struts.apache.org
>> Subject: RE: Struts action call in a JS method returns blank page
>>
>>
>>
>>
>> It returns a blank page might be due to
>>
>> form.submit(); in your JS.
>>
>> I think if you have a form named
>>     
> 'service.device.selected-devices-form'
>   
>> then
>> it will never be null hence it will always submit.
>>
>> May you could enlightened why u need a form.submit() ?
>>
>>
>>     
>>> From: "Christopher Loschen" <CL...@axeda.com>
>>> Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>>> To: <us...@struts.apache.org>
>>> Subject: Struts action call in a JS method returns blank page
>>> Date: Wed, 7 Feb 2007 14:14:35 -0500
>>>
>>> Hi all,
>>>
>>>
>>>
>>> I'm honestly unsure if I'm having a problem with Struts (sadly, 1.1)
>>>       
> or
>   
>>> with Javascript, or something else. But my best guess is it's a
>>>       
> Struts
>   
>>> issue, and anyway, there are a lot of very knowledgeable people on
>>>       
> both
>   
>>> of those technologies here, so I hope someone can help. Bottom line:
>>>       
> I'm
>   
>>> getting the popup with the correct values, but my main page under the
>>> popup becomes blank.
>>>
>>>
>>>
>>> I'm adding some functionality to an existing application. The
>>> functionality I'm adding takes the values from some checkboxes on
>>>       
> page
>   
>>> A, gets the corresponding devices from the checkbox values, and saves
>>> the resulting List into the request. Later down the stream, other
>>>       
> code
>   
>>> gets those values again and uses them as a list of devices on which
>>>       
> to
>   
>>> perform an action. Pretty straightforward.
>>>
>>>
>>>
>>> All of the actual navigation is happening via Javascript calls,
>>>       
> starting
>   
>>> with a link on page A, but outside the form where my checkboxes are
>>> declared. That link fires a Javascript function which pops up a small
>>> window with a list of actions which have been defined. If the user
>>>       
> then
>   
>>> clicks on one of those actions, another Javascript function fires
>>>       
> which
>   
>>> pops up another window to confirm that the user wants to perform the
>>> selected action on the selected devices.
>>>
>>>
>>>
>>> I have inserted my added functionality into that second script.
>>> Basically I need to submit the appropriate form on the page. I've
>>> defined it with the correct action and I've got a mapping in my
>>> struts-config.xml file:
>>>
>>>
>>>
>>>     <form-bean
>>>
>>>      name="service.device.selected-devices-form"
>>>
>>>      type="com.xxx.webapp.common.CheckboxForm"/>
>>>
>>> ...
>>>
>>>     <action path="/service/device/actions/store-selected-devices"
>>>
>>>
>>> type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
>>>
>>>             name="service.device.selected-devices-form" />
>>>
>>>
>>>
>>> The mapping doesn't have any action forwards defined because it
>>>       
> doesn't
>   
>>> actually need to go anywhere (though that might be part of my
>>>       
> problem).
>   
>>> The JS function looks like this:
>>>
>>>
>>>
>>> function popActionConfirm(url) {
>>>
>>>
>>>
>>>   var form = document.forms['service.device.selected-devices-form'];
>>>
>>>   if (form!=null) form.submit();
>>>
>>>
>>>
>>>   var winl = (screen.width - 500) / 2;
>>>
>>>
>>>
>>>   var wint = (screen.height - 350) / 2;
>>>
>>>
>>>
>>>     winprops =
>>>       
>> 'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable
>>     
> =
>   
>>> 0';
>>>
>>>
>>>
>>>   var child = window.open(url,"action_confirm", winprops);
>>>
>>>
>>>
>>>   self.name="main_window";
>>>
>>>
>>>
>>> }
>>>
>>>
>>>
>>> I added the first two lines of the JS method - it worked correctly
>>> before I put those in (though of course it didn't have my added
>>> functionality in place). The popup window does appear, and it has the
>>> correct values in it (that is, the devices which were selected). But
>>>       
> the
>   
>>> main window goes blank where before it remained unchanged. When I've
>>> seen blank pages like this before, it meant there was a bad action
>>> forward in the struts-config file, but I don't want the main page to
>>> change at all, so what I really want is for the main page to just
>>>       
> stay
>   
>>> in place as it was before the form was submitted.
>>>
>>>
>>>
>>> How do I go about doing that? Thanks!
>>>
>>>
>>>
>>> Chris Loschen
>>>
>>>
>>>
>>>
>>>
>>>       
>> _________________________________________________________________
>> Receive MSN Hotmail alerts over SMS!
>> http://en-asiasms.mobile.msn.com/ac.aspx?cid=1002
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>>
>>     
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts action call in a JS method returns blank page

Posted by Christopher Loschen <CL...@axeda.com>.
I'm not all that familiar with JS, to be honest, and I've never had the
chance to use Ajax (but want to learn). What I have now is working, but
I'd be happy to learn how to do it without refreshing the page -- that
does seem like a more elegant solution to me. What do you suggest? We do
use JS for our app, but no JS framework as such as far as I can tell. 

Chris

-----Original Message-----
From: Musachy Barroso [mailto:musachy@gmail.com] 
Sent: Thursday, February 08, 2007 8:03 AM
To: Struts Users Mailing List
Subject: Re: Struts action call in a JS method returns blank page

Like I said before you can use Ajax to submit the form, and the page
won't
refresh, how to do it depends on what JS framework you are using, if
any.

regards
musachy

On 2/8/07, Christopher Loschen <CL...@axeda.com> wrote:
>
> Yes, you're right that the form submit was causing the system to
forward
> to whatever the action said, which in my case was the blank page.
You'll see
> from the later emails in the thread yesterday that I solved that by
> forwarding to the action which populated the original page.
>
> I need the form.submit because I need to get the checked boxes from
the
> form and I need to call the action specified in the action attribute
on that
> form in order to put those checkbox values into the request in the
form that
> my downstream code needs.
>
> Submitting the form is the only way I know to get the form values the
user
> submits from the HTML page to my Java code -- are you saying that I
have
> other alternatives?
>
> Chris
>
> ________________________________
>
> From: Yee Kai Lai [mailto:yeekai.lai@hotmail.com]
> Sent: Thu 2/8/2007 12:24 AM
> To: user@struts.apache.org
> Subject: RE: Struts action call in a JS method returns blank page
>
>
>
>
> It returns a blank page might be due to
>
> form.submit(); in your JS.
>
> I think if you have a form named
'service.device.selected-devices-form'
> then
> it will never be null hence it will always submit.
>
> May you could enlightened why u need a form.submit() ?
>
>
> >From: "Christopher Loschen" <CL...@axeda.com>
> >Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
> >To: <us...@struts.apache.org>
> >Subject: Struts action call in a JS method returns blank page
> >Date: Wed, 7 Feb 2007 14:14:35 -0500
> >
> >Hi all,
> >
> >
> >
> >I'm honestly unsure if I'm having a problem with Struts (sadly, 1.1)
or
> >with Javascript, or something else. But my best guess is it's a
Struts
> >issue, and anyway, there are a lot of very knowledgeable people on
both
> >of those technologies here, so I hope someone can help. Bottom line:
I'm
> >getting the popup with the correct values, but my main page under the
> >popup becomes blank.
> >
> >
> >
> >I'm adding some functionality to an existing application. The
> >functionality I'm adding takes the values from some checkboxes on
page
> >A, gets the corresponding devices from the checkbox values, and saves
> >the resulting List into the request. Later down the stream, other
code
> >gets those values again and uses them as a list of devices on which
to
> >perform an action. Pretty straightforward.
> >
> >
> >
> >All of the actual navigation is happening via Javascript calls,
starting
> >with a link on page A, but outside the form where my checkboxes are
> >declared. That link fires a Javascript function which pops up a small
> >window with a list of actions which have been defined. If the user
then
> >clicks on one of those actions, another Javascript function fires
which
> >pops up another window to confirm that the user wants to perform the
> >selected action on the selected devices.
> >
> >
> >
> >I have inserted my added functionality into that second script.
> >Basically I need to submit the appropriate form on the page. I've
> >defined it with the correct action and I've got a mapping in my
> >struts-config.xml file:
> >
> >
> >
> >     <form-bean
> >
> >      name="service.device.selected-devices-form"
> >
> >      type="com.xxx.webapp.common.CheckboxForm"/>
> >
> >...
> >
> >     <action path="/service/device/actions/store-selected-devices"
> >
> >
> >type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
> >
> >             name="service.device.selected-devices-form" />
> >
> >
> >
> >The mapping doesn't have any action forwards defined because it
doesn't
> >actually need to go anywhere (though that might be part of my
problem).
> >The JS function looks like this:
> >
> >
> >
> >function popActionConfirm(url) {
> >
> >
> >
> >   var form = document.forms['service.device.selected-devices-form'];
> >
> >   if (form!=null) form.submit();
> >
> >
> >
> >   var winl = (screen.width - 500) / 2;
> >
> >
> >
> >   var wint = (screen.height - 350) / 2;
> >
> >
> >
> >     winprops =
>
>'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable
=
> >0';
> >
> >
> >
> >   var child = window.open(url,"action_confirm", winprops);
> >
> >
> >
> >   self.name="main_window";
> >
> >
> >
> >}
> >
> >
> >
> >I added the first two lines of the JS method - it worked correctly
> >before I put those in (though of course it didn't have my added
> >functionality in place). The popup window does appear, and it has the
> >correct values in it (that is, the devices which were selected). But
the
> >main window goes blank where before it remained unchanged. When I've
> >seen blank pages like this before, it meant there was a bad action
> >forward in the struts-config file, but I don't want the main page to
> >change at all, so what I really want is for the main page to just
stay
> >in place as it was before the form was submitted.
> >
> >
> >
> >How do I go about doing that? Thanks!
> >
> >
> >
> >Chris Loschen
> >
> >
> >
> >
> >
>
> _________________________________________________________________
> Receive MSN Hotmail alerts over SMS!
> http://en-asiasms.mobile.msn.com/ac.aspx?cid=1002
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>


-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts action call in a JS method returns blank page

Posted by Musachy Barroso <mu...@gmail.com>.
Like I said before you can use Ajax to submit the form, and the page won't
refresh, how to do it depends on what JS framework you are using, if any.

regards
musachy

On 2/8/07, Christopher Loschen <CL...@axeda.com> wrote:
>
> Yes, you're right that the form submit was causing the system to forward
> to whatever the action said, which in my case was the blank page. You'll see
> from the later emails in the thread yesterday that I solved that by
> forwarding to the action which populated the original page.
>
> I need the form.submit because I need to get the checked boxes from the
> form and I need to call the action specified in the action attribute on that
> form in order to put those checkbox values into the request in the form that
> my downstream code needs.
>
> Submitting the form is the only way I know to get the form values the user
> submits from the HTML page to my Java code -- are you saying that I have
> other alternatives?
>
> Chris
>
> ________________________________
>
> From: Yee Kai Lai [mailto:yeekai.lai@hotmail.com]
> Sent: Thu 2/8/2007 12:24 AM
> To: user@struts.apache.org
> Subject: RE: Struts action call in a JS method returns blank page
>
>
>
>
> It returns a blank page might be due to
>
> form.submit(); in your JS.
>
> I think if you have a form named 'service.device.selected-devices-form'
> then
> it will never be null hence it will always submit.
>
> May you could enlightened why u need a form.submit() ?
>
>
> >From: "Christopher Loschen" <CL...@axeda.com>
> >Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
> >To: <us...@struts.apache.org>
> >Subject: Struts action call in a JS method returns blank page
> >Date: Wed, 7 Feb 2007 14:14:35 -0500
> >
> >Hi all,
> >
> >
> >
> >I'm honestly unsure if I'm having a problem with Struts (sadly, 1.1) or
> >with Javascript, or something else. But my best guess is it's a Struts
> >issue, and anyway, there are a lot of very knowledgeable people on both
> >of those technologies here, so I hope someone can help. Bottom line: I'm
> >getting the popup with the correct values, but my main page under the
> >popup becomes blank.
> >
> >
> >
> >I'm adding some functionality to an existing application. The
> >functionality I'm adding takes the values from some checkboxes on page
> >A, gets the corresponding devices from the checkbox values, and saves
> >the resulting List into the request. Later down the stream, other code
> >gets those values again and uses them as a list of devices on which to
> >perform an action. Pretty straightforward.
> >
> >
> >
> >All of the actual navigation is happening via Javascript calls, starting
> >with a link on page A, but outside the form where my checkboxes are
> >declared. That link fires a Javascript function which pops up a small
> >window with a list of actions which have been defined. If the user then
> >clicks on one of those actions, another Javascript function fires which
> >pops up another window to confirm that the user wants to perform the
> >selected action on the selected devices.
> >
> >
> >
> >I have inserted my added functionality into that second script.
> >Basically I need to submit the appropriate form on the page. I've
> >defined it with the correct action and I've got a mapping in my
> >struts-config.xml file:
> >
> >
> >
> >     <form-bean
> >
> >      name="service.device.selected-devices-form"
> >
> >      type="com.xxx.webapp.common.CheckboxForm"/>
> >
> >...
> >
> >     <action path="/service/device/actions/store-selected-devices"
> >
> >
> >type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
> >
> >             name="service.device.selected-devices-form" />
> >
> >
> >
> >The mapping doesn't have any action forwards defined because it doesn't
> >actually need to go anywhere (though that might be part of my problem).
> >The JS function looks like this:
> >
> >
> >
> >function popActionConfirm(url) {
> >
> >
> >
> >   var form = document.forms['service.device.selected-devices-form'];
> >
> >   if (form!=null) form.submit();
> >
> >
> >
> >   var winl = (screen.width - 500) / 2;
> >
> >
> >
> >   var wint = (screen.height - 350) / 2;
> >
> >
> >
> >     winprops =
> >'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable=
> >0';
> >
> >
> >
> >   var child = window.open(url,"action_confirm", winprops);
> >
> >
> >
> >   self.name="main_window";
> >
> >
> >
> >}
> >
> >
> >
> >I added the first two lines of the JS method - it worked correctly
> >before I put those in (though of course it didn't have my added
> >functionality in place). The popup window does appear, and it has the
> >correct values in it (that is, the devices which were selected). But the
> >main window goes blank where before it remained unchanged. When I've
> >seen blank pages like this before, it meant there was a bad action
> >forward in the struts-config file, but I don't want the main page to
> >change at all, so what I really want is for the main page to just stay
> >in place as it was before the form was submitted.
> >
> >
> >
> >How do I go about doing that? Thanks!
> >
> >
> >
> >Chris Loschen
> >
> >
> >
> >
> >
>
> _________________________________________________________________
> Receive MSN Hotmail alerts over SMS!
> http://en-asiasms.mobile.msn.com/ac.aspx?cid=1002
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>


-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

RE: Struts action call in a JS method returns blank page

Posted by Yee Kai Lai <ye...@hotmail.com>.
Its alright since you have forwarded to the action which populated the 
original page to solve the blank page problem. There are no other ways 
beside submitting form to allow your java code to recieve the parameter 
values passed from the jsp to action.

>From: "Christopher Loschen" <CL...@axeda.com>
>Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>To: <us...@struts.apache.org>
>Subject: RE: Struts action call in a JS method returns blank page
>Date: Thu, 8 Feb 2007 07:36:03 -0500
>
>Yes, you're right that the form submit was causing the system to forward to 
>whatever the action said, which in my case was the blank page. You'll see 
>from the later emails in the thread yesterday that I solved that by 
>forwarding to the action which populated the original page.
>
>I need the form.submit because I need to get the checked boxes from the 
>form and I need to call the action specified in the action attribute on 
>that form in order to put those checkbox values into the request in the 
>form that my downstream code needs.
>
>Submitting the form is the only way I know to get the form values the user 
>submits from the HTML page to my Java code -- are you saying that I have 
>other alternatives?
>
>Chris
>
>________________________________
>
>From: Yee Kai Lai [mailto:yeekai.lai@hotmail.com]
>Sent: Thu 2/8/2007 12:24 AM
>To: user@struts.apache.org
>Subject: RE: Struts action call in a JS method returns blank page
>
>
>
>
>It returns a blank page might be due to
>
>form.submit(); in your JS.
>
>I think if you have a form named 'service.device.selected-devices-form' 
>then
>it will never be null hence it will always submit.
>
>May you could enlightened why u need a form.submit() ?
>
>
> >From: "Christopher Loschen" <CL...@axeda.com>
> >Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
> >To: <us...@struts.apache.org>
> >Subject: Struts action call in a JS method returns blank page
> >Date: Wed, 7 Feb 2007 14:14:35 -0500
> >
> >Hi all,
> >
> >
> >
> >I'm honestly unsure if I'm having a problem with Struts (sadly, 1.1) or
> >with Javascript, or something else. But my best guess is it's a Struts
> >issue, and anyway, there are a lot of very knowledgeable people on both
> >of those technologies here, so I hope someone can help. Bottom line: I'm
> >getting the popup with the correct values, but my main page under the
> >popup becomes blank.
> >
> >
> >
> >I'm adding some functionality to an existing application. The
> >functionality I'm adding takes the values from some checkboxes on page
> >A, gets the corresponding devices from the checkbox values, and saves
> >the resulting List into the request. Later down the stream, other code
> >gets those values again and uses them as a list of devices on which to
> >perform an action. Pretty straightforward.
> >
> >
> >
> >All of the actual navigation is happening via Javascript calls, starting
> >with a link on page A, but outside the form where my checkboxes are
> >declared. That link fires a Javascript function which pops up a small
> >window with a list of actions which have been defined. If the user then
> >clicks on one of those actions, another Javascript function fires which
> >pops up another window to confirm that the user wants to perform the
> >selected action on the selected devices.
> >
> >
> >
> >I have inserted my added functionality into that second script.
> >Basically I need to submit the appropriate form on the page. I've
> >defined it with the correct action and I've got a mapping in my
> >struts-config.xml file:
> >
> >
> >
> >     <form-bean
> >
> >      name="service.device.selected-devices-form"
> >
> >      type="com.xxx.webapp.common.CheckboxForm"/>
> >
> >...
> >
> >     <action path="/service/device/actions/store-selected-devices"
> >
> >
> >type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
> >
> >             name="service.device.selected-devices-form" />
> >
> >
> >
> >The mapping doesn't have any action forwards defined because it doesn't
> >actually need to go anywhere (though that might be part of my problem).
> >The JS function looks like this:
> >
> >
> >
> >function popActionConfirm(url) {
> >
> >
> >
> >   var form = document.forms['service.device.selected-devices-form'];
> >
> >   if (form!=null) form.submit();
> >
> >
> >
> >   var winl = (screen.width - 500) / 2;
> >
> >
> >
> >   var wint = (screen.height - 350) / 2;
> >
> >
> >
> >     winprops =
> >'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable=
> >0';
> >
> >
> >
> >   var child = window.open(url,"action_confirm", winprops);
> >
> >
> >
> >   self.name="main_window";
> >
> >
> >
> >}
> >
> >
> >
> >I added the first two lines of the JS method - it worked correctly
> >before I put those in (though of course it didn't have my added
> >functionality in place). The popup window does appear, and it has the
> >correct values in it (that is, the devices which were selected). But the
> >main window goes blank where before it remained unchanged. When I've
> >seen blank pages like this before, it meant there was a bad action
> >forward in the struts-config file, but I don't want the main page to
> >change at all, so what I really want is for the main page to just stay
> >in place as it was before the form was submitted.
> >
> >
> >
> >How do I go about doing that? Thanks!
> >
> >
> >
> >Chris Loschen
> >
> >
> >
> >
> >
>
>_________________________________________________________________
>Receive MSN Hotmail alerts over SMS!
>http://en-asiasms.mobile.msn.com/ac.aspx?cid=1002
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>

_________________________________________________________________
Find just what you are after with the more precise, more powerful new 
Windows Live Search. http://search.msn.com.sg/ Try it now.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts action call in a JS method returns blank page

Posted by Christopher Loschen <CL...@axeda.com>.
Yes, you're right that the form submit was causing the system to forward to whatever the action said, which in my case was the blank page. You'll see from the later emails in the thread yesterday that I solved that by forwarding to the action which populated the original page.
 
I need the form.submit because I need to get the checked boxes from the form and I need to call the action specified in the action attribute on that form in order to put those checkbox values into the request in the form that my downstream code needs.
 
Submitting the form is the only way I know to get the form values the user submits from the HTML page to my Java code -- are you saying that I have other alternatives?
 
Chris

________________________________

From: Yee Kai Lai [mailto:yeekai.lai@hotmail.com]
Sent: Thu 2/8/2007 12:24 AM
To: user@struts.apache.org
Subject: RE: Struts action call in a JS method returns blank page




It returns a blank page might be due to

form.submit(); in your JS.

I think if you have a form named 'service.device.selected-devices-form' then
it will never be null hence it will always submit.

May you could enlightened why u need a form.submit() ?


>From: "Christopher Loschen" <CL...@axeda.com>
>Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>To: <us...@struts.apache.org>
>Subject: Struts action call in a JS method returns blank page
>Date: Wed, 7 Feb 2007 14:14:35 -0500
>
>Hi all,
>
>
>
>I'm honestly unsure if I'm having a problem with Struts (sadly, 1.1) or
>with Javascript, or something else. But my best guess is it's a Struts
>issue, and anyway, there are a lot of very knowledgeable people on both
>of those technologies here, so I hope someone can help. Bottom line: I'm
>getting the popup with the correct values, but my main page under the
>popup becomes blank.
>
>
>
>I'm adding some functionality to an existing application. The
>functionality I'm adding takes the values from some checkboxes on page
>A, gets the corresponding devices from the checkbox values, and saves
>the resulting List into the request. Later down the stream, other code
>gets those values again and uses them as a list of devices on which to
>perform an action. Pretty straightforward.
>
>
>
>All of the actual navigation is happening via Javascript calls, starting
>with a link on page A, but outside the form where my checkboxes are
>declared. That link fires a Javascript function which pops up a small
>window with a list of actions which have been defined. If the user then
>clicks on one of those actions, another Javascript function fires which
>pops up another window to confirm that the user wants to perform the
>selected action on the selected devices.
>
>
>
>I have inserted my added functionality into that second script.
>Basically I need to submit the appropriate form on the page. I've
>defined it with the correct action and I've got a mapping in my
>struts-config.xml file:
>
>
>
>     <form-bean
>
>      name="service.device.selected-devices-form"
>
>      type="com.xxx.webapp.common.CheckboxForm"/>
>
>...
>
>     <action path="/service/device/actions/store-selected-devices"
>
>
>type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
>
>             name="service.device.selected-devices-form" />
>
>
>
>The mapping doesn't have any action forwards defined because it doesn't
>actually need to go anywhere (though that might be part of my problem).
>The JS function looks like this:
>
>
>
>function popActionConfirm(url) {
>
>
>
>   var form = document.forms['service.device.selected-devices-form'];
>
>   if (form!=null) form.submit();
>
>
>
>   var winl = (screen.width - 500) / 2;
>
>
>
>   var wint = (screen.height - 350) / 2;
>
>
>
>     winprops =
>'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable=
>0';
>
>
>
>   var child = window.open(url,"action_confirm", winprops);
>
>
>
>   self.name="main_window";
>
>
>
>}
>
>
>
>I added the first two lines of the JS method - it worked correctly
>before I put those in (though of course it didn't have my added
>functionality in place). The popup window does appear, and it has the
>correct values in it (that is, the devices which were selected). But the
>main window goes blank where before it remained unchanged. When I've
>seen blank pages like this before, it meant there was a bad action
>forward in the struts-config file, but I don't want the main page to
>change at all, so what I really want is for the main page to just stay
>in place as it was before the form was submitted.
>
>
>
>How do I go about doing that? Thanks!
>
>
>
>Chris Loschen
>
>
>
>
>

_________________________________________________________________
Receive MSN Hotmail alerts over SMS!
http://en-asiasms.mobile.msn.com/ac.aspx?cid=1002


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org




RE: Struts action call in a JS method returns blank page

Posted by Yee Kai Lai <ye...@hotmail.com>.
It returns a blank page might be due to

form.submit(); in your JS.

I think if you have a form named 'service.device.selected-devices-form' then 
it will never be null hence it will always submit.

May you could enlightened why u need a form.submit() ?


>From: "Christopher Loschen" <CL...@axeda.com>
>Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
>To: <us...@struts.apache.org>
>Subject: Struts action call in a JS method returns blank page
>Date: Wed, 7 Feb 2007 14:14:35 -0500
>
>Hi all,
>
>
>
>I'm honestly unsure if I'm having a problem with Struts (sadly, 1.1) or
>with Javascript, or something else. But my best guess is it's a Struts
>issue, and anyway, there are a lot of very knowledgeable people on both
>of those technologies here, so I hope someone can help. Bottom line: I'm
>getting the popup with the correct values, but my main page under the
>popup becomes blank.
>
>
>
>I'm adding some functionality to an existing application. The
>functionality I'm adding takes the values from some checkboxes on page
>A, gets the corresponding devices from the checkbox values, and saves
>the resulting List into the request. Later down the stream, other code
>gets those values again and uses them as a list of devices on which to
>perform an action. Pretty straightforward.
>
>
>
>All of the actual navigation is happening via Javascript calls, starting
>with a link on page A, but outside the form where my checkboxes are
>declared. That link fires a Javascript function which pops up a small
>window with a list of actions which have been defined. If the user then
>clicks on one of those actions, another Javascript function fires which
>pops up another window to confirm that the user wants to perform the
>selected action on the selected devices.
>
>
>
>I have inserted my added functionality into that second script.
>Basically I need to submit the appropriate form on the page. I've
>defined it with the correct action and I've got a mapping in my
>struts-config.xml file:
>
>
>
>     <form-bean
>
>      name="service.device.selected-devices-form"
>
>      type="com.xxx.webapp.common.CheckboxForm"/>
>
>...
>
>     <action path="/service/device/actions/store-selected-devices"
>
>
>type="com.xxx.webapp.service.list.StoreSelectedDevicesAction"
>
>             name="service.device.selected-devices-form" />
>
>
>
>The mapping doesn't have any action forwards defined because it doesn't
>actually need to go anywhere (though that might be part of my problem).
>The JS function looks like this:
>
>
>
>function popActionConfirm(url) {
>
>
>
>   var form = document.forms['service.device.selected-devices-form'];
>
>   if (form!=null) form.submit();
>
>
>
>   var winl = (screen.width - 500) / 2;
>
>
>
>   var wint = (screen.height - 350) / 2;
>
>
>
>     winprops =
>'height=250,width=375,top='+wint+',left='+winl+',scrollbars=0,resizable=
>0';
>
>
>
>   var child = window.open(url,"action_confirm", winprops);
>
>
>
>   self.name="main_window";
>
>
>
>}
>
>
>
>I added the first two lines of the JS method - it worked correctly
>before I put those in (though of course it didn't have my added
>functionality in place). The popup window does appear, and it has the
>correct values in it (that is, the devices which were selected). But the
>main window goes blank where before it remained unchanged. When I've
>seen blank pages like this before, it meant there was a bad action
>forward in the struts-config file, but I don't want the main page to
>change at all, so what I really want is for the main page to just stay
>in place as it was before the form was submitted.
>
>
>
>How do I go about doing that? Thanks!
>
>
>
>Chris Loschen
>
>
>
>
>

_________________________________________________________________
Receive MSN Hotmail alerts over SMS! 
http://en-asiasms.mobile.msn.com/ac.aspx?cid=1002


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org