/*
 * CustomTagAction.java
 *
 * Created on 2006/12/14, 14:07
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package weber_4_0_sample.org.itscool.customtag;

import java.util.Calendar;
import org.itscool.commons.util.MonthTable;
import org.itscool.weber.action.Action;
import org.itscool.weber.action.ActionBucket;

/**
 *
 * @author ios
 */
public class CustomtagSampleAction extends Action{
    
    public String doExecute(ActionBucket bucket)throws Exception{
        MonthTable month;
        Calendar cal = Calendar.getInstance();
        try{
            String yearStr = (String)getParameter("year");
            String monthStr = (String)getParameter("month");
            if(yearStr!=null && monthStr != null){
                int yearVal = Integer.parseInt(yearStr);
                int monthVal = Integer.parseInt(monthStr);
                cal.set(Calendar.YEAR, yearVal);
                cal.set(Calendar.MONTH, monthVal-1);
            }
        }catch(Exception e){
            
        }
        if(getParameter("next") != null ){
            cal.add(Calendar.MONTH, 1);
        }else if(getParameter("before") != null){
            cal.add(Calendar.MONTH, -1);
        }
        month = new MonthTable(cal);
        bucket.setAttribute("calendar", month);
        bucket.setAttribute("year", Integer.toString(month.getYear()));
        bucket.setAttribute("month",Integer.toString(month.getMonth()));
        
        return "sample";
    }
    
}
