You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by GF <ga...@gmail.com> on 2009/07/12 21:49:54 UTC

Struts2, JQuery and JSON result to create a dynamic ajax website

Hello all,
i wrote a simple guide that explains how to use together Struts2 and
JQuery to create dynamic content with Ajax and JSON.

http://www.zulutown.com/blog/2009/07/12/ajax-dynamic-content-with-struts2-jquery-and-json-plugin/

I hope someone can appreciate it

Thank You

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2, JQuery and JSON result to create a dynamic ajax website

Posted by GF <ga...@gmail.com>.
You're right too ;-)
I didn't want to substitute to the plugin documentation.
I'd prefer the "include properties" behaviour anyway.

I believe a good idea could be to use @JsonInclude annotation on the
entity properties to define (just ONE time on the entities) which of
their properties are "safe to return" in the json serialization

Thank You again.

On Mon, Jul 13, 2009 at 9:33 AM, Nils-Helge Garli
Hegvik<ni...@gmail.com> wrote:
> Did you look at the "Excluding properties" example in the json plugin
> documentation?
>
> Nils-H
>
> On Mon, Jul 13, 2009 at 9:15 AM, GF<ga...@gmail.com> wrote:
>> You're absolutely right,
>> but there is a "security reason", in real-world application, the
>> objects i get from business service, are usually JPA entities, and
>> putting a "full JPA entity" on the json result will lead to issues in
>> the case there are some properties of that object that have to kept
>> "hidden" to the end users.. (i.e. in the case of a "User" entity,
>> would a not good idea to return in the json result its hashed
>> password).
>>
>> Your suggestion would surely lead to a "clean code" but an
>> unexperienced programmer might show to its website user some
>> information he didn't want to...
>>
>>
>>
>>
>>> A quick look at your tutorial makes me think you are underestimating the
>>> capability of the JSON plugin. It is fully capable of serializing most java
>>> objects to JSON. Rather than explicitly creating a hashmap, why not put the
>>> 'item' on the action and then set a json result with item configured as the
>>> root object.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2, JQuery and JSON result to create a dynamic ajax website

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
Did you look at the "Excluding properties" example in the json plugin
documentation?

Nils-H

On Mon, Jul 13, 2009 at 9:15 AM, GF<ga...@gmail.com> wrote:
> You're absolutely right,
> but there is a "security reason", in real-world application, the
> objects i get from business service, are usually JPA entities, and
> putting a "full JPA entity" on the json result will lead to issues in
> the case there are some properties of that object that have to kept
> "hidden" to the end users.. (i.e. in the case of a "User" entity,
> would a not good idea to return in the json result its hashed
> password).
>
> Your suggestion would surely lead to a "clean code" but an
> unexperienced programmer might show to its website user some
> information he didn't want to...
>
>
>
>
>> A quick look at your tutorial makes me think you are underestimating the
>> capability of the JSON plugin. It is fully capable of serializing most java
>> objects to JSON. Rather than explicitly creating a hashmap, why not put the
>> 'item' on the action and then set a json result with item configured as the
>> root object.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2, JQuery and JSON result to create a dynamic ajax website

Posted by GF <ga...@gmail.com>.
You're absolutely right,
but there is a "security reason", in real-world application, the
objects i get from business service, are usually JPA entities, and
putting a "full JPA entity" on the json result will lead to issues in
the case there are some properties of that object that have to kept
"hidden" to the end users.. (i.e. in the case of a "User" entity,
would a not good idea to return in the json result its hashed
password).

Your suggestion would surely lead to a "clean code" but an
unexperienced programmer might show to its website user some
information he didn't want to...




> A quick look at your tutorial makes me think you are underestimating the
> capability of the JSON plugin. It is fully capable of serializing most java
> objects to JSON. Rather than explicitly creating a hashmap, why not put the
> 'item' on the action and then set a json result with item configured as the
> root object.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2, JQuery and JSON result to create a dynamic ajax website

Posted by Wes Wannemacher <we...@wantii.com>.
On Sunday 12 July 2009 03:49:54 pm GF wrote:
> Hello all,
> i wrote a simple guide that explains how to use together Struts2 and
> JQuery to create dynamic content with Ajax and JSON.
>
> http://www.zulutown.com/blog/2009/07/12/ajax-dynamic-content-with-struts2-j
>query-and-json-plugin/
>
> I hope someone can appreciate it
>

A quick look at your tutorial makes me think you are underestimating the 
capability of the JSON plugin. It is fully capable of serializing most java 
objects to JSON. Rather than explicitly creating a hashmap, why not put the 
'item' on the action and then set a json result with item configured as the 
root object.

-Wes

-- 
Wes Wannemacher
Author - Struts 2 In Practice 
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org