struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Musachy Barroso" <musa...@gmail.com>
Subject Re: AjaxTag 1.3 support?
Date Mon, 04 Feb 2008 17:04:10 GMT
sorry to be late to this discussion. Dave and Jeromy are right on the
spot. I would advise not to use ajaxtags project and go with what
Struts 2 provides, or use YUI which will play nicely with JSON.

musachy

On Feb 4, 2008 11:57 AM, Griffith, Michael *
<Michael.Griffith@fda.hhs.gov> wrote:
> Jeromy,
>
> Again, thanks for the reply. I appreciate your help!
>
> Following your example below, I can see the JSON result in the app
> server console when the action called, but I get the following error in
> the browser:
>
> FATAL exception raised: TypeError: Value undefined (result of expression
> this.data[x][0].toLowerCase) is not object.
>
> What is this telling me?
>
> -- my Struts mapping:
>         <package name="search" extends="json-default"
> namespace="/search">
>                 <action name="searchByText"
> class="...QuestionSearchAction">
>                         <result name="success" type="json">
>                 <param name="root">list</param>
>                 </result>
>                 </action>
>         </package>
>
> -- My Form:
> <s:url id="search" namespace="/search" value="/searchByText.action" />
> <s:autocompleter theme="ajax" href="%{search}" name="text"
> loadOnTextChange="true" loadMinimumCount="3"/>
>
>
> -- My Action:
> public class QuestionSearchAction extends BaseAction {
>
>         /**
>          *
>          */
>         private static final long serialVersionUID =
> 1127012585409657094L;
>
>         Question[] list;
>         private QuestionService questionService;
>
>         public void setQuestionService(QuestionService questionService)
> {
>                 this.questionService = questionService;
>         }
>
>         public String execute() {
>                 List<Question> all= questionService.getQuestions();
>             list= all.toArray( new Question[all.size()]);
>             return SUCCESS;
>          }
>
>         public Question[] getList(){
>                 return list;
>         }
>
> }
>
>
> Cheers!
> mg
>
> -----Original Message-----
> From: Jeromy Evans [mailto:jeromy.evans@blueskyminds.com.au]
> Sent: Saturday, February 02, 2008 6:15 PM
> To: Struts Users Mailing List
> Subject: Re: AjaxTag 1.3 support?
>
>
> I completely agree with Dave so I'll take a different tact.
>
> Based on this example:
> http://struts.apache.org/2.0.11/docs/ajax-tags.html#AjaxTags-autocomplet
> erTag,
> I would also take the approach of returning a JSON Result via the JSON
> Plugin.  Only the configuration changes for an XML result.
>
> So, my form looks like this:
>
> <s:url id="json" value="/JSONList.action" />
> <s:autocompleter theme="ajax" href="%{json}" dropdownHeight="180"/>
>
> So, my struts.xml contains the corresponding action definition with a
> JSON result:
>
>     <package name="example" extends="json-default">
>        <action name="JSONList" class="package.ListAction">
>            <result name="success" type="json">
>               <param name="root">list</param>
>            </result>
>        </action>
>      </package>
>
> And my action method looks like this:
>
> private ACEntry[] list;
>
> public String execute() {
>     list = populateList()
>     return "success";
>  }
>
> public ACEntry[] getList() {
>    return list;
> }
>
> ---
> In summary, the autocompleter does a get to /JSONList.action
> Struts2 executes the execute method of ListAction
> The execute method creates a structure that will populate the
> autocompleter
> The action returns a JSON result type
> The JSON plugin converts the root object (the list property only rather
> than the whole action) to a JSON structure
> The JSON plugin returns the application/json content to the
> autocompleter
>
> I'll leave it to you to determine what the list structure should like
> like.  As it'll probably be re-use I'd create a bean for the purpose.
> Use the FireBug plugin for firefox to inspect the format of the JSON
> result to ensure it matches the format required by the javascript
> library (or even better, write a unit test).
> This will work with any javascript library that accepts JSON - you just
> have to provide an appropriate structure.  It will also work with any
> library that requires an XML response, except you'd use an XML result
> type like I previously described in this thread.
>
> I hope that helps.  Struts2 is really well suited at providing non-html
> responses if you take the time to understand the ResultType
> architecture.
>
> cheers,
>  Jeromy Evans
>
> Dave Newton wrote:
> > --- "Griffith, Michael *" <Michael.Griffith@fda.hhs.gov> wrote:
> >
> >> 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.
> >>
> >
> > As previously stated if you are writing directly to the response you
> need to
> > return null from the action. I am still not sure why you're using a
> tile
> > definition here.
> >
> >
> >
> >> 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?
> >>
> >
> > As Jeremy said this is, however, probably a bad idea, considering that
> the
> > same outcome can be achieved in several different ways.
> >
> > Using a JSON result will serialize your action to JSON automagically.
> You'd
> > use a "json" result (via the JSON plugin), not a tile. Or you could
> build the
> > JSON manually and configure a FreeMarker result.
> >
> >
> >> If I use the tiles response type, I get a dojo parsing error because
> the
> >> whole page is returned from the reply.
> >>
> >
> > Sure.
> >
> >
> >> 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.
> >>
> >
> > What example are you referring to?
> >
> >
> http://struts.apache.org/2.0.11/docs/ajax-tags.html#AjaxTags-autocomplet
> erTag?
> >
> > When making an Ajax request for a component like <s:autocompleter.../>
> it's
> > unlikely you'd want to return anything other than JSON. (Other
> components or
> > component libraries may want other formats like XML or whatever.)
> Unless your
> > tile definition is creating JSON it's not going to work, and it's
> unlikely
> > that would be the best way to generate the JSON anyway.
> >
> >
> >> 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.
> >>
> >
> > When you configure the package does your namespace have a leading "/"
> (slash)
> > character? If it doesn't this can lead to dispatching issues.
> >
> > 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
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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


Mime
View raw message