Igor, thanks a lot for this hint! With it, I found a solution.

For others with similar problems: I create the following resource in onBeginRender():

    resource = new WebResource()
    {
      @Override
      public IResourceStream getResourceStream()
      {
IModel<Collection<T>> model = (IModel<Collection<T>>) getDefaultModel();
        Collection<T> collection = model.getObject();
        final String json = generateJson(collection.iterator());
        return new StringResourceStream(json, "text/x-json");
      }
    };
    resource.setCacheable(false);
urlConstructor = RequestCycle.get().urlFor(MyPanel.this, IResourceListener.INTERFACE); // (*)

(You cannot do this in the constructor, as it turns out, because urlFor() calls getPage() and this is not a good thing in the constructor -- the component does
not have a page yet at this stage.)

In addition, I made my component implement IResourceListener with

  public void onResourceRequested()
  {
    resource.onResourceRequested();
  }

In this way, a request for the URL (*) will trigger the resource's
onResourceRequested() which in turn outputs the JSON for my JavaScript
component on the browser.

On 13.08.2008, at 00:18, Igor Vaynberg wrote:

see how Link does it, but essentially you call urlfor(component,
listenerinterface)

-igor

On Tue, Aug 12, 2008 at 1:46 PM, Kaspar Fischer <[EMAIL PROTECTED]> wrote:
On 12.08.2008, at 12:42, Kaspar Fischer wrote:

How can I register a resource reference (or, what I actually want: just
the
resource) with the component AND get a URL for it?

To rephrase my question and hopefully make it clearer: How can I get a URL for my component which outputs the current value of my component's model
(in JSON, XML, or whatever)?

Any ideas?

I know this has come up before,

http://markmail.org/message/yewk64k7i452cjhd

but I could not find any answer...

Thanks,
Kaspar

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to