Thanks for the explanation Mike.

The reason I was returning the component I want to update is that I
thought of it as the update link making a get request through an
XMLHttpRequest object, receiving a response, and injecting that
response into the html element identified by the updateContainerId.
Are these components using an Ajax library? I know that working with
Prototype, you can make an asynchronous request specifying the id of
the element to update as well as the page to request. Intuitively I
assumed I need a response to be used to inject the target element
which is why I returned the subcomponent I wanted to render.

I just tried what you suggested; instead of returning the subcomponent
I want to render, I return null. I tried it out, and the same thing
happened. The action is executed (and returns null) the first time the
updateLink is clicked, and the targeted subcomponent is re-rendered,
having one more object to iterate over. A second click won't execute
the ajax action though, just as before. Again, refreshing the page
allows it to be clicked one more time, but only once per refresh.

I assume I don't have all of the components set properly, I'm going
about this with intuition and trying to imagine what is happening on a
lower level, since there's not much documentation for the Ajax
libraries.

I've gone back and made my example as simple as possible so I can
illustrate it here.

-- The WO page MainPage with the Ajax link and update container:
<wo:AjaxUpdateLink action = "~AddElement" updateContainerID =
"ajax_container"> Add Element </wo:AjaxUpdateLink>
<wo:AjaxUpdateContainer id = "ajax_container"> <wo:PartialComponent
elements=elements/> </wo:AjaxUpdateContainer>

-- The java file for MainPage with the array being modified  (a few
things missing):
public class MainPage extends WOComponent {

    public NSMutableArray elements = new NSMutableArray();

    public WOComponent AddElement() {
        elements.add(" elem ");
        return null;
    }
}

-- The PartialComponent I am trying to update iterates over the array
<wo:loop list = "~elements" item = "~item"> I am an item<br/> </wo:loop>

-- The PartialComponent java has an NSArray elements and String item
and nothing more

If that wasn't clear: I have a page with an AjaxUpdateLink and
AjaxUpdateContainer. The AjaxUpdateLink executes an action that adds a
new string to the elements array. The elements array is bound to the
elements array of the subcomponent which iterates over the array
displaying static text on each iteration. With some printf debugging I
can see that the AddComponent() action is executed only the first time
the AjaxUpdateLink is clicked. Clicking it never executes the action
again. On IE7 nothing happens with subsequent clicks. In firefox,
clicking the link a second time loads the entire parent page into the
subcomponent.

Thanks for any additional tips. I recognise after writing this that
I'm not fully clear about everything that is happening which makes me
feel uneasy. If you can explain it to me I would really appreciate it.
If along the way you have any other general tips I'd love to hear
those too, I've only worked in webobjects for a few weeks and there's
a lot to learn.

In particular:
I could have iterated over elements in MainPage, but in the future I
will need subcomponents to rest in the update containers which is why
I created this example. Is it appropriate to expect the nested
subcomponent to read off the updated bound property when its container
is reloaded?

What should the return type of the ajax action be? I have it set as a
WOComponent, but this remains from returning the subcomponent.


Thanks!







______________________________________________________________
 >>   I have a link followed by a container.
 >>  The container contains a component which has an NSArray that it
iterates over.

Your Ajax action method should return null, not the component you're
trying to update. I don't know if this is what you're doing, but it
will definitely cause terrible problems. When you use Ajax framework,
think about how you would write your page if you weren't allowed to
ever return another page (i.e. consider all your action methods
returning null). This is how the framework works -- with every update,
you're doing state transitions on the current page, not going to
another page. This explains why you shouldn't be returning the updated
component from an action. If you did this in a non-ajax action, you
would just end up on a "page" that is the single subcomponent you
returned. Basically this same thing is happening in an Ajax update,
but with slightly weirder side-effects.

    I'm hoping there's something obvious I'm missing.

Definitely something you're doing that's a bit off ... Every
conceivable insane way of using these components is pretty much
covered :)

ms
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to