Re: JSONStreamResponse. How to return an array?

2008-12-23 Thread Howard Lewis Ship
Francois is right, the client side can not directly invoke methods of
Tapestry pages or components; this is by design. The component side
can send events to specific components, and then what happens is
totally defined by the server (and therefore, more predictable and
less hackable).

Component event URLs encapsulate the following information:
- Name of containing page
- Id of component
- Name of event
- Event context

By injecting the ComponentResources object into your page, you can
invoke the method createEventLink().  This Link object can be
converted to a string via it's method toAbsoluteURI().  That's the
string your client-side JavaScript needs.

Example:

@Inject
private ComponentResources resources;

@Envrionmental
private RenderSupport renderSupport;

void afterRender()
{
  Link link = resources.createEventLink("getnodes");

  renderSupport.addScript("new MyClientSideObject('%s');",
link.toAbsoluteURI());
}

JSONArray onGetNodes()
{
  return . . . ;
}


The event handler method does not have to be public.  The Link in this
case identifies the page and event name, indicates a null component
(meaning, the page's root component), and has no context.  The URL
will looking something like  /mypage:getnodes  (mypage is the page
name, getnodes is the event name).

On Thu, Dec 18, 2008 at 4:42 AM, Francois Armand  wrote:
> superoverdr...@gmx.de wrote:
>>
>> Where is this "autocomple mixin" example? I have looked everywhere, but
>> can't find it.
>> Also read about this on the Tapestry website...
>>
>> So you mean something like:
>>
>>
>> @OnEvent(component = "getnodes")
>>
>
> Would be value in place of component, or name your method "onGetnodes()
> {...}
>
> The autocomplete mixin is in the core lib, so you can get the source with T5
> core lib, for example:
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/Autocomplete.java?view=markup
>
> --
> Francois Armand
> Etudes & Développements J2EE
> Groupe Linagora - http://www.linagora.com
> Tél.: +33 (0)1 58 18 68 28
> ---
> http://fanf42.blogspot.com
> InterLDAP - http://interldap.org FederID - http://www.federid.org/
> Open Source identities management and federation
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: JSONStreamResponse. How to return an array?

2008-12-18 Thread Francois Armand

superoverdr...@gmx.de wrote:

Where is this "autocomple mixin" example? I have looked everywhere, but can't 
find it.
Also read about this on the Tapestry website...

So you mean something like:


@OnEvent(component = "getnodes")
  
Would be value in place of component, or name your method "onGetnodes() 
{...}


The autocomplete mixin is in the core lib, so you can get the source 
with T5 core lib, for example: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/Autocomplete.java?view=markup


--
Francois Armand
Etudes & Développements J2EE
Groupe Linagora - http://www.linagora.com
Tél.: +33 (0)1 58 18 68 28
---
http://fanf42.blogspot.com
InterLDAP - http://interldap.org 
FederID - http://www.federid.org/

Open Source identities management and federation


-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: JSONStreamResponse. How to return an array?

2008-12-18 Thread superoverdrive
Where is this "autocomple mixin" example? I have looked everywhere, but can't 
find it.
Also read about this on the Tapestry website...

So you mean something like:


@OnEvent(component = "getnodes")
public JSONArray getNodes() {

Request request = requestGlobals.getRequest();


JSONArray record = new JSONArray();

JSONObject jsObject = new JSONObject();

jsObject.put("text", "adapter");
jsObject.put("id", "/adapter");
jsObject.put("cls", "folder");

record.put(jsObject);


return record;
}

?

http://localhost:8080/reorder:getnodes

says:

"Request event 'getnodes' (on component Reorder) was not handled; you must 
provide a matching event handler method in the component or in one of its 
containers."

Thanks!

 Original-Nachricht ----
> Datum: Thu, 18 Dec 2008 12:46:23 +0100
> Von: Francois Armand 
> An: Tapestry users 
> Betreff: Re: JSONStreamResponse. How to return an array?

> superoverdr...@gmx.de wrote:
> > http://localhost:8080/reorder.getnodes
> >
> > I get:
> >
> > "Component Reorder does not contain an embedded component with id
> 'getnodes'. Available components: (none)."
> >
> >   
> It's because what you actually asked here is : call the "getnodes" 
> component on page reorder. Dot in T5 url are for component navigation, 
> for instance "http://context/page.comp1.comp2 means is the component 
> with t:id "comp2" in component with t:id "comp1" in page "page". Events 
> are denoted with colons, as in "http://context/page.comp1.comp2:event";.
> 
> So, what you want is to fire a T5 events on the Java side. For that, you 
> will have to create an evenLink (the link with colon), call it with JS, 
> and handle the event in Java with "onMY_EVENT".
> There is an example in the autocomple mixin.
> 
> If you had a zone, you could return a block or a component with just:
> - on client side, call: $T('zoneId').zoneManager.updateFromURL('theUrl') 
> with theUrl somethink that looks like: "mypage:eventName"
> - on the java side, handle the event with an onEventName handler 
> returning your block or updated component.
> 
> 
> -- 
> Francois Armand
> Etudes & Développements J2EE
> Groupe Linagora - http://www.linagora.com
> Tél.: +33 (0)1 58 18 68 28
> ---
> http://fanf42.blogspot.com
> InterLDAP - http://interldap.org 
> FederID - http://www.federid.org/
> Open Source identities management and federation
> 
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: JSONStreamResponse. How to return an array?

2008-12-18 Thread Francois Armand

superoverdr...@gmx.de wrote:

http://localhost:8080/reorder.getnodes

I get:

"Component Reorder does not contain an embedded component with id 'getnodes'. 
Available components: (none)."

  
It's because what you actually asked here is : call the "getnodes" 
component on page reorder. Dot in T5 url are for component navigation, 
for instance "http://context/page.comp1.comp2 means is the component 
with t:id "comp2" in component with t:id "comp1" in page "page". Events 
are denoted with colons, as in "http://context/page.comp1.comp2:event";.


So, what you want is to fire a T5 events on the Java side. For that, you 
will have to create an evenLink (the link with colon), call it with JS, 
and handle the event in Java with "onMY_EVENT".

There is an example in the autocomple mixin.

If you had a zone, you could return a block or a component with just:
- on client side, call: $T('zoneId').zoneManager.updateFromURL('theUrl') 
with theUrl somethink that looks like: "mypage:eventName"
- on the java side, handle the event with an onEventName handler 
returning your block or updated component.



--
Francois Armand
Etudes & Développements J2EE
Groupe Linagora - http://www.linagora.com
Tél.: +33 (0)1 58 18 68 28
---
http://fanf42.blogspot.com
InterLDAP - http://interldap.org 
FederID - http://www.federid.org/

Open Source identities management and federation


-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: JSONStreamResponse. How to return an array?

2008-12-18 Thread superoverdrive
p.s.:



public JSONArray getNodes() {

Request request = requestGlobals.getRequest();


JSONArray record = new JSONArray();

JSONObject jsObject = new JSONObject();

jsObject.put("text", "adapter");
jsObject.put("id", "/adapter");
jsObject.put("cls", "folder");

record.put(jsObject);


return record;
}


When I then access: 

http://localhost:8080/reorder.getnodes

I get:

"Component Reorder does not contain an embedded component with id 'getnodes'. 
Available components: (none)."


 Original-Nachricht 
> Datum: Thu, 18 Dec 2008 10:33:12 +0100
> Von: superoverdr...@gmx.de
> An: users@tapestry.apache.org
> Betreff: JSONStreamResponse. How to return an array?

> I am trying to return a JSON Array from a Page:
> 
> Array
> (
> [0] => Array
> (
> [text] => adapter
> [id] => /adapter
> [cls] => folder
> )
> 
> [1] => Array
> (
> [text] => air
> [id] => /air
> [cls] => folder
> )
> 
> [2] => Array
> (
> [text] => build
> [id] => /build
> [cls] => folder
> )
> 
> 
> However JSONStreamResponse only returns a single JSON object and not an
> array of objects,
> 
> How is this supposed to work in Tapestry5?
> 
> Thanks!
> 
> Toby
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



JSONStreamResponse. How to return an array?

2008-12-18 Thread superoverdrive
I am trying to return a JSON Array from a Page:

Array
(
[0] => Array
(
[text] => adapter
[id] => /adapter
[cls] => folder
)

[1] => Array
(
[text] => air
[id] => /air
[cls] => folder
)

[2] => Array
(
[text] => build
[id] => /build
[cls] => folder
)


However JSONStreamResponse only returns a single JSON object and not an array 
of objects,

How is this supposed to work in Tapestry5?

Thanks!

Toby

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org