Re: Generate URL for a Resource depending on component state

2008-08-20 Thread Kaspar Fischer

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> model = (IModel>)  
getDefaultModel();

Collection 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]



Re: Generate URL for a Resource depending on component state

2008-08-12 Thread Igor Vaynberg
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]



Re: Generate URL for a Resource depending on component state

2008-08-12 Thread Kaspar Fischer

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]



Generate URL for a Resource depending on component state

2008-08-12 Thread Kaspar Fischer
I have a component that loads on the browser via JavaScript JSON-data  
from the server.
The data depends on the component's model and needs to be loaded from  
a URL. My
approach so far was to create a subclass DataSource of  
DynamicWebResource, and to do

in my component's constructor:

  MyComponent(String id, Model model)
  {
super(id, model);

final DataSource resource = new DataSource();
resourceReference = new ResourceReference(MyComponent.class,  
"something")

{
  @Override
  protected Resource newResource()
  {
return resource;
  }
};
  }

  private class DataSource extends DynamicWebResource
  // uses MyComponent.this.getDefaultModel() to obtain data
  ...

However, this registers my component class (and not the instance) with  
the resource
and all subsequently constructed components still point to the old  
resource.
How can I register a resource reference (or, what I actually want:  
just the

resource) with the component AND get a URL for it?

Thanks very much for any guidance.
Kaspar

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