click-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bob Schellink <sab...@gmail.com>
Subject Re: I need some help here
Date Sun, 18 Jan 2009 13:52:13 GMT
Hi,

Seems you posted to the wrong list. This list is for the Click Web 
Framework, while you're looking for Wicket. I think the right address 
would be: users@wicket.apache.org.

kind regards

bob



Blackman wrote:
> Im trying to work excel in wicket and im using wicket 1.4
> 
> I have a problem in overriding a function
> 
> package com.myapp.wicket;
> 
> import java.io.Serializable;
> import jxl.Cell;
> import jxl.Sheet;
> import jxl.Workbook;
> import org.apache.wicket.AttributeModifier;
> import org.apache.wicket.Component;
> import org.apache.wicket.markup.html.WebPage;
> import org.apache.wicket.markup.html.basic.Label;
> import org.apache.wicket.markup.html.form.Button;
> import org.apache.wicket.markup.html.form.CheckBox;
> import org.apache.wicket.markup.html.form.Form;
> import org.apache.wicket.markup.html.form.TextField;
> import org.apache.wicket.markup.html.form.upload.FileUpload;
> import org.apache.wicket.markup.html.form.upload.FileUploadField;
> import org.apache.wicket.markup.html.list.Loop;
> import org.apache.wicket.model.IModel;
> import org.apache.wicket.model.Model;
> import org.apache.wicket.model.PropertyModel;
> import org.apache.wicket.util.lang.Bytes;
> 
> /**
>  *
>  * @author
>  */
> public class UpLoadExcel extends WebPage {
> 
>     transient Sheet sheet;
>     private CellMetaData meta;
>     private XCell[][] values;
>     private RowHead[] rowHeads;
>     private ColHead[] colHeads;
>     final transient Button submitGrid;
>     final transient Label noLabel;
> 
>     /** Creates a new instance of UploadExcel */
>     public UpLoadExcel() {
>         values = new XCell[0][0];
>         rowHeads = new RowHead[0];
>         colHeads = new ColHead[0];
>         meta = new CellMetaData();
>         final FileUploadField fup = new FileUploadField("fileUp");
> 
>         Form f = new Form("uploadform") {
> 
>             @Override
>             public void onSubmit() {
>                 Workbook wkb;
>                 FileUpload fupload = fup.getFileUpload();
>                 if (fupload != null) {
>                     if
> (fupload.getContentType().equalsIgnoreCase("application/vnd.ms-excel")) {
>                         try {
>                             wkb =
> Workbook.getWorkbook(fupload.getInputStream());
>                             sheet = wkb.getSheet(0);
>                             meta.setRows(sheet.getRows());
>                             meta.setCols(sheet.getColumns());
>                             values = new
> XCell[sheet.getRows()][sheet.getColumns()];
>                             rowHeads = new RowHead[sheet.getRows()];
>                             colHeads = new ColHead[sheet.getColumns()];
> 
>                             submitGrid.setVisible(true);
>                             noLabel.setVisible(true);
>                         } catch (Exception ex) {
>                         }
>                     }
>                 }
>             }
>         };
>         f.setMultiPart(true);
> 
>         f.add(fup);
>         f.setMaxSize(Bytes.megabytes(5));
>         add(f);
>         Form grid = new Form("gridform") {
> 
>             @Override
>             public void onSubmit() {
>                 for (int i = 0; i < meta.getRows(); i++) {
>                     for (int j = 0; j < meta.getCols(); j++) //delegate each
> cell processing class here
>                     {
>                         System.out.println(values[i][j]);
>                     }
>                 }
>             }
>         };
>         grid.add(createHeadings());
>         grid.add(createLoop());
>         submitGrid = new Button("submit");
>         noLabel = new Label("noLabel", "No.");
>         if (meta.getCols() == 0) {
>             submitGrid.setVisible(false);
>             noLabel.setVisible(false);
>         }
>         grid.add(submitGrid);
>         grid.add(noLabel);
>         add(grid);
>     }
> 
>     private class CellMetaData implements Serializable {
> 
>         private int cols = 0;
>         private int rows = 0;
> 
>         public int getCols() {
>             return cols;
>         }
> 
>         public void setCols(int cols) {
>             this.cols = cols;
>         }
> 
>         public int getRows() {
>             return rows;
>         }
> 
>         public void setRows(int rows) {
>             this.rows = rows;
>         }
>     }
> 
>     private class RowHead implements Serializable {
> 
>         private int row;
>         private Boolean selected;
> 
>         public int getRow() {
>             return row;
>         }
> 
>         public void setRow(int row) {
>             this.row = row;
>         }
> 
>         public Boolean getSelected() {
>             return selected;
>         }
> 
>         public void setSelected(Boolean selected) {
>             this.selected = selected;
>         }
>     }
> 
>     private class ColHead implements Serializable {
> 
>         private int col;
>         private Boolean selected;
> 
>         public int getCol() {
>             return col;
>         }
> 
>         public void setCol(int col) {
>             this.col = col;
>         }
> 
>         public Boolean getSelected() {
>             return selected;
>         }
> 
>         public void setSelected(Boolean selected) {
>             this.selected = selected;
>         }
>     }
> 
>     private Loop createLoop() {
>         return new Loop("rows", new PropertyModel(meta, "rows")) {
> 
>             public void populateItem(LoopItem item) {
> 
>                 final int row = item.getIteration();
> 
>                 //creates and models the Row Label and Checkboxes
>                 item.add(new Label("rowNo", String.valueOf(row)));
>                 IModel rowCheckModel = new Model() {
> 
> /*
> * im not being able to override this function why is that so?please help me
> im new with wickets
> */
>                     @Override
>                     public void setObject(Component c, Object o) {
> 
>                         rowHeads[row] = new RowHead();
>                         rowHeads[row].setSelected((Boolean) o);
>                         rowHeads[row].setRow(row);
>                     }
> 
>                     @Override
>                     public Object getObject(Component c) {
>                         if (rowHeads[row] != null) {
>                             return rowHeads[row].getSelected();
>                         }
>                         return Boolean.TRUE;
>                     }
>                 };
>                 item.add(new CheckBox("rowCheck", rowCheckModel));
> 
>                 //creates and models the inner cells of the Excel table
> Labels and Checkboxes
>                 item.add(new Loop("cols", new PropertyModel(meta, "cols")) {
> 
>                     public void populateItem(LoopItem item) {
> 
>                         final int col = item.getIteration();
> 
>                         IModel model = new Model() {
> 
>                             @Override
>                             public void setObject(Component c, Object o) {
>                                 values[row][col] = new XCell(row, col, o);
> 
>                             }
> 
>                             @Override
>                             public Object getObject(Component c) {
>                                 if (values[row][col] != null) {
>                                     return values[row][col].getData();
>                                 }
> 
>                                 Cell cell = sheet.getCell(col, row);
>                                 values[row][col] = new XCell(row, col,
> cell.getContents());
>                                 return values[row][col].getData();
>                             }
>                         };
> 
>                         IModel checkModel = new Model() {
> 
>                             @Override
>                             public void setObject(Component c, Object o) {
>                                 values[row][col].setPersist((Boolean) o);
> 
>                             }
> 
>                             @Override
>                             public Object getObject(Component c) {
>                                 if (values[row][col] != null) {
>                                     return values[row][col].getPersist();
>                                 }
>                                 return Boolean.TRUE;
>                             }
>                         };
> 
> 
>                         TextField tx = new TextField("cell", model);
> 
>                         tx.add(new AttributeModifier("size", true, new
> Model(String.valueOf(8))));
>                         // cell.getContents().toString().length()))));
>                         item.add(tx);
>                         item.add(new CheckBox("cellCheck", checkModel));
> 
>                     }
>                 });
>             }
>         };
> 
> 
>     }
> 
>     private Loop createHeadings() {
> 
>         return new Loop("heading", new PropertyModel(meta, "cols")) {
> 
>             public void populateItem(final LoopItem item) {
> 
>                 int column = item.getIteration();
> 
>                 String result = "";
> 
>                 for (; column >= 0; column = column / 26 - 1) {
>                     result = (char) ((char) (column % 26) + 'A') + result;
>                 }
> 
>                 item.add(new Label("cellHead", new Model(result)));
>                 IModel colCheckModel = new Model() {
> 
>                     int col = item.getIteration();
> 
>                     @Override
>                     public void setObject(Component c, Object o) {
> 
>                         colHeads[col] = new ColHead();
>                         colHeads[col].setSelected((Boolean) o);
>                         colHeads[col].setCol(col);
>                     }
> 
>                     @Override
>                     public Object getObject(Component c) {
>                         if (colHeads[col] != null) {
>                             return colHeads[col].getSelected();
>                         }
>                         return Boolean.TRUE;
>                     }
>                 };
>                 item.add(new CheckBox("colCheck", colCheckModel));
>             }
>         };
>     }
> }
> 


Mime
View raw message