You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Harland <ha...@yahoo.com> on 2007/04/12 08:14:54 UTC
ajax and struts 2
I am new to ajax and have just written my first ajax function. In my function I am passing a user id into the function and are being returned a List of Contacts to populate a select. Presently I am putting the id in a hidden field in the jsp and then passing it from there. What I would prefer to do is have the javascript function call an action so that the Java code can access the user id from the session.
How do I do this please?
Don't be flakey. Get Yahoo! Mail for Mobile and always stay connected to friends. http://mobile.yahoo.com/mail
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: ajax and struts 2
Posted by Martin Gainty <mg...@hotmail.com>.
Good Morning David-
I would start with looking at the ajax examples from struts2-showcase-2.0.6
and find the example which mostly closely exemplifies your task
for example example7 illustrates population of a div tag in your form and if
you run struts from localhost on port 8080 you can view results at
http://localhost:8080/struts2-showcase-2.0.6/viewSource.action?page=/ajax/remotediv/example7.jsp
Note that In your WEB-INF/classes/struts-ajax.xml note the specification onf
testjs.jsp which will store the results /ajax/testjs.jsp
<action name="Test3">
<result>/ajax/testjs.jsp</result>
</action>
HTH
Martin
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed. If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy. Thank you.
----- Original Message -----
From: "David Harland" <ha...@yahoo.com>
To: "struts" <us...@struts.apache.org>
Sent: Thursday, April 12, 2007 2:14 AM
Subject: ajax and struts 2
>I am new to ajax and have just written my first ajax function. In my
>function I am passing a user id into the function and are being returned a
>List of Contacts to populate a select. Presently I am putting the id in a
>hidden field in the jsp and then passing it from there. What I would prefer
>to do is have the javascript function call an action so that the Java code
>can access the user id from the session.
>
> How do I do this please?
>
>
>
>
> Don't be flakey. Get Yahoo! Mail for Mobile and always stay
> connected to friends. http://mobile.yahoo.com/mail
>
> ---------------------------------------------------------------------
> 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: ajax and struts 2
Posted by Lance <la...@marketpipe.com>.
read my mail... on the serverside you can use
WebContextFactory.get().getSession()
David Harland wrote:
> Im using DWR. The problem is that the java class that the javascript
> talks to does not have access to the session. What would be better would
> be for the dwr javascript to talk to an action.
>
> -----Original Message-----
> From: Lance [mailto:lance.semmens@marketpipe.com]
> Sent: 13 April 2007 16:35
> To: Struts Users Mailing List
> Subject: Re: ajax and struts 2
>
> ew... that sounds icky!
> have you considered DWR, it marshalls calls from javascript to java then
> marshalls the result back into javascript objects for you.
>
> http://getahead.org/dwr/overview/dwr
> on the serverside you can use WebContextFactory.get().getSession()
>
> Mahesh Parab wrote:
>
>> Hi David,
>> u can able to read the session variable in javascript, e.g var intId
>> intId='<%=session.getValue("id")%>' ;
>>
>> try this ,
>>
>> Thanks,
>> mahesh.
>>
>> On 4/12/07, David Harland <ha...@yahoo.com> wrote:
>>
>>> I am new to ajax and have just written my first ajax function. In my
>>> function I am passing a user id into the function and are being
>>> returned a List of Contacts to populate a select. Presently I am
>>> putting the id in a hidden field in the jsp and then passing it from
>>> there. What I would prefer to do is have the javascript function call
>>>
>
>
>>> an action so that the Java code can access the user id from the
>>> session.
>>>
>>> How do I do this please?
>>>
>>>
>>>
>>>
>>> Don't be flakey. Get Yahoo! Mail for Mobile and always stay
>>> connected to friends. http://mobile.yahoo.com/mail
>>>
>>> ---------------------------------------------------------------------
>>> 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
>
>
> - ------
> ML {UFI}
>
> ______________________________________________________________________
> Ufi Limited
> Registered in England No. 3980770
> Registered Office: Dearing House, 1 Young Street, Sheffield, S1 4UP
>
> learndirect Solutions Ltd
> Registered in England No. 5081669
> Registered Office: Dearing House, 1 Young Street, Sheffield, S1 4UP
>
> UFI Charitable Trust
> Registered in England No. 3658378
> Registered Charity No. 1081028
> Registered Office: Dearing House, 1 Young Street, Sheffield, S1 4UP
>
> This email has been scanned by the MessageLabs Email Security System.
>
> ______________________________________________________________________
>
> ---------------------------------------------------------------------
> 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: ajax and struts 2
Posted by David Harland <dh...@ufi.com>.
Thanks Dave, I think that is exactly what I was looking for.
-----Original Message-----
From: Dave Newton [mailto:newton.dave@yahoo.com]
Sent: 13 April 2007 16:54
To: Struts Users Mailing List
Subject: RE: ajax and struts 2
--- David Harland <dh...@ufi.com> wrote:
> Im using DWR. The problem is that the java class that the javascript
> talks to does not have access to
> the session.
http://getahead.org/dwr-demo/javadoc/uk/ltd/getahead/dwr/WebContext.html
But there are better ways to handle this in S2.
d.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
- ------
ML {UFI}
______________________________________________________________________
Ufi Limited
Registered in England No. 3980770
Registered Office: Dearing House, 1 Young Street, Sheffield, S1 4UP
learndirect Solutions Ltd
Registered in England No. 5081669
Registered Office: Dearing House, 1 Young Street, Sheffield, S1 4UP
UFI Charitable Trust
Registered in England No. 3658378
Registered Charity No. 1081028
Registered Office: Dearing House, 1 Young Street, Sheffield, S1 4UP
This email has been scanned by the MessageLabs Email Security System.
______________________________________________________________________
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: ajax and struts 2
Posted by Dave Newton <ne...@yahoo.com>.
--- David Harland <dh...@ufi.com> wrote:
> Im using DWR. The problem is that the java class
> that the javascript talks to does not have access to
> the session.
http://getahead.org/dwr-demo/javadoc/uk/ltd/getahead/dwr/WebContext.html
But there are better ways to handle this in S2.
d.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: ajax and struts 2
Posted by David Harland <dh...@ufi.com>.
Im using DWR. The problem is that the java class that the javascript
talks to does not have access to the session. What would be better would
be for the dwr javascript to talk to an action.
-----Original Message-----
From: Lance [mailto:lance.semmens@marketpipe.com]
Sent: 13 April 2007 16:35
To: Struts Users Mailing List
Subject: Re: ajax and struts 2
ew... that sounds icky!
have you considered DWR, it marshalls calls from javascript to java then
marshalls the result back into javascript objects for you.
http://getahead.org/dwr/overview/dwr
on the serverside you can use WebContextFactory.get().getSession()
Mahesh Parab wrote:
> Hi David,
> u can able to read the session variable in javascript, e.g var intId
> intId='<%=session.getValue("id")%>' ;
>
> try this ,
>
> Thanks,
> mahesh.
>
> On 4/12/07, David Harland <ha...@yahoo.com> wrote:
>>
>> I am new to ajax and have just written my first ajax function. In my
>> function I am passing a user id into the function and are being
>> returned a List of Contacts to populate a select. Presently I am
>> putting the id in a hidden field in the jsp and then passing it from
>> there. What I would prefer to do is have the javascript function call
>> an action so that the Java code can access the user id from the
>> session.
>>
>> How do I do this please?
>>
>>
>>
>>
>> Don't be flakey. Get Yahoo! Mail for Mobile and always stay
>> connected to friends. http://mobile.yahoo.com/mail
>>
>> ---------------------------------------------------------------------
>> 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
- ------
ML {UFI}
______________________________________________________________________
Ufi Limited
Registered in England No. 3980770
Registered Office: Dearing House, 1 Young Street, Sheffield, S1 4UP
learndirect Solutions Ltd
Registered in England No. 5081669
Registered Office: Dearing House, 1 Young Street, Sheffield, S1 4UP
UFI Charitable Trust
Registered in England No. 3658378
Registered Charity No. 1081028
Registered Office: Dearing House, 1 Young Street, Sheffield, S1 4UP
This email has been scanned by the MessageLabs Email Security System.
______________________________________________________________________
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: ajax and struts 2
Posted by Lance <la...@marketpipe.com>.
ew... that sounds icky!
have you considered DWR, it marshalls calls from javascript to java then
marshalls the result back into javascript objects for you.
http://getahead.org/dwr/overview/dwr
on the serverside you can use WebContextFactory.get().getSession()
Mahesh Parab wrote:
> Hi David,
> u can able to read the session variable in javascript,
> e.g
> var intId
> intId='<%=session.getValue("id")%>' ;
>
> try this ,
>
> Thanks,
> mahesh.
>
> On 4/12/07, David Harland <ha...@yahoo.com> wrote:
>>
>> I am new to ajax and have just written my first ajax function. In my
>> function I am passing a user id into the function and are being
>> returned a
>> List of Contacts to populate a select. Presently I am putting the id
>> in a
>> hidden field in the jsp and then passing it from there. What I would
>> prefer
>> to do is have the javascript function call an action so that the Java
>> code
>> can access the user id from the session.
>>
>> How do I do this please?
>>
>>
>>
>>
>> Don't be flakey. Get Yahoo! Mail for Mobile and always stay
>> connected to friends. http://mobile.yahoo.com/mail
>>
>> ---------------------------------------------------------------------
>> 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: ajax and struts 2
Posted by Mahesh Parab <mu...@gmail.com>.
Hi David,
u can able to read the session variable in javascript,
e.g
var intId
intId='<%=session.getValue("id")%>' ;
try this ,
Thanks,
mahesh.
On 4/12/07, David Harland <ha...@yahoo.com> wrote:
>
> I am new to ajax and have just written my first ajax function. In my
> function I am passing a user id into the function and are being returned a
> List of Contacts to populate a select. Presently I am putting the id in a
> hidden field in the jsp and then passing it from there. What I would prefer
> to do is have the javascript function call an action so that the Java code
> can access the user id from the session.
>
> How do I do this please?
>
>
>
>
> Don't be flakey. Get Yahoo! Mail for Mobile and always stay
> connected to friends. http://mobile.yahoo.com/mail
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: ajax and struts 2
Posted by Felipe Rodrigues <fe...@yahoo.com.br>.
Did you realize about use struts tags?
Inside an Action you can use ActionContext.getContext().getSession() to get
a Map that represents the session.
If you can't use Struts tags, then you can use DWR, but I don't know how to
get session using DWR.
Good Look.
Felipe
David Harland wrote:
>
> I am new to ajax and have just written my first ajax function. In my
> function I am passing a user id into the function and are being returned a
> List of Contacts to populate a select. Presently I am putting the id in a
> hidden field in the jsp and then passing it from there. What I would
> prefer to do is have the javascript function call an action so that the
> Java code can access the user id from the session.
>
> How do I do this please?
>
>
>
>
> Don't be flakey. Get Yahoo! Mail for Mobile and always stay
> connected to friends. http://mobile.yahoo.com/mail
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/ajax-and-struts-2-tf3563636.html#a9958559
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org