3.2.0

struts integration

it would be great if someone had an example showingf how onw could integrate ActiveWidget directly into a struts framework. eg. display info returned from an action.
joe007
May 9,
Hi

I have been using grid for two weeks and I really like it.

I'm developing a web application under Struts Framework. The following is the first code I built to get an aswer from a Struts Action in XML Format and display it on a grid.

The process is:

1. invoke the Struts Action: inicioRolesTerceros (class ControlRolesTercerosAction )

2. receive the XML and built an Array wich will feed the grid

3. write the grid to the document


CODE IN THE PAGE:

[/code]

<script type="text/javascript" src="<html:rewrite page="/scripts/grid/lib/grid.js"/>"></script>
<link href="<html:rewrite page="/scripts/grid/styles/flat/grid.css"/>" rel="stylesheet" type="text/css">

..
...
..

<style>
#grid1 {height: 250px; width: 100%; background: white; font-size: 12px;}

#grid1 .active-column-0 {text-align: left; width: 100px;}
#grid1 .active-column-1 {text-align: left; background-color: #f3f6fb; width: 180px;}
#grid1 .active-column-2 {text-align: left; width: 400px;}
#grid1 .active-column-3 {text-align: left; width: 100px;}

.active-grid-row {border-bottom: 1px solid threedlightshadow;}
.active-grid-column {border-right: 1px solid threedlightshadow;}


/* PATCH */
.active-templates-row.gecko {
display: -moz-box;
width: auto;
min-width: 100%;

}



</style>


...
...
..

<script>

var datos = new Array();
var cuantos;
var cols = ["id", "Nombre", "Descripcion", "Reservado"];
var xml;

// create grid basic attributes
var obj1 = new Active.Controls.Grid;
obj1.setId("grid1");
obj1.setProperty("selection/multiple", true);
obj1.setColumnProperty("count", 4);
obj1.setRowProperty("count", 10);
obj1.setRowHeaderWidth("28px");
obj1.setColumnHeaderHeight("20px");
obj1.setDataProperty("text", function(i, j){return datos[i][j]});
obj1.setColumnProperty("text", function(i){return cols[i]});


// Make XMLHttpRequest to get data to feed the grid
var url= "inicioRolesTercerosAction.do";
var async = false;
var obj = new Active.HTTP.Request;
obj.setURL(url);
obj.setRequestMethod("GET");
obj.response =
function(){
xml = obj.getResponseXML();
};
obj.setAsync(async);
obj.request();
var roles = xml.getElementsByTagName("rolTercero");



// Load XML Data in array
var j=0;
for(var i=0; i<roles.length; i++) {
var id = roles[i].getElementsByTagName("id")[0].childNodes[0].nodeValue;
var nombre = roles[i].getElementsByTagName("nombre")[0].childNodes[0].nodeValue;
var descripcion = roles[i].getElementsByTagName("descripcion")[0].childNodes[0].nodeValue;
var reservado = roles[i].getElementsByTagName("reservado")[0].childNodes[0].nodeValue;
var fila = new Array();
fila[0] = id;
fila[1] = nombre;
fila[2] = descripcion;
fila[3] = reservado;
datos[j] = fila;
j++;
}


// wirte grid to page
document.write(obj1);





</script>



[/code]



THE Struts Action Code:


...
...
...

public class ControlRolesTercerosAction extends MappingDispatchAction {
    
     private static final int delta = 10;   
    
     public ActionForward inicioRolesTerceros(ActionMapping mapping, ActionForm form,
                                             HttpServletRequest request,
                                             HttpServletResponse response) throws  Exception {

         /*
              Here I connect to a Data Base, get the elements  inside
               an array ob Object  an pass it to a method to construct the
               XML
  
          */
         
        Object[]  res =  giveMeElementsFromDataBase();      
          
        String xml = this.getXMLRoles(res);        


        response.setContentType("text/xml");
        response.setHeader("Cache-Control", "no-cache");
        PrintWriter out = response.getWriter();    
        out.println(xml);
        out.flush();
        return null;

        }



     private String getXMLRoles(Object[] res ) throws Exception{
         
   
         String xml += "    <registros> " + ParametrosComunes.nuevaLinea;
         
         for (Object o : res) {             
            RolForm rol = (RolForm)o;
            xml += " <rolTercero>";
            xml += " <id>" + rol.getId()+ "</id>";
            xml += " <nombre>" + rol.getNombre() + "</nombre>";
            xml += "<descripcion>" + rol.getDescripcion() + "</descripcion>";
            xml += "<reservado>" + rol.getReservado() + "</reservado>";
            xml += "<validoPersonas>" + rol.getValidoPersonas() + "</validoPersonas>";
            xml += "<validoOrganizaciones>" + rol.getValidoOrganizaciones() + "</validoOrganizaciones>";
            xml += " </rolTercero>";            
         }
         xml += "</registros>";
         
         return xml;
         
         
     }


this is so far what I'm doing. I change the original code to make it more readable, tell me I miss something but I guess with this code you can figure it out.

I built an Array with the XML I receive from the server to feed the grid because when I try to feed the grid with the XML I got some Error: something like "xml.setProperty is not a function" I still don't know what is that error about

J. Pablo M. Vidal




J. Pablo M. Vidal
May 17,
Hi

I have been using grid for two weeks and I really like it.

I'm developing a web application under Struts Framework. The following is the first code I built to get an aswer from a Struts Action in XML Format and display it on a grid.

The process is:

1. invoke the Struts Action: inicioRolesTerceros (class ControlRolesTercerosAction )

2. receive the XML and built an Array wich will feed the grid

3. write the grid to the document


CODE IN THE PAGE:

[/code]

<script type="text/javascript" src="<html:rewrite page="/scripts/grid/lib/grid.js"/>"></script>
<link href="<html:rewrite page="/scripts/grid/styles/flat/grid.css"/>" rel="stylesheet" type="text/css">

..
...
..

<style>
#grid1 {height: 250px; width: 100%; background: white; font-size: 12px;}

#grid1 .active-column-0 {text-align: left; width: 100px;}
#grid1 .active-column-1 {text-align: left; background-color: #f3f6fb; width: 180px;}
#grid1 .active-column-2 {text-align: left; width: 400px;}
#grid1 .active-column-3 {text-align: left; width: 100px;}

.active-grid-row {border-bottom: 1px solid threedlightshadow;}
.active-grid-column {border-right: 1px solid threedlightshadow;}


/* PATCH */
.active-templates-row.gecko {
display: -moz-box;
width: auto;
min-width: 100%;

}



</style>


...
...
..

<script>

var datos = new Array();
var cuantos;
var cols = ["id", "Nombre", "Descripcion", "Reservado"];
var xml;

// create grid basic attributes
var obj1 = new Active.Controls.Grid;
obj1.setId("grid1");
obj1.setProperty("selection/multiple", true);
obj1.setColumnProperty("count", 4);
obj1.setRowProperty("count", 10);
obj1.setRowHeaderWidth("28px");
obj1.setColumnHeaderHeight("20px");
obj1.setDataProperty("text", function(i, j){return datos[i][j]});
obj1.setColumnProperty("text", function(i){return cols[i]});


// Make XMLHttpRequest to get data to feed the grid
var url= "inicioRolesTercerosAction.do";
var async = false;
var obj = new Active.HTTP.Request;
obj.setURL(url);
obj.setRequestMethod("GET");
obj.response =
function(){
xml = obj.getResponseXML();
};
obj.setAsync(async);
obj.request();
var roles = xml.getElementsByTagName("rolTercero");



// Load XML Data in array
var j=0;
for(var i=0; i<roles.length; i++) {
var id = roles[i].getElementsByTagName("id")[0].childNodes[0].nodeValue;
var nombre = roles[i].getElementsByTagName("nombre")[0].childNodes[0].nodeValue;
var descripcion = roles[i].getElementsByTagName("descripcion")[0].childNodes[0].nodeValue;
var reservado = roles[i].getElementsByTagName("reservado")[0].childNodes[0].nodeValue;
var fila = new Array();
fila[0] = id;
fila[1] = nombre;
fila[2] = descripcion;
fila[3] = reservado;
datos[j] = fila;
j++;
}


// wirte grid to page
document.write(obj1);





</script>



[/code]



THE Struts Action Code:


...
...
...

public class ControlRolesTercerosAction extends MappingDispatchAction {
    
     private static final int delta = 10;   
    
     public ActionForward inicioRolesTerceros(ActionMapping mapping, ActionForm form,
                                             HttpServletRequest request,
                                             HttpServletResponse response) throws  Exception {

         /*
              Here I connect to a Data Base, get the elements  inside
               an array ob Object  an pass it to a method to construct the
               XML
  
          */
         
        Object[]  res =  giveMeElementsFromDataBase();      
          
        String xml = this.getXMLRoles(res);        


        response.setContentType("text/xml");
        response.setHeader("Cache-Control", "no-cache");
        PrintWriter out = response.getWriter();    
        out.println(xml);
        out.flush();
        return null;

        }



     private String getXMLRoles(Object[] res ) throws Exception{
         
   
         String xml += "    <registros> " + ParametrosComunes.nuevaLinea;
         
         for (Object o : res) {             
            RolForm rol = (RolForm)o;
            xml += " <rolTercero>";
            xml += " <id>" + rol.getId()+ "</id>";
            xml += " <nombre>" + rol.getNombre() + "</nombre>";
            xml += "<descripcion>" + rol.getDescripcion() + "</descripcion>";
            xml += "<reservado>" + rol.getReservado() + "</reservado>";
            xml += "<validoPersonas>" + rol.getValidoPersonas() + "</validoPersonas>";
            xml += "<validoOrganizaciones>" + rol.getValidoOrganizaciones() + "</validoOrganizaciones>";
            xml += " </rolTercero>";            
         }
         xml += "</registros>";
         
         return xml;
         
         
     }


this is so far what I'm doing. I change the original code to make it more readable, tell me I miss something but I guess with this code you can figure it out.

I built an Array with the XML I receive from the server to feed the grid because when I try to feed the grid with the XML I got some Error: something like "xml.setProperty is not a function" I still don't know what is that error about






J. Pablo M. Vidal
May 17,
hi Pablo,

I am trying to use this Active widgets, so if something is
up and running it would be easier to work from there.

so request u to please put the entire jsp file and ControlRolesTercerosAction.java file which is running.
or mail to naren_mails@yahoo.com

And if possible please can u tell the steps what I need to do
to make your application running.



Thanks and Regards,
Narendra Prasad Y.

Narendra Prasad
December 7,

This topic is archived.

See also:


Back to support forum