当前位置: 代码迷 >> Web前端 >> zk 怎么刷新父窗体
  详细解决方案

zk 怎么刷新父窗体

热度:811   发布时间:2012-11-08 08:48:11.0
zk 如何刷新父窗体
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./targetsWin"?>
<zk>
<window  title="供应商对象信息" id="targetsWin" border="normal" apply="com.lvmama.crm.web.supplier.ListTargetsAction">
<space/>
<groupbox style="border: none;">
<caption label="履行对象"></caption>
<listbox model="@{targetsWin$composer.listperformTarget}" >
<listhead>
<listheader label="对象名称"></listheader>
<listheader label="履行时间"></listheader>
<listheader label="支付信息"></listheader>
<listheader label="履行信息"></listheader>
</listhead>
<listitem self="@{each='pf'}">
<listcell label="@{pf.name}"></listcell>
<listcell><label value="@{pf.openTime}"/>~<label value="@{pf.closeTime}"/></listcell>
<listcell label="@{pf.paymentInfo}"></listcell>
<listcell label="@{pf.performInfo}"></listcell>
</listitem>
</listbox>
</groupbox>

<space/>

	<groupbox style="border: none;">
		<caption label="凭证对象"></caption>
		<listbox model="@{targetsWin$composer.supBCertificateTargetList}" >
		<listhead>
					<listheader label="名称"/>
					<listheader label="凭证类型"/>
					<listheader label="录入时间"/>
				</listhead>
				<listitem height="25px" self="@{each='sup' }">
					<listcell  label="@{sup.name }">
					</listcell>
					<listcell>
						<vbox>
						<label value="@{sup.supportFax,converter='com.lvmama.crm.utils.ConvertFax'}"></label>
						<label value="@{sup.supportDimension,converter='com.lvmama.crm.utils.ConvertEjtong'}"></label>
						</vbox>
					</listcell>
					<listcell label="@{sup.createTime }"></listcell>
					</listitem>
		</listbox>
	</groupbox>
	<space/>
	<groupbox style="border: none;">
	<caption label="结算对象"></caption>
	<listbox mold="paging" pageSize="50" model="@{targetsWin$composer.settlementTargetList}">
			<listhead>
	
				<listheader label="对象名称"/>
				<listheader label="结算周期"/>
				<listheader label="录入时间"/>
		
			</listhead>
			<listitem height="25px" self="@{each='sup' }">
				<listcell label="@{sup.name }">
			
				</listcell>
				<listcell>
					<label value="@{sup.settlementPeriod,converter='com.lvmama.crm.utils.ConverterSettlementPeriod'}"></label>
				</listcell>
				<listcell label="@{sup.createTime }"></listcell>
		
			</listitem>
		</listbox>
	</groupbox>
	<space/>
	<toolbar align="center">
		<button label="关闭窗口" width="100px" onClick="targetsWin.detach()"></button>
		</toolbar>
</window>
</zk>

?

<zk xmlns:h="http://www.w3.org/1999/xhtml"
	xmlns:zk="http://www.zkoss.org/2005/zk">
	<?component name="lvmama_pcity" macroURI="/macors/p_city.zul"?>
	<?page title="Auto Generated index.zul"?>
	<window id="supplierWindow" title="新增供应商信息" border="normal"
		apply="com.lvmama.crm.web.supplier.EditSupplierAction" >
		<space />
		<groupbox style="border: none">
			<caption label="供应商基本信息" />
			<grid>
				<columns>
					<column width="100px" align="right"></column>
					<column></column>
					<column width="100px" align="right"></column>
					<column></column>
				</columns>
				<rows>
					<row>
						<hbox>
							<label value="供应商名称:" />
							<label value="[*]" style="color:red;" />
						</hbox>
						<hbox>
						<textbox id="supplierId" visible="false"></textbox>
							<textbox width="200px;" id="supplierName"></textbox>
						</hbox>
						<hbox>
							<label value="固定电话:" />
							<label value="[*]" style="color:red;" />
						</hbox>
						<hbox>
							<textbox width="200px;" id="phone"
								popup="faxTip">
							</textbox>
						</hbox>
					</row>
					<row>
						<hbox>

							<label value="所在地址:" />
							<label value="[*]" style="color:red;" />
						</hbox>
						<hbox>
							<div>
							<textbox value="" id="macorsHiddenCity" visible="false"></textbox>
							<textbox value="false" id="macorsIsPriewPage" visible="false"></textbox>
							<lvmama_pcity id="pcity">
							</lvmama_pcity>
							<label visible="false">
							<attribute name="onCreate">
							<![CDATA[
								Component com = supplierWindow.getFellow("pcity");
								Button b = (Button) com.getFellow("MarcosCityButton");
								Events.sendEvent(new Event("onClick",b));
							         ]]>
							</attribute>
							</label>
							</div>
						</hbox>
						<hbox>
							<label value="网址:" />
						</hbox>
						<hbox>
							<textbox width="200px;" id="netAddress"></textbox>
						</hbox>
					</row>
					<row>
						<hbox>
							<label value="地址:" />
							<label value="[*]" style="color:red;" />
						</hbox>
						<hbox>
							<textbox width="200px;" id="address"></textbox>
						</hbox>
						<hbox>

							<label value="传真:" />
							<label value="[*]" style="color:red;" />
						</hbox>
						<hbox>
							<textbox width="200px;" id="fax"
								popup="faxTip">
							</textbox>
						</hbox>

					</row>
					<row>
						<hbox>
							<label value="邮编:" />
							<label value="[*]" style="color:red;" />
						</hbox>
						<hbox>
							<textbox width="200px;" id="zcode"></textbox>
						</hbox>
						<hbox>
							<label value="手机:" />
						</hbox>
						<hbox>
							<textbox width="200px;" id="mobile"></textbox>
						</hbox>
					</row>
				</rows>
			</grid>
		</groupbox>
		
		<space />
		<groupbox style="border: none;">
			<caption label="合作详情" />
			<grid>
				<columns>
					<column width="100px;" align="right"></column>
					<column></column>
					<column width="100px;" align="right"></column>
					<column></column>
				</columns>	
				<rows>
					<row>
						<hbox>
							<label value="合作时间:" />
						</hbox>
						<hbox>
							<datebox id="beginDate"></datebox>
							~
							<datebox id="endDate"></datebox>
						</hbox>
						<hbox>
							<label value="目前合作状态:" />
						</hbox>
						<hbox>
							<listbox mold="select" rows="1"
								id="compState">
							</listbox>
						</hbox>
					</row>
					<row>
						<hbox>
							<label value="合同号:" />
						</hbox>
						<hbox>
							<textbox id="contractno"></textbox>
						</hbox>
						<hbox></hbox>
						<hbox></hbox>
					</row>
					<row spans="1,3">
						<hbox>
							<label value="备注:" />
						</hbox>
						<hbox>
							<textbox id="memo" width="280px;" rows="2" 
								height="50px;">
							</textbox>
						</hbox>
					</row>
				</rows>
			</grid>
		</groupbox>
		
		<space />
		<toolbar align="center" id="toolBar">
			<button id="addSupplier" label="提交" width="100px"/><space /><button label="取消" onClick="supplierWindow.detach();" width="100px"></button>
		</toolbar>
		<space/>
		<toolbar align="center"  id="targetToolBar" visible="false">
		<button label="添加履行对象" onClick="supplierWindow$composer.forwardPerformatarget();"></button>
		<button label="添加结算对象" onClick="supplierWindow$composer.forwardSetlementtarget();"></button>
		<button label="添加凭证对象" onClick="supplierWindow$composer.forwardBcerTarget();"></button>
		<button id="search" visible="false"></button>
		</toolbar>
		<popup id="faxTip" width="300px">
			<vbox>
				<toolbarbutton label="请按如下格式输入:02169108783" style="color:red;" />
			</vbox>
		</popup>
	</window>

</zk>

?

package com.lvmama.crm.web.supplier;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lvmama.common.spring.SpringBeanProxy;

import org.apache.commons.lang.StringUtils;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.SuspendNotAllowedException;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Button;
import org.zkoss.zul.Datebox;
import org.zkoss.zul.Hbox;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Toolbar;
import org.zkoss.zul.Window;
import org.zkoss.zul.api.Listbox;

import com.lvmama.crm.dao.ComCityDAO;
import com.lvmama.crm.dao.ComProvinceDAO;
import com.lvmama.crm.po.ComCity;
import com.lvmama.crm.po.SupSupplier;
import com.lvmama.crm.service.SupplierService;
import com.lvmama.crm.utils.ZkMessage;
import com.lvmama.crm.vo.Constant;

public class EditSupplierAction extends GenericForwardComposer {
	private SupplierService supplierService;
	ComProvinceDAO provinceDao = (ComProvinceDAO) SpringBeanProxy.getBean("comProvinceDAO");
	ComCityDAO cityDao = (ComCityDAO) SpringBeanProxy.getBean("comCityDAO");
	Textbox supplierName;
	Textbox phone;
	Textbox netAddress;
	Textbox address;
	Textbox fax;
	Textbox zcode;
	Textbox mobile;
	Datebox beginDate;
	Datebox endDate;
	Listbox marcosSelectCity;
	Listbox compState;
	Textbox memo;
	Textbox contractno;
	Window supplierWindow;
	Textbox supplierId;
	Textbox macorsHiddenCity;
	Toolbar targetToolBar;
	//Textbox hiddenSupId;
	public void onClick$addSupplier(Event event) {
		// System.out.println(supplierName.getValue());

		Component com = supplierWindow.getFellow("pcity");
		Listbox lb = (Listbox) com.getFellow("marcosSelectCity");
		Listbox lb2 =(Listbox) com.getFellow("marcosSelectProvice");
		if (validate(lb2,lb)) {
			SupSupplier ss = new SupSupplier();
			ss.setAddress(address.getValue());
			ss.setBeginDate(beginDate.getValue());
			ss.setEndDate(endDate.getValue());
			if(lb.getSelectedItemApi()!=null){
				String cityId = (String) lb.getSelectedItemApi().getValue();
				ss.setCityId(cityId);
			}
			if(compState.getSelectedItemApi()!=null){
				String comSate = (String) compState.getSelectedItemApi().getValue();
				ss.setCoStatus(comSate);
			}
			ss.setFax(fax.getValue());
			ss.setMemo(memo.getValue());
			ss.setPostcode(zcode.getValue());
			ss.setSupplierName(supplierName.getValue());
			ss.setWebSite(netAddress.getValue());
			ss.setTelephone(phone.getValue());
			ss.setContractNo(contractno.getValue());
			ss.setMobile(mobile.getValue());

			if(this.supplierId.getValue()==null || "".equals(supplierId.getValue())){
			Long id = supplierService.addSupplier(ss);
				ZkMessage.showInfo("添加供应商成功");
				refreshParentWindow();
				supplierId.setValue(id.toString());
				//targetToolBar.setVisible(true);
				supplierWindow.detach();
			} else {
				Long supId = Long.valueOf(supplierId.getValue());
				ss.setSupplierId(supId);
				supplierService.updateSupplierByPk(ss);
				ZkMessage.showInfo("修改供应商成功");
				refreshParentWindow();
				supplierWindow.detach();
			}
			
		}

	}

	public void doAfterCompose(Component win) throws Exception {
		
		super.doAfterCompose(win);
		//Components.wireVariables(win, this);
		// register onXxx event listeners
		//Events.addEventListeners(win, this);
		// auto forward
		//Components.addForwards(win, this);
	
		Long supId = (Long) Executions.getCurrent().getArg().get("supid");

		if (supId != null) {
			
			Map<String,Long> param = new HashMap<String,Long>();
			param.put("supplierId", supId);
			SupSupplier ssp = supplierService.getSupplierById(param);
			supplierId.setValue(supId.toString());
			supplierName.setValue(ssp.getSupplierName());
			phone.setValue(ssp.getTelephone());
			netAddress.setValue(ssp.getWebSite());
			address.setValue(ssp.getAddress());
			fax.setValue(ssp.getFax());
			zcode.setValue(ssp.getPostcode());
			mobile.setValue(ssp.getMobile());
			beginDate.setValue(ssp.getBeginDate());
			endDate.setValue(ssp.getEndDate());
			memo.setValue(ssp.getMemo());
			if (ssp.getCityId()!=null && !"".equals(ssp.getCityId())) {
				macorsHiddenCity.setValue(ssp.getCityId());
			}
			ComCity cc = cityDao.selectByPrimaryKey(ssp.getCityId());
			List<ComCity> clist = cityDao.selectCityByProvinceId(cc.getProvinceId());
			ComCity ccselected = new ComCity();

			List<ComCity> cityList = new ArrayList<ComCity>();
		
			//cityList.add(cc1);
			List<ComCity> bindCity = new ArrayList<ComCity>();
			bindCity.add(cc);
			for (ComCity comCity : cityList) {
				if(!comCity.getCityId().equals(cc.getCityId())){
					bindCity.add(comCity);
				}
			}

			memo.setValue(ssp.getMemo());
			contractno.setValue(ssp.getContractNo());
			Listitem li = new Listitem();
			li.setLabel("请选择");
			Listitem li1 = new Listitem();
			li1.setLabel("合作中");
			li1.setValue("COOPERATION");
			Listitem li2 = new Listitem();
			li2.setLabel("合作终止");
			li2.setValue("TEMMINATED");
			
			compState.appendChild(li);
			compState.appendChild(li1);
			compState.appendChild(li2);

			if("COOPERATION".equals(ssp.getCoStatus())){
				compState.setSelectedIndex(1);
			} else if ("TEMMINATED".equals(ssp.getCoStatus())){
				compState.setSelectedIndex(2);
			}
			
		} else {
			Listitem li = new Listitem();
			li.setLabel("请选择");
			Listitem li1 = new Listitem();
			li1.setLabel("合作中");
			li1.setValue("COOPERATION");
			Listitem li2 = new Listitem();
			li2.setLabel("合作终止");
			li2.setValue("TEMMINATED");
			compState.appendChild(li);
			compState.appendChild(li1);
			compState.appendChild(li2);
		}
		
		
	}

    public void refreshParentWindow(){
   	 Component c = supplierWindow.getParent();
   	 Button b = (Button) c.getFellow("search");
   	 Events.sendEvent(new Event("onClick",b));
   	 
    }
	
	
	public boolean validate(Listbox pbox,Listbox cbox) {
		
		if (StringUtils.trim(supplierName.getValue()) == null
				|| "".equals(org.apache.commons.lang.StringUtils
						.trim(supplierName.getValue()))) {
			ZkMessage.showWarning("您必须输入供应商名称");
			supplierName.focus();
			return false;
		}  if (StringUtils.trim(phone.getValue()) == null
				|| "".equals(org.apache.commons.lang.StringUtils.trim(phone
						.getValue()))) {
			ZkMessage.showWarning("您必须输入固定电话");
			phone.focus();
			return false;
		}   if(pbox.getSelectedItemApi()==null){
			ZkMessage.showWarning("请选择省份");
			pbox.focus();
			return false;
		} else {
			if(pbox.getSelectedItemApi().getValue()==null || "".equals(pbox.getSelectedItemApi().getValue())){
				ZkMessage.showWarning("请选择省份");
				cbox.focus();
				return false;
			}
		} 
		
		if(cbox.getSelectedItemApi()==null){
			ZkMessage.showWarning("请选择城市");
			cbox.focus();
			return false;
		}  else {
			if(cbox.getSelectedItemApi().getValue()==null || "".equals(cbox.getSelectedItemApi().getValue())){
				ZkMessage.showWarning("请选择城市");
				cbox.focus();
				return false;
			}
		}
		 if (StringUtils.trim(address.getValue()) == null
				|| "".equals(org.apache.commons.lang.StringUtils.trim(address
						.getValue()))) {
			ZkMessage.showWarning("您必须输入地址");
			address.focus();
			return false;
		}  if (StringUtils.trim(fax.getValue()) == null
				|| "".equals(org.apache.commons.lang.StringUtils.trim(fax
						.getValue()))) {
			ZkMessage.showWarning("您必须输入传真号码");
			fax.focus();
			return false;
		}  if (StringUtils.trim(zcode.getValue()) == null
				|| "".equals(org.apache.commons.lang.StringUtils.trim(zcode
						.getValue()))) {
			zcode.focus();
			ZkMessage.showWarning("您必须输入邮政编码");
			return false;
		}
		return true;
	}
	
	public void forwardPerformatarget() throws SuspendNotAllowedException, InterruptedException{
		String supplierId = this.supplierId.getValue();
		Map<String,String> performtMap = new HashMap<String, String>();
		//Window parentWindow = new Window();
		//parentWindow.appendChild(b);
		Window wnd = (Window) Executions.createComponents(
				"/targets/performtarget/newperformtarget.zul",
				supplierWindow, performtMap);
		Hbox  hb = (Hbox) wnd.getFellow("supplierIdHbox");
		hb.getChildren().clear();
		Textbox t = new Textbox();
		t.setId("supplierId");
		t.setValue(supplierId);
		hb.appendChild(t);
		wnd.setClosable(true);
		wnd.setMaximizable(true);
		wnd.setWidth(Constant.getInstance().getDefaultWidth());
		wnd.doModal();
	}
	/**
	 * 跳转到凭证对象添加页面
	* @Title: forwardBcerTarget
	* @Description:
	* @param
	* @return void    返回类型
	 * @throws InterruptedException 
	 * @throws SuspendNotAllowedException 
	* @throws
	 */
	public void forwardBcerTarget() throws SuspendNotAllowedException, InterruptedException{
		String supplierId = this.supplierId.getValue();
		Map<String,String> performtMap = new HashMap<String, String>();
		
		//Window parentWindow = new Window();
		//parentWindow.appendChild(b);
		Window wnd = (Window) Executions.createComponents(
				"/targets/certificatetarget/editcertificatetarget.zul",
				supplierWindow, performtMap);
		wnd.setClosable(true);
		wnd.setMaximizable(true);
		wnd.setWidth(Constant.getInstance().getDefaultWidth());
		wnd.doModal();
	}
	
	/**
	 * 结算对象页面
	* @Title: forwardSetlementtarget
	* @Description:
	* @param
	* @return void    返回类型
	 * @throws InterruptedException 
	 * @throws SuspendNotAllowedException 
	* @throws
	 */
	public void forwardSetlementtarget() throws SuspendNotAllowedException, InterruptedException{
		
		String supplierId = this.supplierId.getValue();
		Map<String,String> performtMap = new HashMap<String, String>();
		Window wnd = (Window) Executions.createComponents(
				"/targets/settlementtarget/editsettlementtarget.zul",
				supplierWindow, performtMap);
		wnd.setClosable(true);
		wnd.setMaximizable(true);
		wnd.setWidth(Constant.getInstance().getDefaultWidth());
		wnd.doModal();
	}


	public void setSupplierService(SupplierService supplierService) {
		this.supplierService = supplierService;
	}
}

?

?

?

?

?

?

?

 public void refreshParentWindow(){
   	 Component c = supplierWindow.getParent();
   	 Button b = (Button) c.getFellow("search");
   	 Events.sendEvent(new Event("onClick",b));
   	 
    }

?

  相关解决方案