0

doBeforeCompose is not running.

asked 2011-07-09 12:49:17 +0800

aitelghali gravatar image aitelghali
12

Hello,

I tried to take the example of Zk Demo Calendar, but with the jsp.
but , I do not know why the method doBeforeCompose not running.
here is the code of my files:
1. CalendarDemoComposer.java



package com.diorh.calendar;

import java.text.*;
import java.util.*;
import java.util.Calendar;

import org.zkoss.calendar.*;
import org.zkoss.calendar.api.CalendarEvent;
import org.zkoss.calendar.event.CalendarsEvent;
import org.zkoss.calendar.impl.*;
import org.zkoss.util.Locales;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Execution;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.WebApps;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.ForwardEvent;
import org.zkoss.zk.ui.metainfo.ComponentInfo;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.*;
import org.zkoss.zul.Timer;

public class CalendarDemoComposer extends GenericForwardComposer {

private static final long serialVersionUID = 201011240904L;
private boolean hasPE;
private SimpleCalendarModel cm;
private Calendars calendars;
private Popup updateMsg;
private Label popupLabel;
private Label label;
private Timer timer;

private Window createEvent;
private Datebox createEvent$ppbegin;
private Datebox createEvent$ppend;
private Listbox createEvent$ppbt;
private Listbox createEvent$ppet;
private Checkbox createEvent$ppallDay;
private Checkbox createEvent$pplocked;
private Combobox createEvent$ppcolor;
private Textbox createEvent$ppcnt;

private Window editEvent;
private Datebox editEvent$ppbegin;
private Datebox editEvent$ppend;
private Listbox editEvent$ppbt;
private Listbox editEvent$ppet;
private Checkbox editEvent$ppallDay;
private Checkbox editEvent$pplocked;
private Combobox editEvent$ppcolor;
private Textbox editEvent$ppcnt;
public CalendarDemoComposer() {
}

@Override
public ComponentInfo doBeforeCompose(Page page, Component parent,
ComponentInfo compInfo) {
System.out.println("Debut Executiion doBeforeCompose");
initTimeDropdown(page);
// prepare model data
initCalendarModel(page);
hasPE = WebApps.getFeature("pe");
page.setAttribute("hasPE", hasPE);
System.out.println("Fin Executiion doBeforeCompose");
return super.doBeforeCompose(page, parent, compInfo);
}

@Override
public void doAfterCompose(Component comp) throws Exception {
System.out.println("Executiion doAfterCompose");
super.doAfterCompose(comp);
updateDateLabel();
}

private void updateDateLabel() {
System.out.println("Executiion updateDateLabel");
Date b = calendars.getBeginDate();
Date e = calendars.getEndDate();
SimpleDateFormat sdfV = new SimpleDateFormat(
"yyyy/MMM/dd", Locales.getCurrent());
sdfV.setTimeZone(calendars.getDefaultTimeZone());
label.setValue(sdfV.format(b) + " - " + sdfV.format(e));
}

private void initTimeDropdown(Page page) {
System.out.println("Debut Executiion initTimeDropdown");
List dateTime = new LinkedList();

Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);

for (int i = 0; i < 288; i++) {
dateTime.add(sdf.format(calendar.getTime()));
calendar.add(Calendar.MINUTE, 5);
}
System.out.println("Fin Executiion initTimeDropdown");
page.setAttribute("dateTime", dateTime);
}

private void initCalendarModel(Page page) {
System.out.println("Debut Executiion initCalendarModel");
SimpleDateFormat dataSDF = new SimpleDateFormat("yyyy/MM/dd HH:mm");
Calendar cal = Calendar.getInstance();
int mod = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
String date2 = mod > 9 ? year + "/" + mod + "" : year + "/" + "0" + mod;
String date1 = --mod > 9 ? year + "/" + mod + "" : year + "/" + "0" + mod;
++mod;
String date3 = ++mod > 9 ? year + "/" + mod + "" : year + "/" + "0" + mod;
String[][] evts = {
// Red Events
{date1 + "/28 00:00", date1 + "/29 00:00", "#A32929", "#D96666", "ZK Jet Released"},
{date1 + "/04 02:00", date1 + "/05 03:00", "#A32929", "#D96666", "Experience ZK SpreadSheet Live Demo!"},
{date2 + "/12 10:00", date2 + "/12 20:00", "#A32929", "#D96666", "SF 2009 CCA Open: Nominate ZK Now!"},
{date2 + "/21 05:00", date2 + "/21 07:00", "#A32929", "#D96666", "New Features of ZK Spreadsheet 1.0.0 RC2"},
{date2 + "/08 00:00", date2 + "/09 00:00", "#A32929", "#D96666", "ZK Spreadsheet 1.0.0 RC2 Released"},
// Blue Events
{date1 + "/29 03:00", date2 + "/02 06:00", "#3467CE", "#668CD9", "ZK 3.6.1 Released"},
{date2 + "/02 10:00", date2 + "/02 12:30", "#3467CE", "#668CD9", "New Feature of ZK 3.6.1"},
{date2 + "/17 14:00", date2 + "/18 16:00", "#3467CE", "#668CD9", "Case Study - Mecatena"},
{date2 + "/26 00:00", date2 + "/27 00:00", "#3467CE", "#668CD9", "Small talk: A Preview Of ZK Spreadsheet 1.0"},
{date3 + "/01 14:30", date3 + "/01 17:30", "#3467CE", "#668CD9", "ZK Unit Testing Project - zunit"},
// Purple Events
{date1 + "/29 08:00", date2 + "/03 12:00", "#7A367A", "#B373B3", "ZK Studio 0.9.3 released"},
{date2 + "/07 08:00", date2 + "/07 12:00", "#7A367A", "#B373B3", "Tutorial : Reading from the DB with Netbeans and ZK"},
{date2 + "/13 11:00", date2 + "/13 14:30", "#7A367A", "#B373B3", "Small talk - ZK Charts"},
{date2 + "/16 14:00", date2 + "/18 16:00", "#7A367A", "#B373B3", "Style Guide for ZK 3.6 released !"},
{date3 + "/02 12:00", date3 + "/02 17:00", "#7A367A", "#B373B3", "Small talk -- Simple Database Access From ZK"},
// Khaki Events
{date1 + "/03 00:00", date1 + "/04 00:00", "#88880E", "#BFBF4D", "ZK 3.6.0 Released !"},
{date2 + "/04 00:00", date2 + "/07 00:00", "#88880E", "#BFBF4D", "Sun Microsystems Recruiting"},
{date2 + "/13 05:00", date2 + "/13 07:00", "#88880E", "#BFBF4D", "How to Test ZK Application with Selenium"},
{date2 + "/24 19:30", date2 + "/24 20:00", "#88880E", "#BFBF4D", "ZK Alfresco Talk"},
{date3 + "/03 00:00", date3 + "/04 00:00", "#88880E", "#BFBF4D", "ZK selected as SourceForge.net Project of the Month"},
// Green Events
{date1 + "/28 10:00", date1 + "/28 12:30", "#0D7813", "#4CB052", "ZK Mobile 0.8.10 Released"},
{date2 + "/03 00:00", date2 + "/03 05:30", "#0D7813", "#4CB052", "ZK Gmaps 2.0_11 released"},
{date2 + "/05 20:30", date2 + "/06 00:00", "#0D7813", "#4CB052", "Refresh with Five New ZK Themes!"},
{date2 + "/23 00:00", date2 + "/25 16:30", "#0D7813", "#4CB052", "ZK Roadmap 2009 Announced"},
{date3 + "/01 08:30", date3 + "/01 19:30", "#0D7813", "#4CB052", "Build Database CRUD Application in 6 Steps"}
};

// fill the events' data
cm = new SimpleCalendarModel();

for (int i = 0; i < evts.length; i++) {
SimpleCalendarEvent sce = new SimpleCalendarEvent();
try {
sce.setBeginDate(dataSDF.parse(evts[0]));
sce.setEndDate(dataSDF.parse(evts[1]));
} catch (ParseException e) {
e.printStackTrace();
}
sce.setHeaderColor(evts[2]);
sce.setContentColor(evts[3]);
// ce.setTitle() if any, otherwise, the time stamp is assumed.
sce.setContent(evts[4]);
cm.add(sce);
}
System.out.println("------------------------------------------------------------------------------------");
System.out.println("Envoie de CM");
System.out.println("------------------------------------------------------------------------------------");
page.setAttribute("cm", cm);
System.out.println("CM envoié");
System.out.println("Fin Executiion initCalendarModel");
}

public void onEventCreate$calendars(ForwardEvent event) {
System.out.println("Debut Executiion onEventCreate$calendars");
CalendarsEvent evt = (CalendarsEvent) event.getOrigin();
int left = evt.getX();
int top = evt.getY();
int timeslots = calendars.getTimeslots();
int timeslotTime = 60 / timeslots;
if (top + 245 > evt.getDesktopHeight())
top = evt.getDesktopHeight() - 245;
if (left + 410 > evt.getDesktopWidth())
left = evt.getDesktopWidth() - 410;
createEvent.setLeft(left + "px");
createEvent.setTop(top + "px");
SimpleDateFormat create_sdf = new SimpleDateFormat("HH:mm");
create_sdf.setTimeZone(calendars.getDefaultTimeZone());
String[] times = create_sdf.format(evt.getBeginDate()).split(":");
int hours = Integer.parseInt(times[0]) * timeslots;
int mins = Integer.parseInt(times[1]);
int bdTimeSum = hours + mins;
hours += mins / timeslotTime;

createEvent$ppbt.setSelectedIndex(hours * 12 / timeslots);
times = create_sdf.format(evt.getEndDate()).split(":");
hours = Integer.parseInt(times[0]) * timeslots;
mins = Integer.parseInt(times[1]);
int edTimeSum = hours + mins;
hours += mins / timeslotTime;
((Listbox)createEvent.getFellow("ppet")).setSelectedIndex(hours * 12 / timeslots);
boolean isAllday = (bdTimeSum + edTimeSum) == 0;

createEvent$ppbegin.setTimeZone(calendars.getDefaultTimeZone());
createEvent$ppbegin.setValue(evt.getBeginDate());
createEvent$ppend.setTimeZone(calendars.getDefaultTimeZone());
createEvent$ppend.setValue(evt.getEndDate());
createEvent$ppallDay.setChecked(isAllday);
createEvent$pplocked.setChecked(false);
createEvent$ppbt.setVisible(!isAllday);
createEvent$ppet.setVisible(!isAllday);

createEvent.setVisible(true);
createEvent.setAttribute("calevent", evt);
evt.stopClearGhost();
System.out.println("Fin Executiion onEventCreate$calendars");
}

public void onClose$createEvent(ForwardEvent event) {
event.getOrigin().stopPropagation();
((CalendarsEvent)createEvent.getAttribute("calevent")).clearGhost();
createEvent.setVisible(false);
}

public void onClick$okBtn$createEvent(ForwardEvent event) {
SimpleCalendarEvent ce = new SimpleCalendarEvent();
Calendar cal = Calendar.getInstance(calendars.getDefaultTimeZone());
Date beginDate = createEvent$ppbegin.getValue();
Date endDate = createEvent$ppend.getValue();

int bmin = 0;
int emin = 0;
if (!createEvent$ppallDay.isChecked()) {
String[] times = createEvent$ppbt.getSelectedItem().getLabel().split(":");

cal.setTime(beginDate);
cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(times[0]));
cal.set(Calendar.MINUTE, Integer.parseInt(times[1]));
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
beginDate = cal.getTime();
bmin = cal.get(Calendar.MINUTE);
times = createEvent$ppet.getSelectedItem().getLabel().split(":");
cal.setTime(endDate);
cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(times[0]));
cal.set(Calendar.MINUTE, Integer.parseInt(times[1]));
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
endDate = cal.getTime();
emin = cal.get(Calendar.MINUTE);
}

if (!beginDate.before(endDate)) {
createEvent.setVisible(false);
alert("The end date cannot be earlier than or equal to begin date!");
((CalendarsEvent)createEvent.getAttribute("calevent")).clearGhost();
return;
}
if (bmin == 5 || bmin == 25 || bmin == 35 || bmin == 55) {
createEvent.setVisible(false);
alert("The begin minute:" + bmin + ", is not supported");
((CalendarsEvent)createEvent.getAttribute("calevent")).clearGhost();
return;
}
if (emin == 5 || emin == 25 || emin == 35 || emin == 55) {
createEvent.setVisible(false);
alert("The end minute:" + emin + ", doesn't support");
((CalendarsEvent)createEvent.getAttribute("calevent")).clearGhost();
return;
}

String[] colors = ((String)createEvent$ppcolor.getSelectedItem().getValue()).split(",");
ce.setHeaderColor(colors[0]);
ce.setContentColor(colors[1]);
ce.setBeginDate(beginDate);
ce.setEndDate(endDate);
ce.setContent(createEvent$ppcnt.getValue());
ce.setLocked(createEvent$pplocked.isChecked());
cm.add(ce);

createEvent$ppcnt.setRawValue("");
createEvent$ppbt.setSelectedIndex(0);
createEvent$ppet.setSelectedIndex(0);
createEvent.setVisible(false);
//syncModel();
}

public void onClick$cancelBtn$createEvent(ForwardEvent event) {
createEvent$ppcnt.setRawValue("");
createEvent$ppbt.setSelectedIndex(0);
createEvent$ppet.setSelectedIndex(0);
createEvent.setVisible(false);
((CalendarsEvent)createEvent.getAttribute("calevent")).clearGhost();
}

public void onEventEdit$calendars(ForwardEvent event) {
CalendarsEvent evt = (CalendarsEvent) event.getOrigin();

int left = evt.getX();
int top = evt.getY();
if (top + 245 > evt.getDesktopHeight())
top = evt.getDesktopHeight() - 245;
if (left + 410 > evt.getDesktopWidth())
left = evt.getDesktopWidth() - 410;

TimeZone tz = calendars.getDefaultTimeZone();

editEvent.setLeft(left + "px");
editEvent.setTop(top + "px");
CalendarEvent ce = evt.getCalendarEvent();
SimpleDateFormat edit_sdf = new SimpleDateFormat("HH:mm");
edit_sdf.setTimeZone(tz);
Calendar calendar = Calendar.getInstance(org.zkoss.util.Locales
.getCurrent());
String[] times = edit_sdf.format(ce.getBeginDate()).split(":");
int hours = Integer.parseInt(times[0]);
int mins = Integer.parseInt(times[1]);
int bdTimeSum = hours + mins;
editEvent$ppbt.setSelectedIndex(hours*12 + mins/5);
times = edit_sdf.format(ce.getEndDate()).split(":");
hours = Integer.parseInt(times[0]);
mins = Integer.parseInt(times[1]);
int edTimeSum = hours + mins;
editEvent$ppet.setSelectedIndex(hours*12 + mins/5);
boolean isAllday = (bdTimeSum + edTimeSum) == 0;
editEvent$ppbegin.setTimeZone(tz);
editEvent$ppbegin.setValue(ce.getBeginDate());
editEvent$ppend.setTimeZone(tz);
editEvent$ppend.setValue(ce.getEndDate());
editEvent$ppallDay.setChecked(isAllday);
editEvent$pplocked.setChecked(ce.isLocked());
editEvent$ppbt.setVisible(!isAllday);
editEvent$ppet.setVisible(!isAllday);
editEvent$ppcnt.setValue(ce.getContent());
String colors = ce.getHeaderColor() + "," + ce.getContentColor();
int index = 0;
if ("#3467CE,#668CD9".equals(colors))
index = 1;
else if ("#0D7813,#4CB052".equals(colors))
index = 2;
else if ("#88880E,#BFBF4D".equals(colors))
index = 3;
else if ("#7A367A,#B373B3".equals(colors))
index = 4;

switch (index) {
case 0:
editEvent$ppcolor.setStyle("color:#D96666;font-weight: bold;");
break;
case 1:
editEvent$ppcolor.setStyle("color:#668CD9;font-weight: bold;");
break;
case 2:
editEvent$ppcolor.setStyle("color:#4CB052;font-weight: bold;");
break;
case 3:
editEvent$ppcolor.setStyle("color:#BFBF4D;font-weight: bold;");
break;
case 4:
editEvent$ppcolor.setStyle("color:#B373B3;font-weight: bold;");
break;
}
editEvent$ppcolor.setSelectedIndex(index);
editEvent.setVisible(true);

// store for the edit marco component.
editEvent.setAttribute("ce", ce);
}

public void onClose$editEvent(ForwardEvent event) {
event.getOrigin().stopPropagation();
editEvent.setVisible(false);
}

public void onClick$okBtn$editEvent(ForwardEvent event) {
SimpleCalendarEvent ce = (SimpleCalendarEvent) editEvent.getAttribute("ce");
Calendar cal = Calendar.getInstance(calendars.getDefaultTimeZone());
Date beginDate = editEvent$ppbegin.getValue();
Date endDate = editEvent$ppend.getValue();

int bmin = 0;
int emin = 0;
if (!editEvent$ppallDay.isChecked()) {
String[] times = editEvent$ppbt.getSelectedItem().getLabel().split(":");
cal.setTime(beginDate);
cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(times[0]));
cal.set(Calendar.MINUTE, Integer.parseInt(times[1]));
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
beginDate = cal.getTime();
times = editEvent$ppet.getSelectedItem().getLabel().split(":");
cal.setTime(endDate);
cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(times[0]));
cal.set(Calendar.MINUTE, Integer.parseInt(times[1]));
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
endDate = cal.getTime();
} else {
cal.setTime(beginDate);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
beginDate = cal.getTime();
bmin = cal.get(Calendar.MINUTE);
cal.setTime(endDate);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
endDate = cal.getTime();
emin = cal.get(Calendar.MINUTE);
}
if (!beginDate.before(endDate)) {
editEvent.setVisible(false);
alert("The end date cannot be earlier than or equal to begin date!");
((org.zkoss.calendar.event.CalendarsEvent)editEvent.getAttribute("calevent")).clearGhost();
return;
}
if (bmin == 5 || bmin == 25 || bmin == 35 || bmin ==55) {
editEvent.setVisible(false);
alert("The begin minute:" + bmin + ", is not supported");
((org.zkoss.calendar.event.CalendarsEvent)editEvent.getAttribute("calevent")).clearGhost();
return;
}
if (emin == 5 || emin == 25 || emin == 35 || emin ==55) {
editEvent.setVisible(false);
alert("The end minute:" + emin + ", doesn't support");
((org.zkoss.calendar.event.CalendarsEvent)editEvent.getAttribute("calevent")).clearGhost();
return;
}
String[] colors = ((String)editEvent$ppcolor.getSelectedItem().getValue()).split(",");
ce.setHeaderColor(colors[0]);
ce.setContentColor(colors[1]);
ce.setBeginDate(beginDate);
ce.setEndDate(endDate);
ce.setContent(editEvent$ppcnt.getValue());
ce.setLocked(editEvent$pplocked.isChecked());
cm.update(ce);
editEvent.setVisible(false);
//syncModel();
}

public void onClick$deleteBtn$editEvent(ForwardEvent event) {
try {
Messagebox.show("Are you sure to delete the event!", "Question",
Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION,
new EventListener() {
public void onEvent(Event evt) throws Exception {
if (((Integer) evt.getData()).intValue() != Messagebox.OK)
return;
cm.remove((SimpleCalendarEvent) editEvent.getAttribute("ce"));
}
});
} catch (InterruptedException e) {
e.printStackTrace();
}
editEvent.setVisible(false);
}

public void onEventUpdate$calendars(ForwardEvent event) {
CalendarsEvent evt = (CalendarsEvent) event.getOrigin();
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy/MM/d");
sdf1.setTimeZone(calendars.getDefaultTimeZone());
StringBuffer sb = new StringBuffer("Update... from ");
sb.append(sdf1.format(evt.getCalendarEvent().getBeginDate()));
sb.append(" to ");
sb.append(sdf1.format(evt.getBeginDate()));
popupLabel.setValue(sb.toString());
int left = evt.getX();
int top = evt.getY();
if (top + 100 > evt.getDesktopHeight())
top = evt.getDesktopHeight() - 100;
if (left + 330 > evt.getDesktopWidth())
left = evt.getDesktopWidth() - 330;
updateMsg.open(left, top);
timer.start();
org.zkoss.calendar.Calendars cal = (org.zkoss.calendar.Calendars) evt
.getTarget();
SimpleCalendarModel m = (SimpleCalendarModel) cal.getModel();
SimpleCalendarEvent sce = (SimpleCalendarEvent) evt.getCalendarEvent();
sce.setBeginDate(evt.getBeginDate());
sce.setEndDate(evt.getEndDate());
m.update(sce);
}

public void onMoveDatePrevious(ForwardEvent event) {
calendars.previousPage();
updateDateLabel();
}
public void onMoveDateNext(ForwardEvent event) {
calendars.nextPage();
updateDateLabel();
}
public void onToday(ForwardEvent event) {
calendars.setCurrentDate(Calendar.getInstance(calendars.getDefaultTimeZone()).getTime());
updateDateLabel();
}

public void onSwitchTimeZone(ForwardEvent event) {
Map zone = calendars.getTimeZones();
if (!zone.isEmpty()) {
Map.Entry me = (Map.Entry) zone.entrySet().iterator().next();
calendars.removeTimeZone((TimeZone) me.getKey());
calendars.addTimeZone((String) me.getValue(), (TimeZone) me.getKey());
}
}

public void onUpdateFirstDayOfWeek(ForwardEvent event) {
Listbox listbox = (Listbox) event.getOrigin().getTarget();
calendars.setFirstDayOfWeek(listbox.getSelectedItem().getLabel());
}

public void onUpdateView(ForwardEvent event) {
String text = String.valueOf(event.getData());
int days = "Day".equals(text) ? 1: "5 Days".equals(text) ? 5: "Week".equals(text) ? 7: 0;

if (days > 0) {
calendars.setMold("default");
calendars.setDays(days);
} else calendars.setMold("month");
updateDateLabel();
}

}



Calendar.jsp


<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ taglib uri="http://www.zkoss.org/jsp/zul" prefix="z"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<head>
<link rel="stylesheet" type="text/css" href="css/zkcalendar.css" />
</head>

<body>
<z:init use="org.zkoss.zkplus.databind.AnnotateDataBinderInit" />
<z:page>
<z:window apply="com.diorh.calendar.CalendarDemoComposer"
height="100%">
<z:calendars id="calendars" firstDayOfWeek="Sunday"
timeZone="Casablanca=GMT" model="${cm }" mold="default">
<z:toolbar sclass="calendar-toolbar">
<z:div class="float-left">
<z:hbox>

<!-- arrow-left -->
<z:div class="tabs arrows"
forward="onMoveDatePrevious('arrow-left')">
<z:div class="t1" />
<z:div class="t2">
<z:div class="t3" />
</z:div>
<z:div class="bd">
<z:div class="cm cnt">
<z:div class="text"
style="position:relative; width:15px; height:15px;">
<z:div sclass="arrow-left" />
</z:div>
</z:div>
</z:div>
<z:div class="b2">
<z:div class="b3" />
</z:div>
<z:div class="b1" />
</z:div>
<!-- arrow-left -->
<!-- arrow-left -->
<z:div class="tabs arrows"
forward="onMoveDateNext('arrow-right')">
<z:div class="t1" />
<z:div class="t2">
<z:div class="t3" />
</z:div>
<z:div class="bd">
<z:div class="cm cnt">
<z:div class="text"
style="position:relative; width:15px; height:15px;">
<z:div sclass="arrow-right" />
</z:div>
</z:div>
</z:div>
<z:div class="b2">
<z:div class="b3" />
</z:div>
<z:div class="b1" />
</z:div>
<!-- arrow-left -->
<z:div>
<z:separator orient="vertical" />
<z:label id="label" />
<z:toolbarbutton label="Refresh" class="refresh"
onClick='calendars.invalidate();' />
</z:div>
</z:hbox>
</z:div>
</z:toolbar>
</z:calendars>
</z:window>
</z:page>
</body>
</html>



web.xml


<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>test</display-name>
<listener>
<description>
Used to cleanup when a session is destroyed</description>
<display-name>ZK Session cleaner</display-name>
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
</listener>
<listener>
<description>ZK JspTags EL environment initiation </description>
<display-name>ZK Jsp Factory initiator</display-name>
<listener-class>org.zkoss.jsp.spec.JspFactoryContextListener</listener-class>
</listener>
<servlet>
<description>
The ZK loader for ZUML pages</description>
<servlet-name>zkLoader</servlet-name>
<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
<init-param>
<param-name>update-uri</param-name>
<param-value>/zkau</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<description>
The asynchronous update engine for ZK</description>
<servlet-name>auEngine</servlet-name>
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zul</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.zhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>auEngine</servlet-name>
<url-pattern>/zkau/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>index.zul</welcome-file>
</welcome-file-list>
</web-app>



Result of the execution:
..........
9 juil. 2011 18:47:33 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/15 config=null
9 juil. 2011 18:47:33 org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
9 juil. 2011 18:47:33 org.apache.catalina.startup.Catalina start
INFO: Server startup in 1219 ms
Executiion doAfterCompose
Executiion updateDateLabel

Please help me
Regards

delete flag offensive retag edit

9 Replies

Sort by » oldest newest

answered 2011-07-09 16:59:41 +0800

robertpic71 gravatar image robertpic71
1275 1

I did not study the whole code - but i think you have to implement the interface ComposerExt.

The "normal" composer only catch the doAfterCompose.
Check this docs: An_Introduction_of_ZK_Composer

...and implements ComposerExt...

link publish delete flag offensive edit

answered 2011-07-09 18:59:21 +0800

aitelghali gravatar image aitelghali
12

updated 2011-07-09 19:02:02 +0800

thank you for your answer, but i want to catch the doBeforeCompose.
Here's another simple example.
================ TestComposer.java======================================
package com.diorh.calendar;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.metainfo.ComponentInfo;
import org.zkoss.zk.ui.util.GenericForwardComposer;

public class TestComposer extends GenericForwardComposer{
private static final long serialVersionUID = 1L;

@Override
public ComponentInfo doBeforeCompose(Page page, Component parent,
ComponentInfo compInfo) {
System.out.println("doBeforeCompose executed");
return super.doBeforeCompose(page, parent, compInfo);
}
@Override
public void doAfterCompose(Component comp) throws Exception {
System.out.println("doAfterCompose executed ");
super.doAfterCompose(comp);
}

}
================myTestComposer.jsp ==================================
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ taglib uri="http://www.zkoss.org/jsp/zul" prefix="z"%>
<head>
<link rel="stylesheet" type="text/css" href="css/zkcalendar.css" />
</head>
<body>
<z:page>
<z:window id="TestComposerJSP" apply="com.diorh.calendar.TestComposer"
height="100%">
</z:window>
</z:page>
</body>
</html>
===================== execution result===================
..........
10 juil. 2011 00:56:50 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/31 config=null
10 juil. 2011 00:56:50 org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
10 juil. 2011 00:56:50 org.apache.catalina.startup.Catalina start
INFO: Server startup in 1250 ms
doAfterCompose executed

================== But I want to have as a result===============
............
...........
doBeforeCompose executed
doAfterCompose executed

Thank you in advance

link publish delete flag offensive edit

answered 2011-07-10 04:14:51 +0800

robertpic71 gravatar image robertpic71
1275 1

Try:
... extends GenericForwardComposer implements ComposerExt

Check the docs: API

link publish delete flag offensive edit

answered 2011-07-10 06:08:46 +0800

aitelghali gravatar image aitelghali
12

Even by implementing the interface ComposerExt , the method doBeforeCompose is not running.
here is my new calsse java :

public class TestComposer extends GenericForwardComposer implements ComposerExt{
private static final long serialVersionUID = 1L;

@Override
public ComponentInfo doBeforeCompose(Page page, Component parent,
ComponentInfo compInfo) {
System.out.println("doBeforeCompose executed");
return super.doBeforeCompose(page, parent, compInfo);
}

@Override
public void doAfterCompose(Component comp) throws Exception {
System.out.println("doAfterCompose executed ");
super.doAfterCompose(comp);
}

}

===================== execution result===================
..........
10 juil. 2011 00:56:50 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/31 config=null
10 juil. 2011 00:56:50 org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
10 juil. 2011 00:56:50 org.apache.catalina.startup.Catalina start
INFO: Server startup in 1250 ms
doAfterCompose executed

================== But I want to have as a result===============
............
...........
doBeforeCompose executed
doAfterCompose executed

Thank you in advance

link publish delete flag offensive edit

answered 2011-07-10 09:57:46 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

updated 2011-07-10 10:00:00 +0800

aitelghali, a few points:
1) When putting your code examples in a forum post, you should always put it inside source code tags. The bold, italic, underline, source code, link, and separator bar buttons are at the top of the forum editor so you don't have to type them. It's very difficult to read that much source with it all crammed on the left margin. There is a line above the forum editor when creating a new thread that ends something like this: "...use [ code ][/ code ] to wrap your code."

2) If you do as robertpic71 suggested and read the Javadoc for GenericForwardComposer, you'll see this:

All Implemented Interfaces:
    java.io.Serializable, EventListener, ComponentActivationListener, ComponentCloneListener, Composer, ComposerExt 

With your CalendarDemoComposer extending GFC, it inherits a stub doBeforeCompose(...) from GenericComposer by virtue of the class hierarchy GenericComposer->GenericAutowireComposer->GenericForwardComposer->CalendarDemoComposer. So, there is no need to implement ComposerExt yourself.

3) The easiest way to start pinning down the problem is to use a very small ZUL file to see if it runs the doBeforeCompose(...)...like this:

<zk>
    <window apply="com.diorh.calendar.CalendarDemoComposer" width="100%" height="100%" border="normal">
        <div style="border: 10px solid red;" >
            I'm a box with a fat red border
        </div>
    </window>
</zk>

This will immediately tell you if you have a problem in your JSP using the tags or if the problem lies elsewhere. I just overrode doBeforeCompose(...) in one of my controller classes that extends GFC and set a breakpoint. Eclipse stopped on it and wrote the log message when I let it run:

    @Override
    public ComponentInfo doBeforeCompose( Page page, Component parent, ComponentInfo compInfo )
    {
        logger.info( "::doBeforeCompose:" ) ;
        return super.doBeforeCompose( page, parent, compInfo ) ;
    }

I did this with ZK 5.0.7.1. You didn't say which version you're running.

link publish delete flag offensive edit

answered 2011-07-11 09:03:12 +0800

aitelghali gravatar image aitelghali
12

Thank you very much for your help.
My problem is solved.

Regards

link publish delete flag offensive edit

answered 2011-07-11 09:46:44 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

Solved how? Others reading the thread someday would probably like to know...even if it's something silly that you'd done...

link publish delete flag offensive edit

answered 2011-10-04 12:54:42 +0800

SparkySpider gravatar image SparkySpider
444 1 3

Um exactly. aitelghali please post your experience.

I need to check if a user is "allowed" to view the page, and if they are not, I'd like to redirect them off somewhere else or do something nasty like give them a friendly error message. I thought that it would make sense to do it in doBeforeCompose.

What is the generally used strategy in ZK for this?

Thanks a mill!

Mark

link publish delete flag offensive edit

answered 2011-10-10 13:41:56 +0800

iantsai gravatar image iantsai
2755 1

updated 2011-10-10 13:48:19 +0800

About the problem that aitelghali was facing, the problem is in JSP, there's no way for ZK to do anything about doBeforeCompose().

JSP is static and it ask zk to generate the result before ZK can make the composer's life-cycle start, so this is one of the incompatibility between ZK and JSP.
Developers who want to get such kind of fine-grained control should use ZUL instead of JSP.

@SparkySpider
About your question, I think if the granularity that you have is about a single ZUL page, it's better to use Initiator, DesktopInit or Servlet Filter to do that rather than do it in Composer.
Personally I'd prefer to deal with it in Filter because normally these requirements should have no relationship to ZK.

It's better to do it in Composer's doBeforecompose() only when the "effective area" is the controlled part of that Composer.

For example, if you want to have an org.zkoss.zul.A declared in ZUL which will be switched to org.zkoss.zul.Label if user don't have the permission to access a function but should know that there's such function, then doBeforeCompose () is perfect for you.

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: 2011-07-09 12:49:17 +0800

Seen: 918 times

Last updated: Oct 10 '11

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