struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Griffith, Michael *" <Michael.Griff...@fda.hhs.gov>
Subject RE: AjaxTag 1.3 support?
Date Sat, 02 Feb 2008 22:52:30 GMT
Jeromy, 

Thanks for the comprehensive reply. Looking at the documentation and the
example app, I am still not sure how to configure my action/response.  I
am using tiles 2.

If I configure the autocompleter as such:

<s:label name="text" value="Search for Question Text:" />

<s:url id="search" namespace="/question"
value="/question/searchByText.action" /> 

<s:autocompleter theme="ajax" href="%{search}" name="text"
loadOnTextChange="true" loadMinimumCount="3"/>

It seems I need to return my result in JSON format correct? By returning
a JSON String from the action, how to I configure my response?

<action name="searchByText" method="searchByText"
class="gov.hhs.fda.datacall.web.struts.action.QuestionAction">
	<result name="success" type="tiles">question.panel</result>
</action>

If I use the tiles response type, I get a dojo parsing error because the
whole page is returned from the reply. 

The example in the example app isn't very clear to me, as the action
returns a .JS file with the result hard coded, and not using any
template like tiles I might add.

Also, I think I found a bug? -- the namespace attribute seems to be
ignored when I pass href=%{search} to the autocompleter. I had to put
qualify the namespace in the value to get the correct action to be
invoked.

Any further assistance you might provide would be much appreciated...
MG

-----Original Message-----
From: Jeromy Evans [mailto:jeromy.evans@blueskyminds.com.au] 
Sent: Friday, February 01, 2008 6:36 PM
To: Struts Users Mailing List
Subject: Re: AjaxTag 1.3 support?

My 2c:
I think this is a bad solution and shouldn't be encouraged.  It's 
marginally better than writing a custom servlet.

Struts2 ResultTypes [1] are designed specifically for controlling the 
type and content of results from actions to separate the view from the 
model, even if the "view" is XML data.  Accessing the response and 
writing to it directly isn't necessary except in the rarest of cases.

For Ajax/JS libraries that use JSON, the JSON Plugin (JSON ResultType) 
[2] will serialize your action into JSON automatically
The XSL ResultType will serialize your action into XML if you provide a 
stylesheet [3]
The REST plugin includes code to serialize your action into XML using 
Xstream. [4]

My point is, your action can setup a model (eg. a javabean matching the 
model expected by AjaxTag), and the ResultType can serialize it to the 
output stream.  In this case I'd create a custom result type using 
XStream, but you could also use a XML template in a Tile, or have a 
ResultType that accesses the instance created by AjaxXMLBuilder.

[1] http://struts.apache.org/2.0.11/docs/result-types.html
[2] http://cwiki.apache.org/S2PLUGINS/json-plugin.html
[3] http://struts.apache.org/2.0.11/docs/xsl-result.html
[4] http://xstream.codehaus.org/
[5] http://struts.apache.org/2.0.11/docs/result-configuration.html

regards
Jeromy Evans

Hodgins, Grant wrote:
> I was able to get the AjaxTags stuff working (with Tiles2 although I
don't think that matters at all).
>
> As Dave said, your action should return null since you want the action
to return XML in the response.
>  
> Instead, in addition to returning a null result, I simply wrote the
xml to the response:
>  
> AjaxXmlBuilder xml = new AjaxXmlBuilder();
>
> ... build your xml response ...
>
> response.setContentType("text/xml; charset=iso-8859-1");
> response.setHeader("Cache-Control", "no-store, max-age=0, no-cache,
must-revalidate");
> response.addHeader("Cache-Control", "post-check=0, pre-check=0");
> response.setHeader("Pragma", "no-cache");
>  
> PrintWriter pw = response.getWriter();
> pw.write(xml.toString());
> pw.close();
>  
> Hope this helps.
>  
> Grant
>
> ________________________________
>
> From: Griffith, Michael * [mailto:Michael.Griffith@fda.hhs.gov]
> Sent: Fri 2/1/2008 3:48 PM
> To: Struts Users Mailing List
> Subject: RE: AjaxTag 1.3 support?
>
>
>
> Dave,
>
> Thanks for the reply. I guess I should have said freemarker instead of
> sitemesh...?  At any rate, when the docs don't match the release, it's
a
> bad thing.
>
> I shouldn't need to do any of this should I? Can you point me at a
> simple, minimalist example of the <s:autocompleter> tag?
>
> mg
>
> -----Original Message-----
> From: Dave Newton [mailto:newton.dave@yahoo.com]
> Sent: Friday, February 01, 2008 5:42 PM
> To: Struts Users Mailing List
> Subject: Re: AjaxTag 1.3 support?
>
> --- "Griffith, Michael *" <Michael.Griffith@fda.hhs.gov> wrote:
>   
>> public class QuestionAction extends BaseAction implements
>> ModelDriven<Question>, Preparable, ServletRequestAware,
>> ServletResponseAware {
>>       public String getSearchTerm() throws Exception {
>>               System.out.println("**** Question Search Term:" + qt);
>>               List<Question> results=
>>     
> questionService.getQuestions(qt);
>   
>>               AjaxXmlBuilder builder= new AjaxXmlBuilder();
>>               builder.addItems(results, "questionType", "text");
>>              
>>                response.setContentType("text/xml");
>>                response.setHeader("Cache-Control", "no-cache");
>>                ServletOutputStream out = response.getOutputStream();
>>                out.print(builder.toString());
>>                out.close();
>>              
>>               return SUCCESS;
>>       }
>>
>> My struts mapping:
>>
>>       <package name="question" extends="base-pkg"
>> namespace="/question">
>>               <action name="get-term" method="getSearchTerm"
>> class="...QuestionAction">
>>                       <result name="success"
>> type="tiles">question.panel</result>
>>               </action>
>>       </package>
>>     
>
> If you're writing directly to the stream I doubt you'd even want to
> return
> anything other than a null from the action, no? What is the
> "question.panel"
> tile?
>
>   
>> The struts 2 Ajax documentation seems manic and dated. It seems the
S2
>> Ajax implementation is tied closely to sitemesh, which I am not
using.
>>     
>
> SiteMesh? The Ajax implementation isn't tied to SiteMesh at all.
>
> Dated? Much of the S2 Ajax documentation is for S2.1, which isn't even
> released yet. If anything, it's pre-dated.
>
> Dave
>
>
>
> ---------------------------------------------------------------------
> 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
>
>
>
>
>
> ----Notice Regarding Confidentiality----
> This email, including any and all attachments, (this "Email") is
intended only for the party to whom it is addressed and may contain
information that is confidential or privileged.  Sierra Systems Group
Inc. and its affiliates accept no responsibility for any loss or damage
suffered by any person resulting from any unauthorized use of or
reliance upon this Email.  If you are not the intended recipient, you
are hereby notified that any dissemination, copying or other use of this
Email is prohibited.  Please notify us of the error in communication by
return email and destroy all copies of this Email.  Thank you.
>
>   
>
------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG Free Edition. 
> Version: 7.5.516 / Virus Database: 269.19.18/1255 - Release Date:
1/02/2008 9:59 AM
>   


---------------------------------------------------------------------
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


Mime
View raw message