Wednesday, 7 August 2013

ZK Quick InputBox

Just to get String input before do some process. For example, we will normally ask the reason to delete any record.

<?xml version="1.0" encoding="UTF-8"?>
<window id="inputstringbox" title="@load(vm.screenTitle)"
width="auto" height="auto" border="normal" minimizable="false"
sclass="mymodal" mode="modal" maximizable="false" closable="true"
action="hide: slideUp" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('com.product.webapp.component.InputStringBoxVM')">
<ftextbox id="txtDescription" rows="4" cols="70"
value="@bind(vm.input)" />
<separator />
<div align="center">
<fbutton label="Ok" onClick="@command('onOk')" />
<fbutton label="Cancel" onClick="@command('closeThis')" />

package com.product.webapp.component;

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

import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.bind.annotation.ExecutionArgParam;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Window;

import com.product.webapp.utilities.GlobalCommandValues;
import com.product.webapp.utilities.Libs;
import com.product.webapp.utilities.ShowWindow;
import com.product.webapp.utilities.ValidationMessage;

public class InputStringBoxVM {

private Window win;
private String input;
private String validateMessage;
private String screenTitle;

public String getInput() {
return input;

public String getScreenTitle() {
return screenTitle;

public void setScreenTitle(String screenTitle) {
this.screenTitle = screenTitle;

public String getValidateMessage() {
return validateMessage;

public void setValidateMessage(String validateMessage) {
this.validateMessage = validateMessage;

public void setInput(String input) {
this.input = input;

public void initSetup(@ContextParam(ContextType.VIEW) Component view,
@ExecutionArgParam("validateMessage") String validateMessage,
@ExecutionArgParam("screenTitle") String screenTitle) {
Selectors.wireComponents(view, this, false);
this.validateMessage = validateMessage;
this.screenTitle = screenTitle;

@SuppressWarnings({ "unchecked", "rawtypes" })
public void onOk() {
if (IsValidEntry() == false) {
} else {
Map args = new HashMap();
args.put("input", this.input);
BindUtils.postGlobalCommand(null, null,
GlobalCommandValues.InputStringEntered, args);

public boolean IsValidEntry() {

List<ValidationMessage> vList = new ArrayList<ValidationMessage>();

if (Libs.isNotEmpty(this.input) == false) {
vList.add(new ValidationMessage(this.validateMessage));

if (vList.size() > 0) {
return false;
} else
return true;

public void closeThis() {

public static void showInputBox(String title, String validateMessage,
Window callingFrom) {
final HashMap<String, Object> map = new HashMap<String, Object>();
map.put("screenTitle", title);
map.put("validateMessage", validateMessage);
if (callingFrom.hasFellow("inputstringbox") == false) {
null, map);

public void onResetPassword() {
"Pleas Enter the reason to reset the password.", win);

public void resetPassword() {
// do something here

No comments:

Post a Comment

Passing Parameter between two files using MVVM

This examples shows how to pass parameter between two zul screens. In this example, we are passing some parameters from the parent vm to...