How to load the form

Unlike most JSF components which only deal with presentation layer, web sheet also need inlcude business logic layer. We use a special way to deal with it: extend the base backed bean which include the logical controls and data for the compoent.

Create the bean by extend the TieWebSheetBean

...
import org.tiefaces.components.websheet.TieWebSheetBean;
@Named
@ViewScoped
public class WebSheetDataAnnotation extends TieWebSheetBean {
...

Override initialLoad method.

InitialLoad is executed after bean constructed. This give us the opportunity to prepare the form.

...
    @Override
    public void initialLoad()  {
    ...
    }
...

Prepare data (if no data needed, then skip this step).

Context is a hash map which contain data or business objects. Just put the object paired name into the map. See Apache JEXL for detail.

...
        Map<String, Object> context = new HashMap<String, Object>();
        List<Department> departments = WebSheetDataDemo.createDepartments();
        context.put("departments", departments);
...

Special treatments (if no needed, then skip this step).

We can set some special attributes here before load the form:

1.Skip configuration: default is false. If set to true, then skip the data loading. This used for show up the original template without data loading.

...
 this.setSkipConfiguration(true);
...

Load the web sheet

First we need load the template from repository (files or database). Then load it with context or without.

...
        InputStream stream = this.getClass().getClassLoader().getResourceAsStream("websheet/datacommentdemo.xlsx");
        loadWebSheet(stream, context);
        // or use loadWebSheet(stream) if no context needed.        
...

Whole example with data loading process.

package org.tiefaces.showcase.websheet;

import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.tiefaces.components.websheet.TieWebSheetBean;
import org.tiefaces.showcase.websheet.datademo.Department;
import org.tiefaces.showcase.websheet.datademo.WebSheetDataDemo;

import javax.faces.view.ViewScoped;
import javax.inject.Named;

@Named
@ViewScoped
public class WebSheetDataAnnotation extends TieWebSheetBean {
    private static final long serialVersionUID = 1L;
    @Override
    public void initialLoad()  {
        Map<String, Object> context = new HashMap<String, Object>();
        List<Department> departments = WebSheetDataDemo.createDepartments();
        context.put("departments", departments);
        InputStream stream = this.getClass().getClassLoader().getResourceAsStream("websheet/datacommentdemo.xlsx");
        loadWebSheet(stream, context);        
    }

}

Whole example without data loading process.

package org.tiefaces.showcase.websheet;
import java.io.InputStream;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.tiefaces.components.websheet.TieWebSheetBean;

@Named
@ViewScoped
public class WebSheetDataAnnotation_Config extends TieWebSheetBean {
    private static final long serialVersionUID = 1L;
    @Override
    public void initialLoad() {
        this.setSkipConfiguration(true);
        InputStream stream = this.getClass().getClassLoader().getResourceAsStream("websheet/datacommentdemo.xlsx");
        loadWebSheet(stream);        
    }

}