0

how to make grid hirarchy(detail) structure dynamically.

asked 2012-05-18 10:30:03 +0800

manishashrm gravatar image manishashrm
195

updated 2012-05-18 10:31:24 +0800

hi all,

i am succesfully executed half part of grid hirarchy dynamic code, i am facing an problm with remaining half part. plz see this link http://www.zkoss.org/zkdemo/grid/hierarchy what i amtrying to do but only difference is i am trying to make it dynamically.

Plz see the below code what i have done yet.

hirarchy.zul


<zk>
	<style src="/widgets/grid/hierarchy/Style.css" ></style>
	<grid id="hGrid11" apply="demo.grid.hierarchy.HierarchyController">
		<columns>
			<column width="40px" />
			<column label="ID" />
			<column label="Name" />
			<column label="Active Date" align="center" sort="auto" />
			<column label="Deleated?" align="center" sort="auto" />
			
		</columns>
		<template name="model" var="item">
			<row >
				<detail open="false" fulfill="onOpen=/season.zul" ></detail>
				<label value="${each.id}" ></label>
				<label value="${each.name}" ></label>
				<label value="${each.date}" ></label>
				<label style="color:red;" value="${each.deleted}" ></label>
				
			</row>
		</template>
	</grid>
</zk>






and will get the value ffrom database in above rows, for that i ahve written code.
package demo.grid.hierarchy;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.sql.*;



import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Chart;
import org.zkoss.zul.Footer;
import org.zkoss.zul.Grid;
import org.zkoss.zul.Label;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.ListModelList;
import org.zkoss.zul.Row;
import org.zkoss.zul.Rows;
import org.zkoss.zul.SimpleCategoryModel;
import org.zkoss.zul.Window;

import demo.grid.hierarchy.Customer;



public class HierarchyController extends SelectorComposer<Component> {
      /**
      * 
       */
      private static final long serialVersionUID = -3325569917490393900L;
      
      private final SimpleDateFormat monthFormat = new SimpleDateFormat("MMMM");
      private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMM-yyyy");
      private static NumberFormat nf = NumberFormat.getInstance();
      private static String[] months = new String[12];

      @Override
         public void doAfterCompose(Component comp) throws Exception {
          super.doAfterCompose(comp);
          Grid hierarchyGrid = (Grid) comp;
        
          Connection conn = null;
          String url = "jdbc:mysql://10.224.153.203:3306/student";
          String driver = "com.mysql.jdbc.Driver";
          String userName = "root"; 
          String password = "admin";


          List<Customer> stocks = new ArrayList<Customer>();
          List<Customer> stocks1 = new ArrayList<Customer>();
          try {
            Class.forName(driver).newInstance();
              conn = DriverManager.getConnection(url, userName,password);
              if (conn!=null){
              System.out.println("Connected to the database121");
              }

                Statement s = conn.createStatement();
              
                s.executeQuery("SELECT * FROM customer ;");
                ResultSet rs = s.getResultSet();
                while (rs.next()) {
                    
                      stocks.add(new Customer(rs.getInt("id"), rs.getString("name"),
                                  rs.getDate("date"), rs.getBoolean("deleted")));
                      Statement s1 = conn.createStatement();

                      
                }
                 
                ListModelList<Customer> modelStuds=new ListModelList<Customer>(stocks);
                hierarchyGrid.setModel(modelStuds);
                rs.close();
                s.close();

          } catch (Exception e) {
                System.err.println("ERROR: " + e.getMessage());
         } 
               finally {
                if (conn != null) {
                      try {
                           conn.close();
                            System.out.println("Database connection terminated123");
                      } catch (Exception e) { /* ignore close errors */
                      }
                }
          }

      }    
    }


now my problm is when i click on the plus sign of first row it should display the output of SELECT * FROM customer_complete_info where id =1;

plz help me to solve the above problm.

Thanks in advance.

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2012-05-18 10:38:30 +0800

manishashrm gravatar image manishashrm
195

updated 2012-05-18 10:39:06 +0800

currently getting the output like below-



ID Name Active Date Deleated?

1 COG13 2012-05-05 true
2 NEW1 2012-05-10 false


ID Name Active Date Deleated?

1 COG13 2012-05-05 true
2 NEW1 2012-05-10 false
3 PP 2012-05-10 false


3 PP 2012-05-10 false

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-05-18 10:30:03 +0800

Seen: 157 times

Last updated: May 18 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More