Adding Json to existing action

View: New views
9 Messages — Rating Filter:   Alert me  

Adding Json to existing action

by Michael Varlik :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I need to call an existing struts action within my application from a
JavaScript function. I thought it might be possible to create an additional entry in the struts mapping file like this:

<action name="getDataJson" class="com.mypackage.MyAction" method="getData">
<result type="json" />
</action>

and then call the action with "getDataJson.action".
Unfortunately, when I try this a NullPointerException occurs in the action code. It seems, some parameters are not properly initialized.

What I'd like to know is: what is the recommendet way of calling an existing action to get JSON results? Is it a good idea to do this at all?

Cheers,
Markus
--
Neu: GMX DSL bis 50.000 kBit/s und 200,- Euro Startguthaben!
http://portal.gmx.net/de/go/dsl02

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


Re: Adding Json to existing action

by Struts Two :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You can either use Json plugin or write your own customized result type that return JSON.

--- On Tue, 10/27/09, Michael Varlik <M.Varlik@...> wrote:

> From: Michael Varlik <M.Varlik@...>
> Subject: Adding Json to existing action
> To: user@...
> Received: Tuesday, October 27, 2009, 1:07 PM
> Hi,
>
> I need to call an existing struts action within my
> application from a
> JavaScript function. I thought it might be possible to
> create an additional entry in the struts mapping file like
> this:
>
> <action name="getDataJson"
> class="com.mypackage.MyAction" method="getData">
> <result type="json" />
> </action>
>
> and then call the action with "getDataJson.action".
> Unfortunately, when I try this a NullPointerException
> occurs in the action code. It seems, some parameters are not
> properly initialized.
>
> What I'd like to know is: what is the recommendet way of
> calling an existing action to get JSON results? Is it a good
> idea to do this at all?
>
> Cheers,
> Markus
> --
> Neu: GMX DSL bis 50.000 kBit/s und 200,- Euro
> Startguthaben!
> http://portal.gmx.net/de/go/dsl02
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>


      __________________________________________________________________
Looking for the perfect gift? Give the gift of Flickr!

http://www.flickr.com/gift/

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


RE: Adding Json to existing action

by Mike Baranski-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I do this to pass parameters, using prototype js:

<s:set name="foo" value="%{'door' + door.id}"/>
        <s:set name="form_name" value="%{'form_door' + door.id}"/>

        <s:set name="door_description" value="getText(#foo)"/>
        <s:if test="door.state == 1">
                <s:url id="door_url" action="unlock"><s:param name="door.id"
value="door.id"/></s:url>
                <s:form method="POST" action="unlock" id="%{#form_name}"
onsubmit="return false;">
                        <s:hidden name="door.id"/>
                        <s:hidden name="door.state"/>
                        <s:url var="locked_image"
value="/pages/door-control/images/locked.png" />
                        <s:submit type="image" alt="Locked"
src="%{locked_image}" onclick="%{'new Ajax.Updater(\\'' + #foo +'\\', \\'' +
#door_url + '\\', {evalScripts: true}); return false;'}"/>
                </s:form>

</s:if>

>-----Original Message-----
>From: Struts Two [mailto:strutstwo@...]
>Sent: Tuesday, October 27, 2009 9:24 AM
>To: Struts Users Mailing List
>Subject: Re: Adding Json to existing action
>
>You can either use Json plugin or write your own customized result type
>that return JSON.
>
>--- On Tue, 10/27/09, Michael Varlik <M.Varlik@...> wrote:
>
>> From: Michael Varlik <M.Varlik@...>
>> Subject: Adding Json to existing action
>> To: user@...
>> Received: Tuesday, October 27, 2009, 1:07 PM
>> Hi,
>>
>> I need to call an existing struts action within my
>> application from a
>> JavaScript function. I thought it might be possible to
>> create an additional entry in the struts mapping file like
>> this:
>>
>> <action name="getDataJson"
>> class="com.mypackage.MyAction" method="getData">
>> <result type="json" />
>> </action>
>>
>> and then call the action with "getDataJson.action".
>> Unfortunately, when I try this a NullPointerException
>> occurs in the action code. It seems, some parameters are not
>> properly initialized.
>>
>> What I'd like to know is: what is the recommendet way of
>> calling an existing action to get JSON results? Is it a good
>> idea to do this at all?
>>
>> Cheers,
>> Markus
>> --
>> Neu: GMX DSL bis 50.000 kBit/s und 200,- Euro
>> Startguthaben!
>> http://portal.gmx.net/de/go/dsl02
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@...
>> For additional commands, e-mail: user-help@...
>>
>>
>
>
>      __________________________________________________________________
>Looking for the perfect gift? Give the gift of Flickr!
>
>http://www.flickr.com/gift/
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@...
>For additional commands, e-mail: user-help@...


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


Re: RE: Adding Json to existing action

by Michael Varlik :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for that hint. I have extended my mapping by adding "<param name=root>jsonData</param>" to my action mapping's result tag. Now I don't get any Exception and the server log looks just fine. However, the value returned by the action is just "null".
Do you have any idea what could be wrong here?

Cheers,
Markus

-------- Original-Nachricht --------
> Datum: Tue, 27 Oct 2009 09:39:01 -0400
> Von: "Mike Baranski" <list-subscriptions@...>
> An: "\'Struts Users Mailing List\'" <user@...>
> Betreff: RE: Adding Json to existing action

> I do this to pass parameters, using prototype js:
>
> <s:set name="foo" value="%{'door' + door.id}"/>
> <s:set name="form_name" value="%{'form_door' + door.id}"/>
>
> <s:set name="door_description" value="getText(#foo)"/>
> <s:if test="door.state == 1">
> <s:url id="door_url" action="unlock"><s:param name="door.id"
> value="door.id"/></s:url>
> <s:form method="POST" action="unlock" id="%{#form_name}"
> onsubmit="return false;">
> <s:hidden name="door.id"/>
> <s:hidden name="door.state"/>
> <s:url var="locked_image"
> value="/pages/door-control/images/locked.png" />
> <s:submit type="image" alt="Locked"
> src="%{locked_image}" onclick="%{'new Ajax.Updater(\\'' + #foo +'\\', \\''
> +
> #door_url + '\\', {evalScripts: true}); return false;'}"/>
> </s:form>
>
> </s:if>
>
> >-----Original Message-----
> >From: Struts Two [mailto:strutstwo@...]
> >Sent: Tuesday, October 27, 2009 9:24 AM
> >To: Struts Users Mailing List
> >Subject: Re: Adding Json to existing action
> >
> >You can either use Json plugin or write your own customized result type
> >that return JSON.
> >
> >--- On Tue, 10/27/09, Michael Varlik <M.Varlik@...> wrote:
> >
> >> From: Michael Varlik <M.Varlik@...>
> >> Subject: Adding Json to existing action
> >> To: user@...
> >> Received: Tuesday, October 27, 2009, 1:07 PM
> >> Hi,
> >>
> >> I need to call an existing struts action within my
> >> application from a
> >> JavaScript function. I thought it might be possible to
> >> create an additional entry in the struts mapping file like
> >> this:
> >>
> >> <action name="getDataJson"
> >> class="com.mypackage.MyAction" method="getData">
> >> <result type="json" />
> >> </action>
> >>
> >> and then call the action with "getDataJson.action".
> >> Unfortunately, when I try this a NullPointerException
> >> occurs in the action code. It seems, some parameters are not
> >> properly initialized.
> >>
> >> What I'd like to know is: what is the recommendet way of
> >> calling an existing action to get JSON results? Is it a good
> >> idea to do this at all?
> >>
> >> Cheers,
> >> Markus
> >> --
> >> Neu: GMX DSL bis 50.000 kBit/s und 200,- Euro
> >> Startguthaben!
> >> http://portal.gmx.net/de/go/dsl02
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@...
> >> For additional commands, e-mail: user-help@...
> >>
> >>
> >
> >
> >      __________________________________________________________________
> >Looking for the perfect gift? Give the gift of Flickr!
> >
> >http://www.flickr.com/gift/
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: user-unsubscribe@...
> >For additional commands, e-mail: user-help@...
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...

--
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser

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


Re: RE: Adding Json to existing action

by Michael Varlik :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I just noticed a mistake I made. When adding the parameter to the result I also have to add a getJsonData() method to the action, right?
I have added this method which actually calls execute(). Now I don't get "null" as a result anymore but I get "success" which is also not what I expected.

I guess I have missed something. Since this is the first time I use struts, I have no idea what I did wrong. Any hints are appreciated.

Cheers,
Markus

-------- Original-Nachricht --------
> Datum: Tue, 27 Oct 2009 16:09:25 +0100
> Von: "Michael Varlik" <M.Varlik@...>
> An: "Struts Users Mailing List" <user@...>, user@...
> Betreff: Re: RE: Adding Json to existing action

> Thanks for that hint. I have extended my mapping by adding "<param
> name=root>jsonData</param>" to my action mapping's result tag. Now I don't get any
> Exception and the server log looks just fine. However, the value returned
> by the action is just "null".
> Do you have any idea what could be wrong here?
>
> Cheers,
> Markus
>
> -------- Original-Nachricht --------
> > Datum: Tue, 27 Oct 2009 09:39:01 -0400
> > Von: "Mike Baranski" <list-subscriptions@...>
> > An: "\'Struts Users Mailing List\'" <user@...>
> > Betreff: RE: Adding Json to existing action
>
> > I do this to pass parameters, using prototype js:
> >
> > <s:set name="foo" value="%{'door' + door.id}"/>
> > <s:set name="form_name" value="%{'form_door' + door.id}"/>
> >
> > <s:set name="door_description" value="getText(#foo)"/>
> > <s:if test="door.state == 1">
> > <s:url id="door_url" action="unlock"><s:param name="door.id"
> > value="door.id"/></s:url>
> > <s:form method="POST" action="unlock" id="%{#form_name}"
> > onsubmit="return false;">
> > <s:hidden name="door.id"/>
> > <s:hidden name="door.state"/>
> > <s:url var="locked_image"
> > value="/pages/door-control/images/locked.png" />
> > <s:submit type="image" alt="Locked"
> > src="%{locked_image}" onclick="%{'new Ajax.Updater(\\'' + #foo +'\\',
> \\''
> > +
> > #door_url + '\\', {evalScripts: true}); return false;'}"/>
> > </s:form>
> >
> > </s:if>
> >
> > >-----Original Message-----
> > >From: Struts Two [mailto:strutstwo@...]
> > >Sent: Tuesday, October 27, 2009 9:24 AM
> > >To: Struts Users Mailing List
> > >Subject: Re: Adding Json to existing action
> > >
> > >You can either use Json plugin or write your own customized result type
> > >that return JSON.
> > >
> > >--- On Tue, 10/27/09, Michael Varlik <M.Varlik@...> wrote:
> > >
> > >> From: Michael Varlik <M.Varlik@...>
> > >> Subject: Adding Json to existing action
> > >> To: user@...
> > >> Received: Tuesday, October 27, 2009, 1:07 PM
> > >> Hi,
> > >>
> > >> I need to call an existing struts action within my
> > >> application from a
> > >> JavaScript function. I thought it might be possible to
> > >> create an additional entry in the struts mapping file like
> > >> this:
> > >>
> > >> <action name="getDataJson"
> > >> class="com.mypackage.MyAction" method="getData">
> > >> <result type="json" />
> > >> </action>
> > >>
> > >> and then call the action with "getDataJson.action".
> > >> Unfortunately, when I try this a NullPointerException
> > >> occurs in the action code. It seems, some parameters are not
> > >> properly initialized.
> > >>
> > >> What I'd like to know is: what is the recommendet way of
> > >> calling an existing action to get JSON results? Is it a good
> > >> idea to do this at all?
> > >>
> > >> Cheers,
> > >> Markus
> > >> --
> > >> Neu: GMX DSL bis 50.000 kBit/s und 200,- Euro
> > >> Startguthaben!
> > >> http://portal.gmx.net/de/go/dsl02
> > >>
> > >> ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail: user-unsubscribe@...
> > >> For additional commands, e-mail: user-help@...
> > >>
> > >>
> > >
> > >
> > >    
> __________________________________________________________________
> > >Looking for the perfect gift? Give the gift of Flickr!
> > >
> > >http://www.flickr.com/gift/
> > >
> > >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: user-unsubscribe@...
> > >For additional commands, e-mail: user-help@...
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@...
> > For additional commands, e-mail: user-help@...
>
> --
> Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5
> -
> sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...

--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

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


Re: RE: Adding Json to existing action

by Struts Two :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

What I meant was either to use Json Plugin for struts 2. Read the following Wiki page:

http://cwiki.apache.org/WW/json-plugin.html

The JSON plugin is bundled with Struts since 2.1.7. Or you can write your customized Struts 2 Result type for JSON and register it in your struts2.xml for use [does not make sense to do that if you are using 2.1.7+].

To learn how to do that, take a look at the a sample provided in struts 2 in action. That should do it as well.

Hope this helps.




--- On Tue, 10/27/09, Michael Varlik <M.Varlik@...> wrote:

> From: Michael Varlik <M.Varlik@...>
> Subject: Re: RE: Adding Json to existing action
> To: "Struts Users Mailing List" <user@...>
> Received: Tuesday, October 27, 2009, 3:50 PM
> I just noticed a mistake I made. When
> adding the parameter to the result I also have to add a
> getJsonData() method to the action, right?
> I have added this method which actually calls execute().
> Now I don't get "null" as a result anymore but I get
> "success" which is also not what I expected.
>
> I guess I have missed something. Since this is the first
> time I use struts, I have no idea what I did wrong. Any
> hints are appreciated.
>
> Cheers,
> Markus
>
> -------- Original-Nachricht --------
> > Datum: Tue, 27 Oct 2009 16:09:25 +0100
> > Von: "Michael Varlik" <M.Varlik@...>
> > An: "Struts Users Mailing List" <user@...>,
> user@...
> > Betreff: Re: RE: Adding Json to existing action
>
> > Thanks for that hint. I have extended my mapping by
> adding "<param
> > name=root>jsonData</param>" to my action
> mapping's result tag. Now I don't get any
> > Exception and the server log looks just fine. However,
> the value returned
> > by the action is just "null".
> > Do you have any idea what could be wrong here?
> >
> > Cheers,
> > Markus
> >
> > -------- Original-Nachricht --------
> > > Datum: Tue, 27 Oct 2009 09:39:01 -0400
> > > Von: "Mike Baranski" <list-subscriptions@...>
> > > An: "\'Struts Users Mailing List\'" <user@...>
> > > Betreff: RE: Adding Json to existing action
> >
> > > I do this to pass parameters, using prototype
> js:
> > >
> > > <s:set name="foo" value="%{'door' +
> door.id}"/>
> > >     <s:set name="form_name"
> value="%{'form_door' + door.id}"/>
> > >
> > >     <s:set
> name="door_description" value="getText(#foo)"/>
> > >     <s:if test="door.state ==
> 1">
> > >         <s:url
> id="door_url" action="unlock"><s:param name="door.id"
> > > value="door.id"/></s:url>
> > >         <s:form
> method="POST" action="unlock" id="%{#form_name}"
> > > onsubmit="return false;">
> > >        
>     <s:hidden name="door.id"/>
> > >        
>     <s:hidden name="door.state"/>
> > >        
>     <s:url var="locked_image"
> > > value="/pages/door-control/images/locked.png"
> />
> > >        
>     <s:submit type="image" alt="Locked"
> > > src="%{locked_image}" onclick="%{'new
> Ajax.Updater(\\'' + #foo +'\\',
> > \\''
> > > +
> > > #door_url + '\\', {evalScripts: true}); return
> false;'}"/>
> > >        
> </s:form>
> > >
> > > </s:if>
> > >
> > > >-----Original Message-----
> > > >From: Struts Two [mailto:strutstwo@...]
> > > >Sent: Tuesday, October 27, 2009 9:24 AM
> > > >To: Struts Users Mailing List
> > > >Subject: Re: Adding Json to existing action
> > > >
> > > >You can either use Json plugin or write your
> own customized result type
> > > >that return JSON.
> > > >
> > > >--- On Tue, 10/27/09, Michael Varlik <M.Varlik@...>
> wrote:
> > > >
> > > >> From: Michael Varlik <M.Varlik@...>
> > > >> Subject: Adding Json to existing action
> > > >> To: user@...
> > > >> Received: Tuesday, October 27, 2009,
> 1:07 PM
> > > >> Hi,
> > > >>
> > > >> I need to call an existing struts action
> within my
> > > >> application from a
> > > >> JavaScript function. I thought it might
> be possible to
> > > >> create an additional entry in the struts
> mapping file like
> > > >> this:
> > > >>
> > > >> <action name="getDataJson"
> > > >> class="com.mypackage.MyAction"
> method="getData">
> > > >> <result type="json" />
> > > >> </action>
> > > >>
> > > >> and then call the action with
> "getDataJson.action".
> > > >> Unfortunately, when I try this a
> NullPointerException
> > > >> occurs in the action code. It seems,
> some parameters are not
> > > >> properly initialized.
> > > >>
> > > >> What I'd like to know is: what is the
> recommendet way of
> > > >> calling an existing action to get JSON
> results? Is it a good
> > > >> idea to do this at all?
> > > >>
> > > >> Cheers,
> > > >> Markus
> > > >> --
> > > >> Neu: GMX DSL bis 50.000 kBit/s und 200,-
> Euro
> > > >> Startguthaben!
> > > >> http://portal.gmx.net/de/go/dsl02
> > > >>
> > > >>
> ---------------------------------------------------------------------
> > > >> To unsubscribe, e-mail: user-unsubscribe@...
> > > >> For additional commands, e-mail: user-help@...
> > > >>
> > > >>
> > > >
> > > >
> > > >     
> >
> __________________________________________________________________
> > > >Looking for the perfect gift? Give the gift
> of Flickr!
> > > >
> > > >http://www.flickr.com/gift/
> > > >
> > >
> >---------------------------------------------------------------------
> > > >To unsubscribe, e-mail: user-unsubscribe@...
> > > >For additional commands, e-mail: user-help@...
> > >
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@...
> > > For additional commands, e-mail: user-help@...
> >
> > --
> > Jetzt kostenlos herunterladen: Internet Explorer 8 und
> Mozilla Firefox 3.5
> > -
> > sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@...
> > For additional commands, e-mail: user-help@...
>
> --
> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

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


Re: RE: Adding Json to existing action

by Musachy Barroso :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

can you show us your action mapping and the relevant parts of your code?

musachy

On Tue, Oct 27, 2009 at 8:50 AM, Michael Varlik <M.Varlik@...> wrote:

> I just noticed a mistake I made. When adding the parameter to the result I also have to add a getJsonData() method to the action, right?
> I have added this method which actually calls execute(). Now I don't get "null" as a result anymore but I get "success" which is also not what I expected.
>
> I guess I have missed something. Since this is the first time I use struts, I have no idea what I did wrong. Any hints are appreciated.
>
> Cheers,
> Markus
>
> -------- Original-Nachricht --------
>> Datum: Tue, 27 Oct 2009 16:09:25 +0100
>> Von: "Michael Varlik" <M.Varlik@...>
>> An: "Struts Users Mailing List" <user@...>, user@...
>> Betreff: Re: RE: Adding Json to existing action
>
>> Thanks for that hint. I have extended my mapping by adding "<param
>> name=root>jsonData</param>" to my action mapping's result tag. Now I don't get any
>> Exception and the server log looks just fine. However, the value returned
>> by the action is just "null".
>> Do you have any idea what could be wrong here?
>>
>> Cheers,
>> Markus
>>
>> -------- Original-Nachricht --------
>> > Datum: Tue, 27 Oct 2009 09:39:01 -0400
>> > Von: "Mike Baranski" <list-subscriptions@...>
>> > An: "\'Struts Users Mailing List\'" <user@...>
>> > Betreff: RE: Adding Json to existing action
>>
>> > I do this to pass parameters, using prototype js:
>> >
>> > <s:set name="foo" value="%{'door' + door.id}"/>
>> >     <s:set name="form_name" value="%{'form_door' + door.id}"/>
>> >
>> >     <s:set name="door_description" value="getText(#foo)"/>
>> >     <s:if test="door.state == 1">
>> >             <s:url id="door_url" action="unlock"><s:param name="door.id"
>> > value="door.id"/></s:url>
>> >             <s:form method="POST" action="unlock" id="%{#form_name}"
>> > onsubmit="return false;">
>> >                     <s:hidden name="door.id"/>
>> >                     <s:hidden name="door.state"/>
>> >                     <s:url var="locked_image"
>> > value="/pages/door-control/images/locked.png" />
>> >                     <s:submit type="image" alt="Locked"
>> > src="%{locked_image}" onclick="%{'new Ajax.Updater(\\'' + #foo +'\\',
>> \\''
>> > +
>> > #door_url + '\\', {evalScripts: true}); return false;'}"/>
>> >             </s:form>
>> >
>> > </s:if>
>> >
>> > >-----Original Message-----
>> > >From: Struts Two [mailto:strutstwo@...]
>> > >Sent: Tuesday, October 27, 2009 9:24 AM
>> > >To: Struts Users Mailing List
>> > >Subject: Re: Adding Json to existing action
>> > >
>> > >You can either use Json plugin or write your own customized result type
>> > >that return JSON.
>> > >
>> > >--- On Tue, 10/27/09, Michael Varlik <M.Varlik@...> wrote:
>> > >
>> > >> From: Michael Varlik <M.Varlik@...>
>> > >> Subject: Adding Json to existing action
>> > >> To: user@...
>> > >> Received: Tuesday, October 27, 2009, 1:07 PM
>> > >> Hi,
>> > >>
>> > >> I need to call an existing struts action within my
>> > >> application from a
>> > >> JavaScript function. I thought it might be possible to
>> > >> create an additional entry in the struts mapping file like
>> > >> this:
>> > >>
>> > >> <action name="getDataJson"
>> > >> class="com.mypackage.MyAction" method="getData">
>> > >> <result type="json" />
>> > >> </action>
>> > >>
>> > >> and then call the action with "getDataJson.action".
>> > >> Unfortunately, when I try this a NullPointerException
>> > >> occurs in the action code. It seems, some parameters are not
>> > >> properly initialized.
>> > >>
>> > >> What I'd like to know is: what is the recommendet way of
>> > >> calling an existing action to get JSON results? Is it a good
>> > >> idea to do this at all?
>> > >>
>> > >> Cheers,
>> > >> Markus
>> > >> --
>> > >> Neu: GMX DSL bis 50.000 kBit/s und 200,- Euro
>> > >> Startguthaben!
>> > >> http://portal.gmx.net/de/go/dsl02
>> > >>
>> > >> ---------------------------------------------------------------------
>> > >> To unsubscribe, e-mail: user-unsubscribe@...
>> > >> For additional commands, e-mail: user-help@...
>> > >>
>> > >>
>> > >
>> > >
>> > >
>> __________________________________________________________________
>> > >Looking for the perfect gift? Give the gift of Flickr!
>> > >
>> > >http://www.flickr.com/gift/
>> > >
>> > >---------------------------------------------------------------------
>> > >To unsubscribe, e-mail: user-unsubscribe@...
>> > >For additional commands, e-mail: user-help@...
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@...
>> > For additional commands, e-mail: user-help@...
>>
>> --
>> Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5
>> -
>> sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@...
>> For additional commands, e-mail: user-help@...
>
> --
> GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>



--
Screw John Galt, who is Martin Gainty?

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


Re: RE: Adding Json to existing action

by Michael Varlik :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I already use the json plugin. I have written a new action to test the plugin and it works fine - I get my json result.
But for some reason it doesn't work with the existing action (I didn't write this action).

Here's what I did:
* Installed the json plugin by copying it into WEB-INF/lib
* Added a mapping to struts.xml which refers to the existing
  action but has a json result type and a different name.
* Added the getJsonData() method to the action with "return execute();"
  in the body.

Now I can call the action by it name "myJsonData.action" but it only
returns "success".


-------- Original-Nachricht --------
> Datum: Tue, 27 Oct 2009 12:56:51 -0700 (PDT)
> Von: Struts Two <strutstwo@...>
> An: Struts Users Mailing List <user@...>
> Betreff: Re: RE: Adding Json to existing action

> What I meant was either to use Json Plugin for struts 2. Read the
> following Wiki page:
>
> http://cwiki.apache.org/WW/json-plugin.html
>
> The JSON plugin is bundled with Struts since 2.1.7. Or you can write your
> customized Struts 2 Result type for JSON and register it in your
> struts2.xml for use [does not make sense to do that if you are using 2.1.7+].
>
> To learn how to do that, take a look at the a sample provided in struts 2
> in action. That should do it as well.
>
> Hope this helps.
>
>
>
>
> --- On Tue, 10/27/09, Michael Varlik <M.Varlik@...> wrote:
>
> > From: Michael Varlik <M.Varlik@...>
> > Subject: Re: RE: Adding Json to existing action
> > To: "Struts Users Mailing List" <user@...>
> > Received: Tuesday, October 27, 2009, 3:50 PM
> > I just noticed a mistake I made. When
> > adding the parameter to the result I also have to add a
> > getJsonData() method to the action, right?
> > I have added this method which actually calls execute().
> > Now I don't get "null" as a result anymore but I get
> > "success" which is also not what I expected.
> >
> > I guess I have missed something. Since this is the first
> > time I use struts, I have no idea what I did wrong. Any
> > hints are appreciated.
> >
> > Cheers,
> > Markus
> >
> > -------- Original-Nachricht --------
> > > Datum: Tue, 27 Oct 2009 16:09:25 +0100
> > > Von: "Michael Varlik" <M.Varlik@...>
> > > An: "Struts Users Mailing List" <user@...>,
> > user@...
> > > Betreff: Re: RE: Adding Json to existing action
> >
> > > Thanks for that hint. I have extended my mapping by
> > adding "<param
> > > name=root>jsonData</param>" to my action
> > mapping's result tag. Now I don't get any
> > > Exception and the server log looks just fine. However,
> > the value returned
> > > by the action is just "null".
> > > Do you have any idea what could be wrong here?
> > >
> > > Cheers,
> > > Markus
> > >
> > > -------- Original-Nachricht --------
> > > > Datum: Tue, 27 Oct 2009 09:39:01 -0400
> > > > Von: "Mike Baranski" <list-subscriptions@...>
> > > > An: "\'Struts Users Mailing List\'" <user@...>
> > > > Betreff: RE: Adding Json to existing action
> > >
> > > > I do this to pass parameters, using prototype
> > js:
> > > >
> > > > <s:set name="foo" value="%{'door' +
> > door.id}"/>
> > > >     <s:set name="form_name"
> > value="%{'form_door' + door.id}"/>
> > > >
> > > >     <s:set
> > name="door_description" value="getText(#foo)"/>
> > > >     <s:if test="door.state ==
> > 1">
> > > >         <s:url
> > id="door_url" action="unlock"><s:param name="door.id"
> > > > value="door.id"/></s:url>
> > > >         <s:form
> > method="POST" action="unlock" id="%{#form_name}"
> > > > onsubmit="return false;">
> > > >        
> >     <s:hidden name="door.id"/>
> > > >        
> >     <s:hidden name="door.state"/>
> > > >        
> >     <s:url var="locked_image"
> > > > value="/pages/door-control/images/locked.png"
> > />
> > > >        
> >     <s:submit type="image" alt="Locked"
> > > > src="%{locked_image}" onclick="%{'new
> > Ajax.Updater(\\'' + #foo +'\\',
> > > \\''
> > > > +
> > > > #door_url + '\\', {evalScripts: true}); return
> > false;'}"/>
> > > >        
> > </s:form>
> > > >
> > > > </s:if>
> > > >
> > > > >-----Original Message-----
> > > > >From: Struts Two [mailto:strutstwo@...]
> > > > >Sent: Tuesday, October 27, 2009 9:24 AM
> > > > >To: Struts Users Mailing List
> > > > >Subject: Re: Adding Json to existing action
> > > > >
> > > > >You can either use Json plugin or write your
> > own customized result type
> > > > >that return JSON.
> > > > >
> > > > >--- On Tue, 10/27/09, Michael Varlik <M.Varlik@...>
> > wrote:
> > > > >
> > > > >> From: Michael Varlik <M.Varlik@...>
> > > > >> Subject: Adding Json to existing action
> > > > >> To: user@...
> > > > >> Received: Tuesday, October 27, 2009,
> > 1:07 PM
> > > > >> Hi,
> > > > >>
> > > > >> I need to call an existing struts action
> > within my
> > > > >> application from a
> > > > >> JavaScript function. I thought it might
> > be possible to
> > > > >> create an additional entry in the struts
> > mapping file like
> > > > >> this:
> > > > >>
> > > > >> <action name="getDataJson"
> > > > >> class="com.mypackage.MyAction"
> > method="getData">
> > > > >> <result type="json" />
> > > > >> </action>
> > > > >>
> > > > >> and then call the action with
> > "getDataJson.action".
> > > > >> Unfortunately, when I try this a
> > NullPointerException
> > > > >> occurs in the action code. It seems,
> > some parameters are not
> > > > >> properly initialized.
> > > > >>
> > > > >> What I'd like to know is: what is the
> > recommendet way of
> > > > >> calling an existing action to get JSON
> > results? Is it a good
> > > > >> idea to do this at all?
> > > > >>
> > > > >> Cheers,
> > > > >> Markus
> > > > >> --
> > > > >> Neu: GMX DSL bis 50.000 kBit/s und 200,-
> > Euro
> > > > >> Startguthaben!
> > > > >> http://portal.gmx.net/de/go/dsl02
> > > > >>
> > > > >>
> > ---------------------------------------------------------------------
> > > > >> To unsubscribe, e-mail: user-unsubscribe@...
> > > > >> For additional commands, e-mail: user-help@...
> > > > >>
> > > > >>
> > > > >
> > > > >
> > > > >     
> > >
> > __________________________________________________________________
> > > > >Looking for the perfect gift? Give the gift
> > of Flickr!
> > > > >
> > > > >http://www.flickr.com/gift/
> > > > >
> > > >
> > >---------------------------------------------------------------------
> > > > >To unsubscribe, e-mail: user-unsubscribe@...
> > > > >For additional commands, e-mail: user-help@...
> > > >
> > > >
> > > >
> > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: user-unsubscribe@...
> > > > For additional commands, e-mail: user-help@...
> > >
> > > --
> > > Jetzt kostenlos herunterladen: Internet Explorer 8 und
> > Mozilla Firefox 3.5
> > > -
> > > sicherer, schneller und einfacher!
> http://portal.gmx.net/de/go/chbrowser
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@...
> > > For additional commands, e-mail: user-help@...
> >
> > --
> > GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> > Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@...
> > For additional commands, e-mail: user-help@...
> >
> >
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com 
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...

--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

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


Re: RE: Adding Json to existing action

by Michael Varlik :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

whis is the mapping for the action as it is currently used in the application. No json here:

<action name="getDailyAssetUtilizationReport" class="com.pbvm.crr.web.assetcalendar.AssetCalendarAction" method="getDailyAssetUtilizationReport"> <result>/jsp/crr_Asset_Calendar_Daily_Report.jsp</result>
</action>

This is the mapping I have created which points to the same action but with json enabled:
<action name="getDailyAssetUtilizationReportNew" class="com.pbvm.crr.web.assetcalendar.AssetCalendarAction" method="getDailyAssetUtilizationReport">
  <result type="json">
    <param name="root">jsonData</param>
  </result>
</action>

The only method I have added to the action is this:

public String getJsonData() throws Exception {
   return getDailyAssetUtilizationReport();
}

Do you need any additional information?

-------- Original-Nachricht --------
> Datum: Tue, 27 Oct 2009 13:00:42 -0700
> Von: Musachy Barroso <musachy@...>
> An: Struts Users Mailing List <user@...>
> Betreff: Re: RE: Adding Json to existing action

> can you show us your action mapping and the relevant parts of your code?
>
> musachy
>
> On Tue, Oct 27, 2009 at 8:50 AM, Michael Varlik <M.Varlik@...> wrote:
> > I just noticed a mistake I made. When adding the parameter to the result
> I also have to add a getJsonData() method to the action, right?
> > I have added this method which actually calls execute(). Now I don't get
> "null" as a result anymore but I get "success" which is also not what I
> expected.
> >
> > I guess I have missed something. Since this is the first time I use
> struts, I have no idea what I did wrong. Any hints are appreciated.
> >
> > Cheers,
> > Markus
> >
> > -------- Original-Nachricht --------
> >> Datum: Tue, 27 Oct 2009 16:09:25 +0100
> >> Von: "Michael Varlik" <M.Varlik@...>
> >> An: "Struts Users Mailing List" <user@...>,
> user@...
> >> Betreff: Re: RE: Adding Json to existing action
> >
> >> Thanks for that hint. I have extended my mapping by adding "<param
> >> name=root>jsonData</param>" to my action mapping's result tag. Now I
> don't get any
> >> Exception and the server log looks just fine. However, the value
> returned
> >> by the action is just "null".
> >> Do you have any idea what could be wrong here?
> >>
> >> Cheers,
> >> Markus
> >>
> >> -------- Original-Nachricht --------
> >> > Datum: Tue, 27 Oct 2009 09:39:01 -0400
> >> > Von: "Mike Baranski" <list-subscriptions@...>
> >> > An: "\'Struts Users Mailing List\'" <user@...>
> >> > Betreff: RE: Adding Json to existing action
> >>
> >> > I do this to pass parameters, using prototype js:
> >> >
> >> > <s:set name="foo" value="%{'door' + door.id}"/>
> >> >     <s:set name="form_name" value="%{'form_door' + door.id}"/>
> >> >
> >> >     <s:set name="door_description" value="getText(#foo)"/>
> >> >     <s:if test="door.state == 1">
> >> >             <s:url id="door_url" action="unlock"><s:param
> name="door.id"
> >> > value="door.id"/></s:url>
> >> >             <s:form method="POST" action="unlock"
> id="%{#form_name}"
> >> > onsubmit="return false;">
> >> >                     <s:hidden name="door.id"/>
> >> >                     <s:hidden name="door.state"/>
> >> >                     <s:url var="locked_image"
> >> > value="/pages/door-control/images/locked.png" />
> >> >                     <s:submit type="image" alt="Locked"
> >> > src="%{locked_image}" onclick="%{'new Ajax.Updater(\\'' + #foo +'\\',
> >> \\''
> >> > +
> >> > #door_url + '\\', {evalScripts: true}); return false;'}"/>
> >> >             </s:form>
> >> >
> >> > </s:if>
> >> >
> >> > >-----Original Message-----
> >> > >From: Struts Two [mailto:strutstwo@...]
> >> > >Sent: Tuesday, October 27, 2009 9:24 AM
> >> > >To: Struts Users Mailing List
> >> > >Subject: Re: Adding Json to existing action
> >> > >
> >> > >You can either use Json plugin or write your own customized result
> type
> >> > >that return JSON.
> >> > >
> >> > >--- On Tue, 10/27/09, Michael Varlik <M.Varlik@...> wrote:
> >> > >
> >> > >> From: Michael Varlik <M.Varlik@...>
> >> > >> Subject: Adding Json to existing action
> >> > >> To: user@...
> >> > >> Received: Tuesday, October 27, 2009, 1:07 PM
> >> > >> Hi,
> >> > >>
> >> > >> I need to call an existing struts action within my
> >> > >> application from a
> >> > >> JavaScript function. I thought it might be possible to
> >> > >> create an additional entry in the struts mapping file like
> >> > >> this:
> >> > >>
> >> > >> <action name="getDataJson"
> >> > >> class="com.mypackage.MyAction" method="getData">
> >> > >> <result type="json" />
> >> > >> </action>
> >> > >>
> >> > >> and then call the action with "getDataJson.action".
> >> > >> Unfortunately, when I try this a NullPointerException
> >> > >> occurs in the action code. It seems, some parameters are not
> >> > >> properly initialized.
> >> > >>
> >> > >> What I'd like to know is: what is the recommendet way of
> >> > >> calling an existing action to get JSON results? Is it a good
> >> > >> idea to do this at all?
> >> > >>
> >> > >> Cheers,
> >> > >> Markus
> >> > >> --
> >> > >> Neu: GMX DSL bis 50.000 kBit/s und 200,- Euro
> >> > >> Startguthaben!
> >> > >> http://portal.gmx.net/de/go/dsl02
> >> > >>
> >> > >>
> ---------------------------------------------------------------------
> >> > >> To unsubscribe, e-mail: user-unsubscribe@...
> >> > >> For additional commands, e-mail: user-help@...
> >> > >>
> >> > >>
> >> > >
> >> > >
> >> > >
> >> __________________________________________________________________
> >> > >Looking for the perfect gift? Give the gift of Flickr!
> >> > >
> >> > >http://www.flickr.com/gift/
> >> > >
> >> >
> >---------------------------------------------------------------------
> >> > >To unsubscribe, e-mail: user-unsubscribe@...
> >> > >For additional commands, e-mail: user-help@...
> >> >
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: user-unsubscribe@...
> >> > For additional commands, e-mail: user-help@...
> >>
> >> --
> >> Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox
> 3.5
> >> -
> >> sicherer, schneller und einfacher!
> http://portal.gmx.net/de/go/chbrowser
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@...
> >> For additional commands, e-mail: user-help@...
> >
> > --
> > GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
> > Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@...
> > For additional commands, e-mail: user-help@...
> >
> >
>
>
>
> --
> Screw John Galt, who is Martin Gainty?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...

--
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

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