- 浏览: 453261 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
a464697691:
楼主厉害,现在可以使用了
Proxool houseKeepingSleepTime bug修正 -
chenpi529:
楼主好牛逼
Proxool houseKeepingSleepTime bug修正 -
huangxinyu_it:
多谢楼主了
Proxool houseKeepingSleepTime bug修正 -
kokorodo:
谢谢了!
zk中文开发手册pdf版(基于3.5.1) -
superscorpio:
public void testImportInContex ...
MVEL2.0控制流
ZkUtils集合了zk中常用的一些功能,方便开发中的使用,
该版本更新列表:
1,修复了一些bug,
2,增加更详尽的注释
3,增加了一些常用方法
附件内有源码
package org.sunflower.common.web.zk.util; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Collection; import java.util.Map; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Components; import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Execution; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Session; import org.zkoss.zk.ui.Sessions; import org.zkoss.zk.ui.WebApp; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.ForwardEvent; import org.zkoss.zk.ui.util.Clients; import org.zkoss.zul.Messagebox; /** * ZkUtils集合了zk中常用的一些功能,方便开发中的使用 * * * @author sunflower * * 时间:2010-7-9 上午09:40:26 * * Email:zhangxuehuaemail # gmail 点 com * */ public class ZkUtils { /** * 获取当前Execution * * @return */ public static Execution exec() { return Executions.getCurrent(); } /** * 获得当前桌面 * * @return */ public static Desktop desktop() { return exec().getDesktop(); } /** * 返回当前桌面的webapp * * @return */ public static WebApp webApp() { return desktop().getWebApp(); } /** * 返回指定key的webapp作用域内的对象 * * @param key * @return */ public static Object webAppAttr(String key) { return webApp().getAttribute(key); } /** * 设置指定key的webapp作用域对象 * * @param key * @param value */ public static void setAppAttr(String key, Object value) { webApp().setAttribute(key, value); } /** * 获得给定路径的URL * * @param path * @return */ public static URL getResource(String path) { return webApp().getResource(path); } /** * 获得跟定资源的二进制流 * * <p> * Notice that, since 3.6.3, this method can retreive the resource starting * with "~./". If the path contains the wildcard ('*'), you can use * {@link Execution#locate} to convert it to a proper string first. */ public static InputStream getResourceAsStream(String path) { return webApp().getResourceAsStream(path); } /** * 获得 path虚拟路径的实际路径 . 例如, the path "/index.html" returns the absolute file * path on the server's filesystem would be served by a request for * "http://host/contextPath/index.html", where contextPath is the context * path of this {@link WebApp}. * * <p> * Notice that ZK don't count on this method to retrieve resources. If you * want to change the mapping of URI to different resources, override * {@link org.zkoss.zk.ui.sys.UiFactory#getPageDefinition} instead. */ public static String getRealPath(String path) { return webApp().getRealPath(path); } /** * 返回指定文件的mime类型 Returns the MIME type of the specified file, or null if the * MIME type is not known. The MIME type is determined by the configuration * of the Web container. * <p> * Common MIME types are "text/html" and "image/gif". */ public static String getMimeType(String file) { return webApp().getMimeType(file); } /** * 获得当前请求的session * * @return */ public static Session session() { return Sessions.getCurrent(); } /** * 设置指定key的对象到session作用域 * * @param name * @param value */ public static void setSessionAttr(String key, Object value) { session().setAttribute(key, value); } /** * 获得从当前request的session中取出指定key的对象 * * @param name * @return */ public static Object getSessionAttr(String key) { return session().getAttribute(key); } /** * 获得当前session作用域所有变量 * * @return */ @SuppressWarnings("unchecked") public static Map getSessionAttrs() { return session().getAttributes(); } /** * 获得指定名称的请求参数 * * @param name * 参数名 * @return 参数值 */ public static Object getParameter(String name) { return exec().getParameter(name); } /** * 获得所有请求参数 * * @return 参数map */ public static Object getParameterMap() { return exec().getParameterMap(); } /** * 获得指定名称的请求作用域对象 * * @param name * 请求作用域对象名称 * @return 作用域对象 */ public static Object getRequestAttr(String name) { return exec().getAttribute(name); } /** * 将指定key的变量设置的到request scope * * @param name * @param value */ public static void setRequestAttr(String name, Object value) { exec().setAttribute(name, value); } /** * 获得请求作用域所有对象 * * @param name * 请求作用域对象名称 * @return 作用域对象 */ @SuppressWarnings("unchecked") public static Map getRequestAttrs() { return exec().getAttributes(); } /** * 客户端重定向 * * After calling this method, the caller shall end the processing * immediately (by returning). All pending requests and events will be * dropped. * * Parameters: uri the URI to redirect to, or null to reload the same page */ public static void sendRedirect(String uri) { exec().sendRedirect(uri); } /** * 请求重定向 * <p> * 如果页面已加载 * * @param uri * 定向uri * @param target * 显示uri内容的目标窗口,如果target=null,则在当前窗口显示 */ public static void sendRedirect(String uri, String target) { exec().sendRedirect(uri, target); } /** * 请求转发 * <p> * 注:页面已响应客户端时, 按钮等组件监听事件不可调用该方法 * * 该方法使用范围为:客户url请求,服务器端未将响应结果响应给客户端 * * @param uri */ public static void forward(String uri) { try { exec().forward(uri); } catch (IOException e) { e.printStackTrace(); } } /** * 发送一个事件到指定组件 Sends the event to the specified component and process it * immediately. This method can only be called when processing an event. It * is OK to send event to component from another page as long as they are in * the same desktop. * <p> * 详细中文解释见<a href="http://zh.zkoss.org/doc/devguide/ch05s03.html">这里</a> */ public static void sendEvent(Component comp, Event event) { Events.sendEvent(comp, event); } /** * 发送一个事件到event关联的目标组件 Sends the event the target specified in the event. * * <p> * 详细中文解释见<a href="http://zh.zkoss.org/doc/devguide/ch05s03.html">这里</a> * <p> * Note: {@link Event#getTarget} cannot be null. */ public static void sendEvent(Event event) { Events.sendEvent(event); } /** * 发送事件到当前execution Posts an event to the current execution. * <p> * The priority of the event is assumed to be 0. Refer to * {@link #postEvent(int, Event)}. * * <p> * On the other hand, the event sent by {@link #sendEvent} is processed * immediately without posting it to the queue. * * <p> * Note: if the target of an event is not attached to the page yet, the * event is ignored silently. * <p> * 详细中文解释见<a href="http://zh.zkoss.org/doc/devguide/ch05s03.html">这里</a> * * @see #sendEvent * @see #echoEvent * @see #postEvent(int, Event) */ public static final void postEvent(Event event) { exec().postEvent(event); } /** * 发送一个命名的事件到指定target Posts an instance of {@link Event} to the current * execution. * <p> * The priority of the event is assumed to be 0. Refer to * {@link #postEvent(int, String, Component, Object)}. 详细中文解释见<a * href="http://zh.zkoss.org/doc/devguide/ch05s03.html">这里</a> * * @see #postEvent(Event) * @see #postEvent(int, String, Component, Object) */ public static final void postEvent(String name, Component target, Object data) { postEvent(0, name, target, data); } /** * Posts an event to the current execution with the specified priority. * * <p> * The posted events are processed from the higher priority to the lower * one. If two events are posted with the same priority, the earlier the * event being posted is processed earlier (first-in-first-out). * * <p> * The priority posted by posted by {@link #postEvent(Event)} is 0. * Applications shall not use the priority higher than 10,000 and lower than * -10,000 since they are reserved for component development. * * @param priority * the priority of the event. * @since 3.0.7 */ public static final void postEvent(int priority, Event event) { exec().postEvent(priority, event); } /** * Posts an instance of {@link Event} to the current execution with the * specified priority. * * <p> * The posted events are processed from the higher priority to the lower * one. If two events are posted with the same priority, the earlier the * event being posted is processed earlier (first-in-first-out). * * <p> * The priority posted by posted by {@link #postEvent(Event)} is 0. * Applications shall not use the priority higher than 10,000 and lower than * -10,000 since they are reserved for component development. * * @param priority * the priority of the event. * @since 3.0.7 */ public static final void postEvent(int priority, String name, Component target, Object data) { Events.postEvent(priority, name, target, data); } /** * * 回显事件. By echo we mean the event is fired after the client receives the AU * responses and then echoes back. In others, the event won't be execute in * the current execution. Rather, it executes after the client receives the * AU responses and then echoes back the event back. * * <p> * It is usually if you want to prompt the user before doing a long * operartion. A typical case is to open a hightlighted window to prevent * the user from clicking any button before the operation gets done. * * @since 3.0.2 * @see #sendEvent * @see #echoEvent * @param name * the event name, such as onSomething * @param target * the component to receive the event (never null). * @param data * the extra information, or null if not available. It will * become {@link Event#getData}. */ public static final void echoEvent(String name, Component target, String data) { Events.echoEvent(name, target, data); } /** * 消息提示框 * <p> * <b style="color:red;"/>注意</b>:自从zk5.0以后,默认禁用本地事件进程,见zk.xml配置文件 * <disable-event-thread>true</disable-event-thread>启用事件处理线程, * 请将true改为false * ,如果此行注释掉或者没有此行,请添加配置<disable-event-thread>false</disable * -event-thread * >当禁用事件线程时,如果您使用了messagebox的返回值作为判断的话,那么if语句内的代码永远都不会执行。这两个的区别的详细说明见 <a * href="http://sunflowers.iteye.com/blog/686243">这里<a> * * @param message * 消息内容 * @param title * 窗口标题 */ public static void showInformationbox(String message, String title) { show(message, title, Messagebox.INFORMATION); } /** * 询问提示框 * <p> * <b style="color:red;"/>注意</b>:自从zk5.0以后,默认禁用本地事件进程,见zk.xml配置文件 * <disable-event-thread>true</disable-event-thread>启用事件处理线程, * 请将true改为false * ,如果此行注释掉或者没有此行,请添加配置<disable-event-thread>false</disable * -event-thread * >当禁用事件线程时,如果您使用了messagebox的返回值作为判断的话,那么if语句内的代码永远都不会执行。这两个的区别的详细说明见 <a * href="http://sunflowers.iteye.com/blog/686243">这里<a> * * @param message * 提示内容 * @param title * 窗口标题 * @return boolean 类型,true确认,false否 */ public static boolean showQuestionbox(String message, String title) { try { int flag = Messagebox .show(message, title, Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION, Messagebox.CANCEL); return flag == Messagebox.OK; } catch (InterruptedException e) { } return false; } /** * 警告提示框 * <p> * <b style="color:red;"/>注意</b>:自从zk5.0以后,默认禁用本地事件进程,见zk.xml配置文件 * <disable-event-thread>true</disable-event-thread>启用事件处理线程, * 请将true改为false * ,如果此行注释掉或者没有此行,请添加配置<disable-event-thread>false</disable * -event-thread * >当禁用事件线程时,如果您使用了messagebox的返回值作为判断的话,那么if语句内的代码永远都不会执行。这两个的区别的详细说明见 <a * href="http://sunflowers.iteye.com/blog/686243">这里<a> * * @param message * 警告内容 * @param title * 窗口标题 */ public static void showExclamationbox(String message, String title) { show(message, title, Messagebox.EXCLAMATION); } /** * 错误提示框 * <p> * <b style="color:red;"/>注意</b>:自从zk5.0以后,默认禁用本地事件进程,见zk.xml配置文件 * <disable-event-thread>true</disable-event-thread>启用事件处理线程, * 请将true改为false * ,如果此行注释掉或者没有此行,请添加配置<disable-event-thread>false</disable * -event-thread * >当禁用事件线程时,如果您使用了messagebox的返回值作为判断的话,那么if语句内的代码永远都不会执行。这两个的区别的详细说明见 <a * href="http://sunflowers.iteye.com/blog/686243">这里<a> * * @param message * 提示内容 * @param title * 窗口标题 */ public static void showErrorbox(String message, String title) { show(message, title, Messagebox.ERROR); } /** * 显示Information提示框 * * @param message * 提示内容 * @param title * 窗口标题 * @param icon * 窗口图标:Messagebox.INFORMATION,Messagebox.QUESTION,Messagebox.EXCLAMATION * ,Messagebox.ERROR */ private static void show(String message, String title, String icon) { try { Messagebox.show(message, title, Messagebox.OK, icon); } catch (InterruptedException e) { // do nothing } } /** * 返回远端完全限定名,或者最后一次发送请求的代理 */ public static String getRemoteHost() { return exec().getRemoteHost(); } /** * * 返回请求客户端的IP地址 */ public String getRemoteAddr() { return exec().getRemoteAddr(); } /** * 返回本地请求对象(即ServletRequest),如果不可用返回null * * <p> * The returned object depends on the Web container. If it is based Java * servlet container, an instance of javax.servlet.ServletRequest is * returned. */ public static Object getNativeRequest() { return exec().getNativeRequest(); } /** * 返回本地响应对象(即ServletResponse),如果不可用返回null * * <p> * The returned object depends on the Web container. If it is based Java * servlet container, an instance of javax.servlet.ServletResponse is * returned. */ public static Object getNativeResponse() { return exec().getNativeResponse(); } /** * 开始处理 * <p> * 在浏览器左上角,会出现一个"处理中,请稍后..."提示框<br /> * 并禁用桌面上所有组件的行为,用户无法操作 * * @since 5.0 */ public static void startProcessing() { Clients.evalJavaScript("zk.startProcessing(1);"); } /** * 结束处理 * <p> * 隐藏浏览器左上角的"处理中,请稍后..."提示框 ,<br /> * 并启用用桌面上所有组件的行为,允许用户操作 * * @since 5.0 */ public static void endProcessing() { Clients.evalJavaScript("zk.endProcessing();"); } /** * 使用另外一个组件替换组件 * * @param oldc * 删除的组件 * @param newc * 添加的组件 * @exception IllegalArgumentException * 如果旧组件无父组件或无所属page * @since 3.5.2 */ public static void replaceComponent(Component oldc, Component newc) { Components.replace(oldc, newc); } /** *替换指定组件的所有子组件. 其与下面代码是等效的 * * <pre> * <code>parent.getChildren().clear(); * parent.getChildren().addAll(newChildren); * </code> * </pre> * * @since 3.5.2 */ @SuppressWarnings("unchecked") public static void replaceChildren(Component parent, Collection newChildren) { Components.replaceChildren(parent, newChildren); } /** * 获得指定组件的根节点 ,注意,可能返回其自身,当其是根节点或者为null的时候, * * @since 3.6.3 */ public static Component getRoot(Component comp) { return Components.getRoot(comp); } /** *检测node1是否是node2的祖先,如果相同返回true */ public static boolean isAncestor(Component node1, Component node2) { return Components.isAncestor(node1, node2); } /** * 删除指定组件的所有子组件 ,它与代码 <code>comp.getChildren().clear()</code>.是等效的 */ public static void removeAllChildren(Component comp) { if (comp == null || comp.getChildren().size() < 1) return; comp.getChildren().clear(); } /** * 返回组件是否真正可见的 (所有父组件均可见). * <p> * 注意: 如果comp为空,返回true.另外, 它不能检测根节点是否可见,例如 * <code>Components.isRealVisible(getParent())</code>. * * @see Component#isVisible */ public static boolean isRealVisible(Component comp) { return Components.isRealVisible(comp); } /** *判断id是否为自动生成的 * * @since 5.0.3 */ public static final boolean isAutoUuid(String id) { return org.zkoss.zk.ui.sys.ComponentsCtrl.isAutoUuid(id); } /** * 获得Configuration信息 */ public static final Object getConfiguration(String key) { return webApp().getConfiguration().getAttribute(key); } /** * 获得真正原始事件 * * @param event * @return */ public static Event getRealOrigin(ForwardEvent event) { return Events.getRealOrigin(event); } }
- ZkUtils.rar (5.1 KB)
- 下载次数: 99
发表评论
-
zkspring 3.0RC bug 修复
2010-11-19 15:46 1808zkspring 3.0RC bug 修复 ... -
【zk开发】使用Sessions.getCurrent().invalidate()时需要特别注意到问题
2010-11-15 16:25 2412Sessions.getCurrent().invali ... -
【zk开发】use和apply的区别
2010-11-15 14:03 4505use 使用一个组件类,该类必须是当前组件 ... -
【zk开发】java代码给组件添加客户端事件处理javascript
2010-11-10 10:49 1795/** *设置或删除widget的事件监听器,如 ... -
【zk开发】zk中的表单验证(优化版)
2010-11-10 10:41 2353/** * 验证表单 * <p> ... -
【zk开发】ZkUtils 1.2
2010-11-08 10:22 2747ZkUtils 是zk开发中的一些工具方法集合,将散落在 ... -
ZK 5.0.5 chm api文档
2010-11-03 10:11 5813ZK 5.0.5 chm api文档 文档在附件 ... -
ZK 5.0.5正式版发布
2010-11-02 18:24 1156ZK 5.0.5正式版发布 更新日志http: ... -
【zk开发】理解zk事件处理线程
2010-11-01 17:27 2254什么是事件处理线程(EventProcessingTh ... -
【zk开发】zkstudio安装及使用视屏
2010-10-29 16:58 2176安装视屏 http://docs.zkoss ... -
zk5.0.5可能最近两天发布
2010-10-29 13:13 1059zk5.0.5可能最近两天发布 zk5.0 ... -
【zk开发】zk注解的秘密
2010-10-28 14:26 3953The DataBinder that rea ... -
【zk开发】zk内存监控
2010-10-21 09:03 2766所用到的资源 ... -
【zk开发】如何在页面中获得composer对象
2010-10-15 15:31 2606样例: <window id=&qu ... -
【zk开发】jQuery+zk完美客户端
2010-09-14 11:11 2550(function(window) { var lin ... -
【zk开发】zk5.0.4 datebox inplace模式的bug
2010-09-08 16:24 1588zk5.0.4 datebox inplace模式 ... -
使用ZK CE版开发商业软件
2010-09-07 15:50 2447仔细读一下内容 LGPL(GNU Lesser Gene ... -
【zk开发】zk的国际化
2010-09-02 16:22 3795【zk开发】zk的国际化 一,准备资源文件 ... -
zk5.0.4 chm版API
2010-09-01 12:37 1242zk5.0.4 chm版API -
挥起马鞭,升到zk5.0.4
2010-08-31 23:22 1387由于zk5.0.4测试版已发布公开测试,正式版应该很快出 ...
相关推荐
NULL 博文链接:https://sunflowers.iteye.com/blog/805363
自己总结ZK开发工具类,里面都是一些ZK经常用到的方法
该jar是用java编写的一个操作zookeeper的工具类,能快速的将远程zk服务节点中的数据导出来,也能快速将数据上传到zk中去!
zk source code http://www.zkoss.org/javadoc/latest/zk/
zk连接工具,很好用的zk工具,zk主要用于我们知道要写一个分布式应用是非常困难的,主要原因就是局部故障。一个消息通过网络在两个节点之间传递时,网络如果发生故障,发送方并不知道接收方是否接收到了这个消息。他...
ZK框架是一个用JAVA实现的简单但是功能强大的表现层框架。它包括了一个基于Ajax的 事件驱动引擎、这也是它的最大特色。可以做到没有JavaScript,只通过ZUML(ZK User Interface Markup Language...此为zk-bin包6.5.1版本
zk从版本3.4.9升级到3.5.5详细笔记文档总结
之前的上传资源中有dubbo,这个保重包含zookeeper的安装包,以及测试demo
zk的chm版的api英文帮助文档. 本人自己制作的。 zk是台湾的一个纯ajax框架。
ZK桌面管理工具,开发的时候使用,非常便利,查看ZK里面的数据
windows环境下zk压缩包
ZK 开发手册(带目录版本),详细介绍zk的前台开发和后台数据绑定功能,是zk入门的首选.
客户端是Curator Framework,是Apache的项目,它主要的功能...可以总结Curator主要解决以下三类问题: 封装ZK Client与Server之间的连接处理; 提供了一套Fluent风格的操作API; 提供ZK各种应用场景的抽象封装;
ZK 8.0.0端参考 ZK 8.0.0组件开发的必需品 ZK 8.0.0组件引用 ZK 8.0.0配置参考 ZK 8.0.0开发人员的参考 ZK 8.0.0风格定制指南 ZK 8.0.0 ZUML参考 zk-mvvm-book
ZK源代码下载版本3.07(ZK.src)
------------------------------------------------2017-09-28 版本:ZK9211系列V2.00调试工具说明: ZK9211系列V2.00以及之后的版本场景配置工具只适配 ZK9211系列MCU版本为2.00及之后的版本;ZK9211系列现有两...
zk web框架 zk web框架 zk web框架 zk web框架 zk web框架 zk web框架 zk web框架 zk web框架 zk web框架 zk web框架 zk web框架 zk web框架 zk web框架 zk web框架 zk web框架
可根据RGB值扩展ZK主题,适用于多个不同的版本。
zookeeper Dubbo,zookeeper Dubbozookeeper Dubbozookeeper Dubbo