Skip to content

Commit 376e066

Browse files
author
Vitalii
committed
ZKoss example
1 parent 67168c5 commit 376e066

File tree

11 files changed

+382
-0
lines changed

11 files changed

+382
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Class-Path:
3+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<display-name>ZKossExample</display-name>
4+
<listener>
5+
<description>Used to cleanup when a session is destroyed</description>
6+
<display-name>ZK Session cleaner</display-name>
7+
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
8+
</listener>
9+
<servlet>
10+
<description>The ZK loader for ZUML pages</description>
11+
<servlet-name>zkLoader</servlet-name>
12+
<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
13+
<init-param>
14+
<param-name>update-uri</param-name>
15+
<param-value>/zkau</param-value>
16+
</init-param>
17+
<load-on-startup>1</load-on-startup>
18+
</servlet>
19+
<servlet>
20+
<description>The asynchronous update engine for ZK</description>
21+
<servlet-name>auEngine</servlet-name>
22+
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
23+
</servlet>
24+
<servlet>
25+
<description>
26+
</description>
27+
<display-name>UserServlet</display-name>
28+
<servlet-name>UserServlet</servlet-name>
29+
<servlet-class>UserServlet</servlet-class>
30+
</servlet>
31+
32+
<servlet-mapping>
33+
<servlet-name>zkLoader</servlet-name>
34+
<url-pattern>*.zul</url-pattern>
35+
</servlet-mapping>
36+
<servlet-mapping>
37+
<servlet-name>zkLoader</servlet-name>
38+
<url-pattern>*.zhtml</url-pattern>
39+
</servlet-mapping>
40+
<servlet-mapping>
41+
<servlet-name>auEngine</servlet-name>
42+
<url-pattern>/zkau/*</url-pattern>
43+
</servlet-mapping>
44+
<servlet-mapping>
45+
<servlet-name>UserServlet</servlet-name>
46+
<url-pattern>/UserServlet</url-pattern>
47+
</servlet-mapping>
48+
<welcome-file-list>
49+
<welcome-file>index.html</welcome-file>
50+
<welcome-file>index.htm</welcome-file>
51+
<welcome-file>index.jsp</welcome-file>
52+
<welcome-file>default.html</welcome-file>
53+
<welcome-file>default.htm</welcome-file>
54+
<welcome-file>default.jsp</welcome-file>
55+
<welcome-file>index.zul</welcome-file>
56+
</welcome-file-list>
57+
</web-app>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Created by ZK Studio
5+
-->
6+
7+
<zk>
8+
<device-config>
9+
<device-type>ajax</device-type>
10+
<timeout-uri>/timeout.zul</timeout-uri><!-- An empty URL can cause the browser to reload the same URL -->
11+
</device-config>
12+
13+
<richlet>
14+
<richlet-class>example.richlet.UserRichlet</richlet-class>
15+
<richlet-url>/user.zul</richlet-url>
16+
</richlet>
17+
18+
<!--
19+
<richlet>
20+
<richlet-name>user_richlet</richlet-name>
21+
<richlet-class>example.richlet.UserRichlet</richlet-class>
22+
</richlet>
23+
24+
<richlet-mapping>
25+
<richlet-name>user_richlet</richlet-name>
26+
<url-pattern>/user.zul</url-pattern>
27+
</richlet-mapping>
28+
-->
29+
</zk>

ZKossExample/WebContent/index.zul

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?page title="Auto Generated index.zul"?>
2+
<window title="Hello World!!" border="normal" width="200px" id="windowMain" position="right,top" sizable="true" tooltiptext="this is tooltip text" droppable="true" closable="true">
3+
4+
<label value="You are using: ${desktop.webApp.version}"/>
5+
<textbox id="t1" value="this is simple text"> </textbox>
6+
<button label="JavaScript inner code" id="b1" orient="horizontal" draggable="true">
7+
<attribute name="onClick">
8+
<![CDATA[
9+
System.out.println("Click to button: "+this.getClass().getName());
10+
alert("Test");
11+
// перенаправление
12+
execution.sendRedirect("temp_example.zul");
13+
// получение доступа к сессии
14+
// windowMain.getDesktop().getSession()
15+
]]>
16+
</attribute>
17+
</button>
18+
<separator></separator>
19+
20+
<button label="Java Script function" id="b2" onClick="showAlert()">
21+
</button>
22+
23+
<button label="Sample button" id="b3" onClick="b3.setVisible(false);"></button>
24+
25+
<zscript>
26+
<![CDATA[
27+
import org.zkoss.zhtml.*;
28+
import example.first.*;
29+
30+
int counter=0;
31+
32+
private void showAlert(){
33+
t1.setValue(Integer.toString(++counter));
34+
b3.setVisible(true);
35+
System.out.println(++StaticProperties.intValue);
36+
}
37+
]]>
38+
</zscript>
39+
</window>

ZKossExample/WebContent/temp.css

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*SEC:BUTTON-DEFAULT:*/
2+
/*RULE:TOP-LEFT*/
3+
.z-button .z-button-tl{
4+
background-color : #FF0000; /*PRO*/
5+
}
6+
/*RULE_E*/
7+
/*RULE:BOTTOM-LEFT*/
8+
.z-button .z-button-bl{
9+
background-color : #FF0000; /*PRO*/
10+
}
11+
/*RULE_E*/
12+
/*RULE:CENTER-LEFT*/
13+
.z-button .z-button-cl{
14+
background-color : #FF0000; /*PRO*/
15+
}
16+
/*RULE_E*/
17+
/*RULE:CENTER-MIDDLE*/
18+
.z-button .z-button-cm{
19+
background-color : #FF0000; /*PRO*/
20+
}
21+
/*RULE_E*/
22+
/*RULE:CENTER-RIGHT*/
23+
.z-button .z-button-cr{
24+
background-color : #FF0000; /*PRO*/
25+
}
26+
/*RULE_E*/
27+
/*RULE:TOP-MIDDLE*/
28+
.z-button .z-button-tm{
29+
background-color : #FF0000; /*PRO*/
30+
}
31+
/*RULE_E*/
32+
/*RULE:TOP-RIGHT*/
33+
.z-button .z-button-tr{
34+
background-color : #FF0000; /*PRO*/
35+
}
36+
/*RULE_E*/
37+
/*RULE:BOTTOM-MIDDLE*/
38+
.z-button .z-button-bm{
39+
background-color : #FF0000; /*PRO*/
40+
}
41+
/*RULE_E*/
42+
/*RULE:BOTTOM-RIGHT*/
43+
.z-button .z-button-br{
44+
background-color : #FF0000; /*PRO*/
45+
}
46+
/*RULE_E*/
47+
/*SEC_E*//*SEC:LABEL:anchor_link*/
48+
/*RULE:BASIC*/
49+
.anchor_link.z-label {
50+
border-style : dashed; /*PRO*/
51+
border-width : thin; /*PRO*/
52+
border-color : #FF0000; /*PRO*/
53+
}
54+
/*RULE_E*/
55+
/*SEC_E*/
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?page title="example" contentType="text/html;charset=UTF-8"?>
2+
<zk>
3+
<window title="example" border="normal" id="windowMain" onCreate="beginInit()" onFulfill="endInit()" width="300">
4+
<vbox align="center" width="100%">
5+
<label id="label1">Click this button for input </label>
6+
<textbox id="t1" value="this is textbox value"></textbox>
7+
<button id="button1" label="click" onClick="buttonClick()"></button>
8+
<label id="label2" visible="false" onClick="onLabelReaction()" class="anchor_link">flag of parameter</label>
9+
<button id="button_show_servlet" label="GoTo Servlet" onClick="buttonServlet()" />
10+
<separator />
11+
<button onClick="showModal()" label="show modal" />
12+
</vbox>
13+
<zscript>
14+
<![CDATA[
15+
import example.first.ShareObject;
16+
import org.zkoss.zk.ui.event.EventListener;
17+
18+
String value1=null;
19+
20+
/** реакция на нажатие Label */
21+
private void onLabelReaction(){
22+
System.out.println("LabelReaction: "+t1.getValue());
23+
}
24+
25+
private void buttonClick(){
26+
System.out.println("Click the button:"+execution.getParameter("value"));
27+
alert(value1);
28+
// получить имя браузера
29+
System.out.println("UserAgent:"+execution.getUserAgent());
30+
// установить атрибут сессии
31+
session.setAttribute("user_zk_attribute",new ShareObject(3,"three"));
32+
label2.setVisible(!label2.isVisible());
33+
}
34+
35+
private void buttonServlet(){
36+
// перенаправить вызов на сервлет
37+
execution.sendRedirect("UserServlet");
38+
}
39+
40+
/** первоначальная инициализация страницы */
41+
private void beginInit(){
42+
System.out.println("begin init");
43+
System.out.println("Request parameter: value="+execution.getParameter("value"));
44+
if(execution.getParameter("show_label")!=null){
45+
label2.setVisible(true);
46+
value1=execution.getParameter("show_label");
47+
}
48+
}
49+
50+
private void showModal(){
51+
Window win=new Window("modal window example", "normal", true);
52+
final Textbox textbox=new Textbox("this is temp value");
53+
textbox.setParent(win);
54+
win.addEventListener("onClose",new EventListener(){
55+
public void onEvent(Event event) throws Exception{
56+
System.out.println("event onClose, value:"+textbox.getValue());
57+
}
58+
});
59+
win.setWidth("100px");
60+
win.setHeight("100px");
61+
win.setParent(windowMain);
62+
// windowMain.getPage();
63+
64+
win.doModal();
65+
// win.onModal();
66+
}
67+
]]>
68+
</zscript>
69+
</window>
70+
</zk>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<window width="80%" title="Session Timeout" border="normal">
2+
<vbox>
3+
The page or component you request is no longer available.
4+
This is normally caused by timeout, opening too many Web pages, or rebooting
5+
the server.
6+
</vbox>
7+
</window>

ZKossExample/src/UserServlet.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
3+
import java.io.IOException;
4+
import javax.servlet.ServletException;
5+
import javax.servlet.ServletOutputStream;
6+
import javax.servlet.http.HttpServlet;
7+
import javax.servlet.http.HttpServletRequest;
8+
import javax.servlet.http.HttpServletResponse;
9+
10+
/**
11+
* Servlet implementation class UserServlet
12+
*/
13+
public class UserServlet extends HttpServlet {
14+
private static final long serialVersionUID = 1L;
15+
16+
/**
17+
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
18+
*/
19+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
20+
doAction(request, response);
21+
}
22+
23+
/**
24+
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
25+
*/
26+
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
27+
doAction(request, response);
28+
}
29+
30+
private void doAction(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
31+
Object sessionObject=request.getSession().getAttribute("user_zk_attribute");
32+
String outputValue=null;
33+
if(sessionObject!=null){
34+
outputValue=sessionObject.getClass().getName();
35+
System.out.println("Session Object:"+outputValue);
36+
}
37+
38+
ServletOutputStream out=response.getOutputStream();
39+
out.println("<html>");
40+
out.println(" <head>");
41+
out.println(" <title>user servlet</title>");
42+
out.println(" </head>");
43+
out.println(" <body>");
44+
out.println(" session user object: "+outputValue);
45+
out.println(" </body>");
46+
out.println("</html>");
47+
}
48+
49+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package example.first;
2+
3+
import java.io.Serializable;
4+
5+
public class ShareObject implements Serializable{
6+
private final static long serialVersionUID=1L;
7+
private int id;
8+
private String name;
9+
10+
public ShareObject(){}
11+
12+
public ShareObject(int id, String name){
13+
this.id=id;
14+
this.name=name;
15+
}
16+
17+
public int getId() {
18+
return id;
19+
}
20+
public void setId(int id) {
21+
this.id = id;
22+
}
23+
public String getName() {
24+
return name;
25+
}
26+
public void setName(String name) {
27+
this.name = name;
28+
}
29+
30+
@Override
31+
public String toString(){
32+
33+
return this.id+":"+this.name;
34+
}
35+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package example.first;
2+
3+
/** ãëîáàëüíûå íàñòðîéêè ñèñòåìû */
4+
public class StaticProperties {
5+
/** êîë-âî îáðàùåíèé */
6+
public static int intValue=0;
7+
}

0 commit comments

Comments
 (0)