Generate tags with zk framework from java

0

I hope they are the best, the problem I have is that I want to generate a menu in zk framework, but I want to generate the data from java. The problem is that I do not know if what I formulate serves me. I need help, apart from that I do not know how to make java create the labels according to the data that it extracts from the database. I need help to be able to grab the data I take, and be able to generate the menu.

//// esta clase extraera y devolvera los datos que agarre de la base.
public class MenuOption {
private int id_memu;
private int id_padre;
private int id_orden;
private String nombre_menu;
private String url_img;
private String url_pag;





public MenuOption(int padre, int orden, String nombre, String img,String pag) {

    this.id_padre = padre;
    this.id_orden = orden;
    this.nombre_menu = nombre;
    this.url_img = img;
    this.url_pag = pag;

}


public int getId_memu() {
    return id_memu;
}

public void setId_memu(int id_memu) {
    this.id_memu = id_memu;
}

public int getId_padre() {
    return id_padre;
}

public void setId_padre(int id_padre) {
    this.id_padre = id_padre;
}

public int getId_orden() {
    return id_orden;
}

public void setId_orden(int id_orden) {
    this.id_orden = id_orden;
}

public String getNombre_menu() {
    return nombre_menu;
}

public void setNombre_menu(String nombre_menu) {
    this.nombre_menu = nombre_menu;
}

public String getUrl_img() {
    return url_img;
}

public void setUrl_img(String url_img) {
    this.url_img = url_img;
}

public String getUrl_pag() {
    return url_pag;
}

public void setUrl_pag(String url_pag) {
    this.url_pag = url_pag;
}



 }

/// another class

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.abraham.conexionSQL.conexion;;

public class DatosSql {

      private PreparedStatement pst;
      private ResultSet rst;
      private conexion con = new conexion();
      public ArrayList<MenuOption> GetConsultaMenu(String app) throws SQLException{
           Connection conn = con.getConexion();
           String query = "SELECT ID_OPCION_MENU,NIVEL,ORDEN,NOMBRE_MENU,URL_IMG,URL_PAG FROM MENU WHERE ID_APP ='"+app+"'";
           ArrayList<MenuOption> almacenes = new ArrayList<MenuOption>();
           pst = conn.prepareStatement(query);
           rst = pst.executeQuery();
           rst.moveToCurrentRow();
           while (!rst.isAfterLast()){
              MenuOption almacenesCon = cursorToContact(rst);
              almacenes.add(almacenesCon);
              rst.moveToCurrentRow();
           }
           rst.close();
           return almacenes;
     }

     private MenuOption cursorToContact(ResultSet cursor) throws SQLException {
    MenuOption alma1 = new MenuOption(
            cursor.getInt(1),
            cursor.getInt(2),
            cursor.getString(3),
            cursor.getString(4),
            cursor.getString(5));
       alma1.setId_memu(cursor.getInt(0));

       return alma1;
  }
}

//// and the class that will take the data

   import java.awt.Cursor;
   import java.sql.Connection;
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
   import java.sql.SQLException;
   import java.util.ArrayList;
   import java.util.List;
   import java.sql.SQLData;

   import com.abraham.conexionSQL.conexion;
       public class Menu {
         private ArrayList<MenuOption> opciones;
         private DatosSql datos;
         private conexion con = new conexion();
public void GenerarMenu(String app) throws SQLException{
    Connection conn = con.getConexion();
    opciones = datos.GetConsultaMenu(app);

    ArrayList<String> nombres = new ArrayList<String>();
    for (MenuOption opcionesMenu : opciones) {
        nombres.add(opcionesMenu.getNombre_menu());

      }
   }

  }
    
asked by AbrahamYeah Mares 15.03.2018 в 00:16
source

1 answer

0

I do not know if you are working with the MVC pattern, but if so, I do not see what your controller is, since generating the tags from Java code must be from your controller, which inherits everything from the GenericForwardComposer class in if you use that, if it is this way, in your html code you only have to have a container, it can be a menubar label and inside a menu, which you declare in your controller, so that this is the father of each menu item that you want to create.

In this way, inside your java code, where you have the loop that carries your dynamic menu data, you only create objects of type Menuitem, for example:

Menuitem itmenu = new Menuitem();

To which you can add the attributes you like, and you only indicate its parent label that you have declared as a Menu type, I think this is what you want to do? .

    
answered by 16.07.2018 в 18:39