zk框架中常见问题的解决

 1、打开浏览器窗口常用于超链接

/**
  * 重新打开浏览器弹出页面
  * 
  * @param url 网络地址
  * @param blank;打开类型,可以是"_blank","_self"等
  */
 public void onSendRedirect(String url, String blank) {
  Executions.getCurrent().sendRedirect(url, blank);
 }

 例子:

if(reportInfo==null){
			onSendRedirect(
					"/designer.zul","_self");	
		}else{
			Executions.getCurrent().sendRedirect(
					"/designer.zul?reporturl=" + reportInfo.getDir() + "/"
							+ reportInfo.getFileName(), "_self");
		}

  2、主窗体与弹出子窗体之间传值刷新问题

  主窗体java代码

public class ListBusinessModel extends Window implements AfterCompose {
	
	private static final long serialVersionUID = 1L;
	public void afterCompose() {
		initPage();	

	}
	
	/**
	 * 初始化问题
	 */
	public void initPage() {
		
	}

	/**
	 * 添加函数
	 */
	public void add() {
		try {
			AddBusinessModel wnd = (AddBusinessModel) Executions.createComponents(
					"/pages/systemManage/business/addBusinessModel.zul",
					ListBusinessModel.this, null);
			wnd.doModal();
		} catch (SuspendNotAllowedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * 修改函数
	 */
	public void edit() {
		try {
			Treeitem item = ((Tree)getFellow("tree")).getSelectedItem();
			if(item==null||item.getParentItem()==null){
				Message.showInfo("请选择一个业务模型.");
			}else{				
				BusinessModel model = irbm.getBusiModel(item.getId());
				Map map = new HashMap();
				map.put("bmodel", model);
				map.put("dsId", item.getParentItem().getId());
				EditBusinessModel wnd = (EditBusinessModel) Executions.createComponents(
						"/pages/systemManage/business/editBusinessModel.zul",
						ListBusinessModel.this, map);
				wnd.doModal();
			}			
			
		}catch (SuspendNotAllowedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
	}
}

 

 添加窗体代码,注意如何刷新主窗体

public class AddBusinessModel extends Window implements AfterCompose {
	
	private static final long serialVersionUID = 1L;

	/* (non-Javadoc)
	 * @see org.zkoss.zk.ui.ext.AfterCompose#afterCompose()
	 */
	public void afterCompose() {
		initPage();

	}
	/**
	 * 初始化函数
	 */
	public void initPage() {
	}
	
	/**
	 * 保存函数
	 */
	public void save() {
	//do something	
		this.refresh();
		this.detach();
	}
	/**
	 * 刷新函数
	 */
	public void refresh() {
		ListBusinessModel bmWn = (ListBusinessModel)this.getParent();
		bmWn.initPage();
	}
}

  修改窗体,观察如何传值和接受值

public class EditBusinessModel extends Window implements AfterCompose {
	
	private static final long serialVersionUID = 1L;
	//参数的获取方法
	String dsId = (String)Executions.getCurrent().getArg().get("dsId");
	BusinessModel model = (BusinessModel)Executions.getCurrent().getArg().get("bmodel");

	public void afterCompose() {
	//do something
	}
	/**
	 * 保存
	 */
	public void save() {
		//do something
		this.refresh();
		this.detach();
	}
	/**
	 * 刷新
	 */
	public void refresh() {
		ListBusinessModel bmWn = (ListBusinessModel)this.getParent();
		bmWn.initPage();
	}
}

  

3.通过设置include对象的src属性给hostAdd.zul页面传递参数。

设置要传入的参数例如:
m_includeHost
   .setSrc("/pages/hostMan/hostAdd.zul
       ?mode=wizard&hostGroupType=monitorhostgroup");
在hostAdd.zul后台类中获取参数mode例如:
String m_mode = Executions.getCurrent().getParameter("mode");

4. hostAdd.zul是通过include被加载进来的,给该页面传递一个对象

例如:
m_includeHost.setDynamicProperty("wizardObject", this);
在hostAdd.zul后台类读取传入的对象例如:
WebsiteWizardUi m_wizardObject = (WebsiteWizardUi) Executions.getCurrent()
  .getAttribute("wizardObject");

5.给弹出窗口设置参数

例如:
Map<String, String> arg = new HashMap<String, String>();
arg.put("hostGroupId", hostGroupId);
arg.put("hostGroupType", hostGroupType);
Window wnd = (Window) Executions.createComponents("/pages/hostMan/hostAdd.zul", null, arg);
wnd.doModal();
窗口弹出后读取参数需要写在渲染方法public void afterCompose() {}中例如:
hostGroupId = (String) Executions.getCurrent().getArg().get("hostGroupId");
 Window viewWin = (Window) Executions.createComponents(
     "pages/reportView.zul", IndexWin.this, argMap);
java类中
Map argMap = this.getDesktop().getExecution().getArg();

 6、局部刷新问题

Include geronimoInc = (Include) Path
				.getComponent("//mainPage/geronimoMainWnd/geronimoInc");
		String rootPath = Paths.getPagePath();
		Date time = new Date();
		geronimoInc.setSrc(rootPath
				+ "/pages/JEEService/databaseManager/databaseList.zul?"
				+ time.getTime());

 7.添加监听方法 

方法1

this.addEventListener("onOK", new EventListener() {
public void onEvent(Event e){
      matchBeforAdd();     
}});

 

方法2

使用org.zkoss.zk.ui.Component接口中的addEventListene和removeEventListener方法
来动态地添加或移除事件监听器。
如下所示,动态添加的事件监听器必须实现org.zkoss.zk.ui.event.EventListener接口。
 void init(Component comp){
  ...
  comp.addEventListener("onClick", new MyListener());
  ...
 }
 class MyListener implements org.zkoss.zk.ui.event.EventListener {
   public void onEvent(Event event) throws UiException{     
  //事件处理    
 }
} 

 8、转到另一个servlet

例如:
Executions.sendRedirect("/welcome");
在web.xml里面定义该serverlet
例如:
<servlet>
  <servlet-name>welcome</servlet-name>
    <servlet-class>
      com.cvicse.inforguard.common.context.WelcomeServlet
    </servlet-class>
   </servlet>
 <servlet-mapping>
 <servlet-name>welcome</servlet-name>
 <url-pattern>/welcome</url-pattern>
 </servlet-mapping>
com.cvicse.inforguard.common.context.WelcomeServlet类定义为:
 
/*
 * 把请求导向首页面index.zul
 */
public class WelcomeServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
 if (req != null
   && req.getSession() != null
   && req.getSession().getAttribute(AuthenticationFilter.USER_KEY) != null
   && req.getSession().getAttribute(AuthenticationFilter.USER_KEY).equals("anonymity")){
    req.getSession().removeAttribute(AuthenticationFilter.USER_KEY);   
 }
  RequestDispatcher rd = req.getRequestDispatcher("/pages/index.zul");
  rd.forward(req, res);
 }
}

9.两个并列组件间的空隙

<vbox spacing="5em">     表示两个要排列的组建之间的间隙
    <textbox width="100px"/>
   <datebox width="100px"/>
</vbox>

10.Hbox/Vbox设置内部组件占位

<hbox width="100%" widths="10%,20%,30%,40%"> widths用逗号隔开并列的各组件占的宽度
<vbox height="100%" heights="10%,20%,30%,40%"> heights用逗号隔开并排的各组件占的高度度

11.borderlayout中子组件自适应大小

<borderlayout>组件flex属性设置为"true" 则该组件下子组件可自适应大小

12.grid组件设置

grid组件可以通过设置span属性使某一个格子占多列。 如:设置span="2,1,1",grid为四列,
则此行第一格子占两列。

13.listbox组件设置高度用rows比height好

listbox用设置rows属性来设置组件的高度可以避免listbox渲染时的闪动

14.转换字符编码格式的方法

String childtype = new String(Executions.getCurrent().getParameter("type")
           .getBytes("UTF-8"), "GBK");
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值