You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jeancarlo <je...@gmail.com> on 2008/01/23 16:15:24 UTC

Dwr and combo box (select) input, please help.

Hello,

   I'm using struts 2 version 2.0.9. I have a form with a lot of input
fields, including a select, which is the 'category group'. When I select a
group (onchange), I go to the server and get all categories for that group.
The way I did so far, is by using DWR; I have a class called AjaxHelper and
a method which returns a list of String. I couldn't make it work by
returning a List of the bean 'Category'. My current javascript code is:

    function ajaxRequest(select) {
         AjaxHelper.category(document.forms[0].grupoCategoryId.value,{
               callback:function(dataFromServer) {
                      alert('callback: ' + dataFromServer);
                      showResponse(dataFromServer);
               }
           });
    }
    function showResponse(data) { // set the data to another combo }

   When that function runs, the method at the server side is executed ok
(I've verified, it really gets the categories), but in the callback
javascript function, there is only a coma ( , ) as the value for
'dataFromServer'.  It only works ok if the method from server returns a list
of String. Did I miss something? Do I need some extra config for doing so,
or is not possible? How is the code for the javascript function (or Java)?

Another question: Stead of using DWR and call a method from a helper class,
is it possible to call a struts action when I select an option from the
select / combo box? That would be of a greate value, if I could use the
values from that action.


Thank you in advance,
Jeancarlo.