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@(protected)]
> 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@(protected)]
>> 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@(protected)
>> 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@(protected)]
>>>> 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 <CLoschen@(protected):
>>>>
>>>>
>>>>> 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@(protected)]
>>>>> Sent: Thu 2/8/2007 12:24 AM
>>>>> To: user@(protected)
>>>>> 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" <CLoschen@(protected)>
>>>>>> Reply-To: "Struts Users Mailing List" <user@(protected)>
>>>>>> To: <user@(protected)>
>>>>>> 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@(protected)
>>>>> For additional commands, e-mail: user-help@(protected)
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>>> For additional commands, e-mail: user-help@(protected)
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>> For additional commands, e-mail: user-help@(protected)
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>> For additional commands, e-mail: user-help@(protected)
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)