You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Kaspar Fischer <fi...@inf.ethz.ch> on 2008/08/12 12:42:13 UTC
Generate URL for a Resource depending on component state
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Generate URL for a Resource depending on component state
Posted by Kaspar Fischer <fi...@inf.ethz.ch>.
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
> <fi...@inf.ethz.ch> 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: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Generate URL for a Resource depending on component state
Posted by Igor Vaynberg <ig...@gmail.com>.
see how Link does it, but essentially you call urlfor(component,
listenerinterface)
-igor
On Tue, Aug 12, 2008 at 1:46 PM, Kaspar Fischer <fi...@inf.ethz.ch> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Generate URL for a Resource depending on component state
Posted by Kaspar Fischer <fi...@inf.ethz.ch>.
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org