You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Angelo C." <an...@gmail.com> on 2012/07/27 02:16:54 UTC

json support in template

Hi,

you have this in the code,

public JSONObject getJS() { 
       JSONObject js = new JSONObject(); 
       js.put("name1","123"); 
       return js; 
}

then in the template:
${js.get('name1')} 

considering json objects are used often nowadays, possible to have a direct
support in template? maybe some other prefix like:
#{js.name1}

what do you think?

Angelo







--
View this message in context: http://tapestry.1045711.n5.nabble.com/json-support-in-template-tp5714820.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: json support in template

Posted by Taha Siddiqi <ta...@gmail.com>.
Nice and easy!!

Thanks Christian and thanks Tapestry :)


On Jul 27, 2012, at 6:27 PM, Christian Riedel wrote:

> This might be solved using a custom PropertyBinding and should look like ${json:property.name}…  
> Challenge accepted!
> 
> https://gist.github.com/3187796
> 
> 
> Am 27.07.2012 um 02:16 schrieb Angelo C.:
> 
>> Hi,
>> 
>> you have this in the code,
>> 
>> public JSONObject getJS() { 
>>      JSONObject js = new JSONObject(); 
>>      js.put("name1","123"); 
>>      return js; 
>> }
>> 
>> then in the template:
>> ${js.get('name1')} 
>> 
>> considering json objects are used often nowadays, possible to have a direct
>> support in template? maybe some other prefix like:
>> #{js.name1}
>> 
>> what do you think?
>> 
>> Angelo
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> --
>> View this message in context: http://tapestry.1045711.n5.nabble.com/json-support-in-template-tp5714820.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


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


Re: json support in template

Posted by Christian Riedel <cr...@googlemail.com>.
I created a github repo with a complete binding module:

https://github.com/criedel/tapestry-json-binding

I tried to get all the syntax features inside that we were talking about:

${json:json.inner.inner2}
${json:jarr[1].inner.inner2}
${json:json.inner[0].inner2}

…and also with guarding '?'
${json:json.inner?.inner2}
${json:jarr[1]?.inner.inner2}
${json:json?.inner[0].inner2}

If you think the syntax is complete with that feature set you could easily put the whole module into tapestry with the next release.
I know the implementation is not really clean and maybe not as efficient as the stuff in tapestry-core but I thought if someone wants to use it and likes some improvements it's going to be easier if there's a github repo to start with :-)



Am 28.07.2012 um 05:25 schrieb Angelo C.:

> That's a good solution, can you have a maven entry for that?
> also, does it handle nested json objects?
> 
> Thanks,
> 
> 
> Christian Riedel-4 wrote
>> 
>> This might be solved using a custom PropertyBinding and should look like
>> ${json:property.name}…  
>> Challenge accepted!
>> 
>> https://gist.github.com/3187796
>> 
>> 
>> Am 27.07.2012 um 02:16 schrieb Angelo C.:
>> 
>>> Hi,
>>> 
>>> you have this in the code,
>>> 
>>> public JSONObject getJS() { 
>>>      JSONObject js = new JSONObject(); 
>>>      js.put("name1","123"); 
>>>      return js; 
>>> }
>>> 
>>> then in the template:
>>> ${js.get('name1')} 
>>> 
>>> considering json objects are used often nowadays, possible to have a
>>> direct
>>> support in template? maybe some other prefix like:
>>> #{js.name1}
>>> 
>>> what do you think?
>>> 
>>> Angelo
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> --
>>> View this message in context:
>>> http://tapestry.1045711.n5.nabble.com/json-support-in-template-tp5714820.html
>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@.apache
>>> For additional commands, e-mail: users-help@.apache
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@.apache
>> For additional commands, e-mail: users-help@.apache
>> 
> 
> 
> 
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/json-support-in-template-tp5714820p5714846.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


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


Re: json support in template

Posted by "Angelo C." <an...@gmail.com>.
That's a good solution, can you have a maven entry for that?
also, does it handle nested json objects?

Thanks,


Christian Riedel-4 wrote
> 
> This might be solved using a custom PropertyBinding and should look like
> ${json:property.name}…  
> Challenge accepted!
> 
> https://gist.github.com/3187796
> 
> 
> Am 27.07.2012 um 02:16 schrieb Angelo C.:
> 
>> Hi,
>> 
>> you have this in the code,
>> 
>> public JSONObject getJS() { 
>>       JSONObject js = new JSONObject(); 
>>       js.put("name1","123"); 
>>       return js; 
>> }
>> 
>> then in the template:
>> ${js.get('name1')} 
>> 
>> considering json objects are used often nowadays, possible to have a
>> direct
>> support in template? maybe some other prefix like:
>> #{js.name1}
>> 
>> what do you think?
>> 
>> Angelo
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> --
>> View this message in context:
>> http://tapestry.1045711.n5.nabble.com/json-support-in-template-tp5714820.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@.apache
>> For additional commands, e-mail: users-help@.apache
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@.apache
> For additional commands, e-mail: users-help@.apache
> 




--
View this message in context: http://tapestry.1045711.n5.nabble.com/json-support-in-template-tp5714820p5714846.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: json support in template

Posted by Christian Riedel <cr...@googlemail.com>.
A basic integration could support a few basic things like:

- Getting a value at a position in an array would be the only useful thing such a syntax should support, I'd say:
author.articles[0]

- Iterating over such an array would be supported without any need for array notation, since JSONArray is already Iterable:
<t:loop t:source="json:author.articles" t:value="article">
	${json:article.title}
</t:loop>

- The guarding '?' could be useful. It could not only guard against missing members but also against missing elements in the array:
author?.articles[1]

Parsing the expression might be quite expensive if the solution is just string-manipulation-based. The way the regular properties are resolved (all this stuff around antlr) is faster than any string-tokenizing, right?


Case-insensitivity: 
I would say only the Tapestry properties. Everyone knows which case the properties should be, since in most cases that you need a JSON the function that receives it is not case-insensitive. Javascript libraries, JSON-centric databases… 


Regarding the "simple mapping from JSONObject to normal Object": 
We're using Jackson(http://jackson.codehaus.org) to map objects from MongoDB to POJOs (using a wrapping library for that https://github.com/vznet/mongo-jackson-mapper).
Now it's getting pretty complex. But in general: would you prefer such mapper over reinventing the json-mapping-wheel? It would mean another dependency but I think it would be worth it.



Am 27.07.2012 um 20:19 schrieb Howard Lewis Ship:

> Time allowing, an optional sub-project of Tapestry.
> 
> The hard part is coming up with a format that works well with Tapestry;
> 
> I suppose we could just treat the first key name in the property path
> as a JavaBean property, i.e.
> 
> user.address.line1
> 
> would expect there to be a
> 
> public JSONObject getUser() { ... }
> 
> on the class; the JSONObject would contain key "address", and sub-key "line1".
> 
> A proper syntax should give some option for supporting nested JSONArrays.
> 
> In addition, is only the Tapestry property case-insensitive, or do we
> make the keys inside the JSONObjects case insensitive as well?
> 
> I've also been thinking of a simple mapping from JSONObject to normal
> Object, with annotated fields and/or naming conventions. So you might
> pass a JSONObject to a service and get back an Object that you can
> then use with Tapestry.
> 
> 
> On Fri, Jul 27, 2012 at 11:13 AM, Christian Riedel
> <cr...@googlemail.com> wrote:
>> So what do you think? Should something like that go into tapestry-core or into some 3rd party library?
>> 
>> 
>> Am 27.07.2012 um 19:35 schrieb Howard Lewis Ship:
>> 
>>> Some form of json: binding prefix will be invaluable as we move from
>>> Java-centric ORMs such as Hibernate to JSON-centric databases such as
>>> MongoDB and CouchDB (or, perhaps, even Datomic).
>>> 
>>> On Fri, Jul 27, 2012 at 5:57 AM, Christian Riedel
>>> <cr...@googlemail.com> wrote:
>>>> This might be solved using a custom PropertyBinding and should look like ${json:property.name}…
>>>> Challenge accepted!
>>>> 
>>>> https://gist.github.com/3187796
>>>> 
>>>> 
>>>> Am 27.07.2012 um 02:16 schrieb Angelo C.:
>>>> 
>>>>> Hi,
>>>>> 
>>>>> you have this in the code,
>>>>> 
>>>>> public JSONObject getJS() {
>>>>>     JSONObject js = new JSONObject();
>>>>>     js.put("name1","123");
>>>>>     return js;
>>>>> }
>>>>> 
>>>>> then in the template:
>>>>> ${js.get('name1')}
>>>>> 
>>>>> considering json objects are used often nowadays, possible to have a direct
>>>>> support in template? maybe some other prefix like:
>>>>> #{js.name1}
>>>>> 
>>>>> what do you think?
>>>>> 
>>>>> Angelo
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> --
>>>>> View this message in context: http://tapestry.1045711.n5.nabble.com/json-support-in-template-tp5714820.html
>>>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>>>> 
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>> 
>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>> 
>>> 
>>> 
>>> 
>>> --
>>> Howard M. Lewis Ship
>>> 
>>> Creator of Apache Tapestry
>>> 
>>> The source for Tapestry training, mentoring and support. Contact me to
>>> learn how I can get you up and productive in Tapestry fast!
>>> 
>>> (971) 678-5210
>>> http://howardlewisship.com
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
> 
> 
> 
> -- 
> Howard M. Lewis Ship
> 
> Creator of Apache Tapestry
> 
> The source for Tapestry training, mentoring and support. Contact me to
> learn how I can get you up and productive in Tapestry fast!
> 
> (971) 678-5210
> http://howardlewisship.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


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


Re: json support in template

Posted by Howard Lewis Ship <hl...@gmail.com>.
Time allowing, an optional sub-project of Tapestry.

The hard part is coming up with a format that works well with Tapestry;

I suppose we could just treat the first key name in the property path
as a JavaBean property, i.e.

user.address.line1

would expect there to be a

public JSONObject getUser() { ... }

on the class; the JSONObject would contain key "address", and sub-key "line1".

A proper syntax should give some option for supporting nested JSONArrays.

In addition, is only the Tapestry property case-insensitive, or do we
make the keys inside the JSONObjects case insensitive as well?

I've also been thinking of a simple mapping from JSONObject to normal
Object, with annotated fields and/or naming conventions. So you might
pass a JSONObject to a service and get back an Object that you can
then use with Tapestry.


On Fri, Jul 27, 2012 at 11:13 AM, Christian Riedel
<cr...@googlemail.com> wrote:
> So what do you think? Should something like that go into tapestry-core or into some 3rd party library?
>
>
> Am 27.07.2012 um 19:35 schrieb Howard Lewis Ship:
>
>> Some form of json: binding prefix will be invaluable as we move from
>> Java-centric ORMs such as Hibernate to JSON-centric databases such as
>> MongoDB and CouchDB (or, perhaps, even Datomic).
>>
>> On Fri, Jul 27, 2012 at 5:57 AM, Christian Riedel
>> <cr...@googlemail.com> wrote:
>>> This might be solved using a custom PropertyBinding and should look like ${json:property.name}…
>>> Challenge accepted!
>>>
>>> https://gist.github.com/3187796
>>>
>>>
>>> Am 27.07.2012 um 02:16 schrieb Angelo C.:
>>>
>>>> Hi,
>>>>
>>>> you have this in the code,
>>>>
>>>> public JSONObject getJS() {
>>>>      JSONObject js = new JSONObject();
>>>>      js.put("name1","123");
>>>>      return js;
>>>> }
>>>>
>>>> then in the template:
>>>> ${js.get('name1')}
>>>>
>>>> considering json objects are used often nowadays, possible to have a direct
>>>> support in template? maybe some other prefix like:
>>>> #{js.name1}
>>>>
>>>> what do you think?
>>>>
>>>> Angelo
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context: http://tapestry.1045711.n5.nabble.com/json-support-in-template-tp5714820.html
>>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>
>>
>>
>> --
>> Howard M. Lewis Ship
>>
>> Creator of Apache Tapestry
>>
>> The source for Tapestry training, mentoring and support. Contact me to
>> learn how I can get you up and productive in Tapestry fast!
>>
>> (971) 678-5210
>> http://howardlewisship.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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


Re: json support in template

Posted by Christian Riedel <cr...@googlemail.com>.
So what do you think? Should something like that go into tapestry-core or into some 3rd party library?


Am 27.07.2012 um 19:35 schrieb Howard Lewis Ship:

> Some form of json: binding prefix will be invaluable as we move from
> Java-centric ORMs such as Hibernate to JSON-centric databases such as
> MongoDB and CouchDB (or, perhaps, even Datomic).
> 
> On Fri, Jul 27, 2012 at 5:57 AM, Christian Riedel
> <cr...@googlemail.com> wrote:
>> This might be solved using a custom PropertyBinding and should look like ${json:property.name}…
>> Challenge accepted!
>> 
>> https://gist.github.com/3187796
>> 
>> 
>> Am 27.07.2012 um 02:16 schrieb Angelo C.:
>> 
>>> Hi,
>>> 
>>> you have this in the code,
>>> 
>>> public JSONObject getJS() {
>>>      JSONObject js = new JSONObject();
>>>      js.put("name1","123");
>>>      return js;
>>> }
>>> 
>>> then in the template:
>>> ${js.get('name1')}
>>> 
>>> considering json objects are used often nowadays, possible to have a direct
>>> support in template? maybe some other prefix like:
>>> #{js.name1}
>>> 
>>> what do you think?
>>> 
>>> Angelo
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> --
>>> View this message in context: http://tapestry.1045711.n5.nabble.com/json-support-in-template-tp5714820.html
>>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
> 
> 
> 
> -- 
> Howard M. Lewis Ship
> 
> Creator of Apache Tapestry
> 
> The source for Tapestry training, mentoring and support. Contact me to
> learn how I can get you up and productive in Tapestry fast!
> 
> (971) 678-5210
> http://howardlewisship.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


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


Re: json support in template

Posted by Howard Lewis Ship <hl...@gmail.com>.
Some form of json: binding prefix will be invaluable as we move from
Java-centric ORMs such as Hibernate to JSON-centric databases such as
MongoDB and CouchDB (or, perhaps, even Datomic).

On Fri, Jul 27, 2012 at 5:57 AM, Christian Riedel
<cr...@googlemail.com> wrote:
> This might be solved using a custom PropertyBinding and should look like ${json:property.name}…
> Challenge accepted!
>
> https://gist.github.com/3187796
>
>
> Am 27.07.2012 um 02:16 schrieb Angelo C.:
>
>> Hi,
>>
>> you have this in the code,
>>
>> public JSONObject getJS() {
>>       JSONObject js = new JSONObject();
>>       js.put("name1","123");
>>       return js;
>> }
>>
>> then in the template:
>> ${js.get('name1')}
>>
>> considering json objects are used often nowadays, possible to have a direct
>> support in template? maybe some other prefix like:
>> #{js.name1}
>>
>> what do you think?
>>
>> Angelo
>>
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context: http://tapestry.1045711.n5.nabble.com/json-support-in-template-tp5714820.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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


Re: json support in template

Posted by Christian Riedel <cr...@googlemail.com>.
This might be solved using a custom PropertyBinding and should look like ${json:property.name}…  
Challenge accepted!

https://gist.github.com/3187796


Am 27.07.2012 um 02:16 schrieb Angelo C.:

> Hi,
> 
> you have this in the code,
> 
> public JSONObject getJS() { 
>       JSONObject js = new JSONObject(); 
>       js.put("name1","123"); 
>       return js; 
> }
> 
> then in the template:
> ${js.get('name1')} 
> 
> considering json objects are used often nowadays, possible to have a direct
> support in template? maybe some other prefix like:
> #{js.name1}
> 
> what do you think?
> 
> Angelo
> 
> 
> 
> 
> 
> 
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/json-support-in-template-tp5714820.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


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