0

I'm working with portlets and spring MVC. I want to get a list of items with an ajax call and use that list as the display:table attribute.

I use this ajax call:

jQuery.ajax({ url:'<portlet:resourceURL id="recuperarDatosAF">
 </portlet:resourceURL>', data: {idExpediente:expediente}, type: 'POST',
  datatype:'json', success: function(data) { 
      alert(data); 
  } 

This call is executed each time the user selects an item of a combo. the list of items that will be different each time recovered.

My question is: How could generate displaytable with that list I just get?

There a way to update a display: table defined in the jsp with that list?

The display that I have defined, retrieves the list of requestScope but I want to retrieve the list with ajax call.

My display:table:

       <display:table id="docentes" name="${requestScope.docentesList}"                       
                                           htmlId="resultadosDocentesListTable"
                                           pagesize="4"
                                           class="displayTagTable"
                                           uid="docente">
user1821460
  • 33
  • 2
  • 7

2 Answers2

0

http://jsfiddle.net/kVdZG/

Script to generate a table from json data, replace alert(data) with this code, here data.scores is my data

var data = { "scores" : [ ["3/1/2011", 610],["4/1/2011", 610],["5/1/2011", 610],["6/1/2011", 610], ["7/1/2011", 720], ["8/1/2011", 500], ["9/1/2011", 500] ] }



$(data.scores).each(function(index, element){
         $('#scores').append('<tr><td> '+element[0]+' </td> <td> '+element[1]+' </td></tr>');       
    })
chipmunk
  • 944
  • 8
  • 19
  • Thanks for answering I already knew how to build a table by injecting the html code but wanted to know if you can generate a display:table or upgrade to a list obtained from the call. I use on jsp displaytag. – user1821460 Dec 02 '12 at 21:08
0

My question is: How could generate displaytable with that list I just get?

From my experience, your list must contains Map of json data eg:

Map productMap = new HashMap();

    productMap.put("id", "1");
    productMap.put("name", "Coca Cola");                

    List<Product> productList = new ArrayList<Product>();
    productList.add(productMap);

    jsonWriter.object()
        .key("status").value(true)                   
        .key("pList").value(productList)
        .endObject();

The pList is contains Map of product.

There is a way to update a display: table defined in the jsp with that list?

Yup, after I check the display table tag part using firebug, I have found out that the display table tag will be change to normal html table. So in ajax:

success: function(data){
    if(data.status == true){
        var strHtml='';                
        for(var i=0;i<data.pList.length;i++){
        strHtml+='<tr><td>'"+data.pList[i].name+"'</td></tr>';   
        }
    jQuery("table#docentes tbody").html(strHtml);
    }                   

},

and your display tag:

<display:table id="docentes" pagesize="4" class="displayTagTable" uid="docente">
    <display:column escapeXml="true" title="Product Name" >
    </display:column>                                                                                 
</display:table>
gjman2
  • 912
  • 17
  • 28
  • This only appends to table once display tag has already been generated, pagination is removed, which defeats the purpose of the display tag – mel3kings Mar 11 '14 at 02:27