This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Struts and the fly likes AJAX+STRUTS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "AJAX+STRUTS" Watch "AJAX+STRUTS" New topic
Author

AJAX+STRUTS

Manoj Amrutkar
Ranch Hand

Joined: Apr 15, 2006
Posts: 47


Above is the javascript function which gets called on body load first up and automatically then onwards with set timer

The problem i am facing is when first up the body gets loaded the action for ../cm.do gets called but not after

What could be the reason for this?

Is there any other way?

I think Merril you can help in this regard, as you allready have solved my related problem...

Thanks in Advance
Manoj Amrutkar
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The JavaScript setTimeout method executes code only once after the specified interval. If you want the code to execute every 5 seconds, you need to use the setInterval() method.

Also, I'd suggest making req a global variable, and splitting the above function into two functions: one to initialize req, and another to send the message. Only the function to send the message should be put in the setInterval loop.


Merrill
Consultant, Sima Solutions
Manoj Amrutkar
Ranch Hand

Joined: Apr 15, 2006
Posts: 47
Hi,
i have called that setTimeout function in calling function(second last line of the code) so basically it's unconditional loop.
That is not the problem also i have tried alert and it fires message after some time interval.
but there is something else which is giving problem i do have some other code of javascript function is it might be creating problem?



addMessages function is called on some onclick of button.


Thanks in advance
Manoj Amrutkar
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Yes, I see what you mean about the recursive call. You might try increasing the time interval. It could be that the request isn't able to complete in the time allotted.

Also, try my earlier suggestion about only initializing the request once, and then doing the "send" part in a loop.
Manoj Amrutkar
Ranch Hand

Joined: Apr 15, 2006
Posts: 47
Hi Merrill,
Well i got stuck man why this action is not been called after some time interval?
Please try out following code.....

//NewAction.java


Thanks
Manoj
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In the case of an action called with through AJAX, I'd recommend you format the response directly using the HttpServletResponse object's PrintWriter and then retun null from the execute() method.

See the example toward the end of this thread.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: AJAX+STRUTS