As an added note it does have something to do with the jsp. I did the
example with the ruby server and was able to add 20 items without an
issue.
On Apr 4, 9:35 am, sasonline
<ssta...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I have been messing with this for a couple of days now and didn''t
find
> anything when I searched the group. I am trying to learn Prototype
> and ran across something weird with the events in Ajax.Updater. Here
> is a simple example to illustrate my problem (stright from the
> Prototype and script.aculo.us book example using jsp & jboss instead
> of ruby scripts). The example is pretty simple. The html file loads
> the todo.js which after the dom is loaded we tell the form submit to
> route to an ajax call. The route to ajax function simply calls a
> Ajax.Updater that on load disables all the input controls and on
> complete re-enables them. The problem I am seeing is that although
> this always works the first time somewhere between the second and 6th
> time called the load event fires but the on complete doesnt (so all
> the fields remain disabled). I suspect this has something to do with
> using java instead of ruby for the back end processing. I googled
> something about headers being cached and added a couple of lines for
> that but it didn''t change anything. Anyone out there alot smarter
> than me have any ideas why this is happening and how to correct it? I
> have the html, jsp and js files listed below. I left out he css and
> fluff but can add if needed.
>
> Thanks in advance,
>
> todo.html
> --------------------
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <!--
> ! Excerpted from "Prototype and script.aculo.us",
> ! published by The Pragmatic Bookshelf.
> ! Copyrights apply to this code. It may not be used to create
> training material,
> ! courses, books, articles, and the like. Contact us if you are in
> doubt.
> ! We make no guarantees that this code is fit for any purpose.
> ! Visithttp://www.pragmaticprogrammer.com/titles/cppsufor more book
> information.
> -->
> <html xmlns="http://www.w3.org/1999/xhtml"
lang="en-US" xml:lang="en-
> US">
> <head>
> <meta http-equiv="Content-Type" content="text/html;
> charset=utf-8" />
> <title>A combined example of using
Prototype…</title>
> <link rel="stylesheet" type="text/css"
href="includes/todo/
> todo.css" />
> <script type="text/javascript"
src="includes/prototype.js"></
> script>
> <script type="text/javascript"
src="includes/todo/todo.js"></
> script>
> </head>
> <body>
>
> <h1>A combined example of using Prototype</h1>
>
> <form id="addForm" method="post"
action="todo.jsp">
> <fieldset>
> <legend>Add task</legend>
> <p>
> <input type="hidden" id="index"
name="index" value="0" />
> <label for="taskText"
accesskey="T">Text:</label>
> <input type="text" id="taskText"
name="text" />
> </p>
> <p><input type="submit" value="New task!"
/></p>
> </fieldset>
> </form>
>
> <p id="progress" style="display: none;">Adding
task…</p>
>
> <h2>Task list</h2>
>
> <p id="selectors">
> <a href="#" id="selectAll">Select all</a>
·
> <a href="#" id="deselectAll">Deselect
all</a>
> </p>
>
> <ul id="tasks">
> </ul>
>
> <div id="debug"> </div>
>
> </body>
> </html>
>
> todo.jsp
> -------------------
> <%
> response.setHeader("Cache-Control","no-cache");
> response.setHeader("Pragma","no-cache");
> response.setDateHeader ("Expires", 0);
>
> String index = request.getParameter("index");
> if (index.length() == 0)
> index = "0";
> String text = request.getParameter("text");
> if (text.length() == 0)
> text = "text" + index;
> %>
> <li>
> <input type="checkbox" id="chk<%= index %>"
/>
> <label for="chk<%= index %>"><%= text
%></label>
> </li>
>
> todo.js
> ---------------------
> /***
> * Excerpted from "Prototype and script.aculo.us",
> * published by The Pragmatic Bookshelf.
> * Copyrights apply to this code. It may not be used to create
> training material,
> * courses, books, articles, and the like. Contact us if you are in
> doubt.
> * We make no guarantees that this code is fit for any purpose.
> * Visithttp://www.pragmaticprogrammer.com/titles/cppsufor more book
> information.
> ***/
> var items = 0;
>
> function bindUI() {
> $(''addForm'').observe(''submit'',
routeToAJAX);
> $(''selectAll'').observe(''click'',
toggleAll.bindAsEventListener(this,
> true));
> $(''deselectAll'').observe(''click'',
> toggleAll.bindAsEventListener(this, false));
>
> } // bindUI
>
> function toggleAll(event, doSelect) {
> event.stop();
>
$(''tasks'').select(''input[type=checkbox]'').each(function(box)
{
> box.checked = doSelect;
> });
>
> } // toggleAll
>
> Ajax.Responders.register({
> onCreate: function() {
> $(''progress'').show();
> },
> onComplete: function() {
> if (0 == Ajax.activeRequestCount)
> $(''progress'').hide();
> }
>
> });
>
> function routeToAJAX(event) {
> event.stop();
> var form = event.element();
> $(''index'').value = ++items;
> new Ajax.Updater(''tasks'', form.action, {
> parameters: Form.serialize(form),
> insertion: Insertion.Bottom,
> onLoading: function() { $(''addForm'').disable(); $
> (''debug'').update("loading" + items);},
> onComplete: function() {
> $(''addForm'').enable();
> $(''taskText'').clear().focus();
> $(''debug'').update("completed" +
items);
> },
> onException: function() {
> $(''debug'').update("exception"
+ items);
> },
> onSuccess: function() {
>
$(''debug'').update("success" + items);
> },
> method: ''post''
> });
>
> } // routeToAJAX
>
> document.observe(''dom:loaded'', bindUI);
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---