here is an example:
Action:
public GetIdAction {
private int id;
public String execute() {
id = 10;
return SUCESS;
}
public int getId() {
return id;
}
}
mapping:
<action name="hello" method="hello"
class="..package.action.SectionAction">
<result type="freemarker">/view/Section/hello.ftl</result>
</action>
on the ftl file:
${id}
dojo.io.bind({
url: "/hello.action",
handler: function(type, data, e) {
var id = data;
alert(id); // is "load"
},
mimetype: "text/plain"
});
Make sure the result is not decorated.
musachy
Monttez wrote:
> Hi !
>
> Musachy ?
>
> I'm getting the renderized view-result on my "divtest".. when I expect
> to get the "hello from action!!" string...
>
> I'm not sure about my action mapping..
>
> I'm trying to follow the examples but getting no success. :S
>
>
> My action code:
>
> public String hello() {
> return "hello from action!!";
> }
> -------------------------------------------------
>
> My action map:
>
> <action name="hello" method="hello"
> class="..package.action.SectionAction">
> <result type="freemarker">/view/Section/hello.ftl</result>
> </action>
>
> -------------------------------------------------
>
> Dojo code:
>
> dojo.io.bind({
> url: "/hello.action",
> handler: function(type, data, e) {
> var id = data;
> //use your id
> alert(type); // is "load"
> document.getElementById('divtest').innerHTML = data;
> },
> mimetype: "text/plain"
> });
> }
>
>
> -----Mensagem original-----
> De: Musachy Barroso [mailto:mbarroso@(protected)]
> Enviada em: ter?a-feira, 13 de fevereiro de 2007 15:20
> Para: Struts Users Mailing List
> Assunto: Re: Ajax - obtaining a method result
>
>
> If you are making the call using the anchor or submit tag in the ajax
> theme, the returned text is available as a parameter(first parameter,
> when "type" is load) to the "notifyTopics", see:
>
> http://cwiki.apache.org/WW/ajax-tags.html
>
> If you are going to use Dojo directly,:
>
> dojo.io.bind({
> url: "/youraction",
> handler: function(type, data, e) {
> var id = data;
> //use your id
> },
> mimetype: "text/html"
> });
>
> That's assuming you are going to return just the id in the response. You
>
> can also returned a JSON string if you need to return more data. Or you
> can (but it will hurt :) ) return xml, which I wouldn't recommend unless
>
> you have to. If you happen to be using GWT, you can just return the int
> from your method, and you will just get it back on your GWT(javascript)
> code. These are just a few ideas, there's got to be zillion ways of
> doing it these days.
>
> musachy
>
> Monttez wrote:
>
>> Hi all
>>
>> I want to make an ajax call to a method and get its returning.. (for
>> use in a javascript fragment)
>>
>>
>> For example: I want to get the Id for the inserted person (in an ajax
>> insert..)..
>>
>>
>> How it is possible?
>>
>>
>> This method could be in an action or directly in my Service class..
>>
>>
>>
>> Thanks in advance
>>
>> Luciano
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>> For additional commands, e-mail: user-help@(protected)
>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)