You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by john lee <sh...@yahoo.com> on 2013/08/06 16:31:51 UTC
sj:a json return result question
Question for Sjquery's sj:a tag as the following
<s:url id="ajax" value="ReportAction"/>
<sj:a id="ajaxlink"
href="%{ajax}"
targets="result"
> TOTAL # PARTS
</sj:a>
<div id="result"> <s:property value="sum"/></div>
public class ReportkeyAction extends extends ActionSupport {
private int sum;
public int getSum() { return sum; }
public void setSum(int sum) { this.sum = sum; }
public String execute() throws Exception { sum=310;
System.out.println("sum get fired for json, val="+sum);
return "success";
}
public String getJSON() throws Exception
{
System.out.println("json get triggered for json, val="+sum);
return execute();
}
}
the render return result/display is the following
TOTAL # PARTS
{"JSON":"success","sum":310}
I only expect result of 310 get returned, why heading info also get returned?
obvioulsy, <s:property value="sum"/> even did not working.
how can i just display 310 only?
thanks in advance
john
Re: sj:a json return result question
Posted by john lee <sh...@yahoo.com>.
Dave,
Thanks your very much, it works very well
brw, the book you wrote/published, i had it.
john
________________________________
From: Dave Newton <da...@gmail.com>
To: Struts Users Mailing List <us...@struts.apache.org>; john lee <sh...@yahoo.com>
Sent: Tuesday, August 6, 2013 11:26 AM
Subject: Re: sj:a json return result question
Configure your result's `root` to be `sum`, otherwise it will serialize the entire action.
On Tue, Aug 6, 2013 at 10:31 AM, john lee <sh...@yahoo.com> wrote:
>Question for Sjquery's sj:a tag as the following
>
><s:url id="ajax" value="ReportAction"/>
> <sj:a id="ajaxlink"
> href="%{ajax}"
> targets="result"
> > TOTAL # PARTS
> </sj:a>
><div id="result"> <s:property value="sum"/></div>
>
>public class ReportkeyAction extends extends ActionSupport {
> private int sum;
> public int getSum() { return sum; }
> public void setSum(int sum) { this.sum = sum; }
> public String execute() throws Exception { sum=310;
> System.out.println("sum get fired for json, val="+sum);
> return "success";
>}
>public String getJSON() throws Exception
> {
> System.out.println("json get triggered for json, val="+sum);
> return execute();
> }
>}
>
>the render return result/display is the following
>
> TOTAL # PARTS
>{"JSON":"success","sum":310}
>
>
>I only expect result of 310 get returned, why heading info also get returned?
>obvioulsy, <s:property value="sum"/> even did not working.
>
>how can i just display 310 only?
>
>thanks in advance
>
>john
--
e: davelnewton@gmail.com
m: 908-380-8699
s: davelnewton_skype
t: @dave_newton
b: Bucky Bits
g: davelnewton
so: Dave Newton
Re: sj:a json return result question
Posted by Dave Newton <da...@gmail.com>.
Configure your result's `root` to be `sum`, otherwise it will serialize the
entire action.
On Tue, Aug 6, 2013 at 10:31 AM, john lee <sh...@yahoo.com> wrote:
>
> Question for Sjquery's sj:a tag as the following
>
> <s:url id="ajax" value="ReportAction"/>
> <sj:a id="ajaxlink"
> href="%{ajax}"
> targets="result"
> > TOTAL # PARTS
> </sj:a>
> <div id="result"> <s:property value="sum"/></div>
>
> public class ReportkeyAction extends extends ActionSupport {
> private int sum;
> public int getSum() { return sum; }
> public void setSum(int sum) { this.sum = sum; }
> public String execute() throws Exception { sum=310;
> System.out.println("sum get fired for json, val="+sum);
> return "success";
> }
> public String getJSON() throws Exception
> {
> System.out.println("json get triggered for json, val="+sum);
> return execute();
> }
> }
>
> the render return result/display is the following
>
> TOTAL # PARTS
> {"JSON":"success","sum":310}
>
>
> I only expect result of 310 get returned, why heading info also get
> returned?
> obvioulsy, <s:property value="sum"/> even did not working.
>
> how can i just display 310 only?
>
> thanks in advance
>
> john
--
e: davelnewton@gmail.com
m: 908-380-8699
s: davelnewton_skype
t: @dave_newton <https://twitter.com/dave_newton>
b: Bucky Bits <http://buckybits.blogspot.com/>
g: davelnewton <https://github.com/davelnewton>
so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>