-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Here is My ZUL
<?xml version="1.0" encoding="UTF-8"?>
<zk xmlns="<a href=" http:="" www.zkoss.org="" 2005="" zul"="">http://www.zkoss.org/2005/zul" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:w="http://www.zkoss.org/2005/zk/client" xmlns:n="http://www.zkoss.org/2005/zk/native" xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd"> <window border="none" sclass="outerwin" id="insuranceCRUD" viewmodel="@id('vm') @init('com.product.webapp.admin.InsuranceCRUDVM')">
<!-- ### Bootstrap 'container-fluid' modus ### -->
<n:div class="container-fluid">
<div
form="@id('fx') @load(vm.selectedRecord) @save(vm.selectedRecord,before='saveThis')">
<n:div class="panel panel-primary">
<n:div class="clearfix panel-heading ">
<n:h4 class="panel-title pull-left">
Insurance
</n:h4>
<n:div
class="btn-group btn-group-sm pull-right">
<div sclass="pull-left"
visible="@load(fxStatus.dirty)">
<span
class="fa fa-cog fa-2x fa-spin text-danger"
tooltiptext="There are unsaved data'">
</span>
<space></space>
<space></space>
<space></space>
</div>
<h:a
class="btn btn-xs btn-default fa fa-save btn-group-btn"
onClick="@command('onAddNew')" title="Save" />
<h:a
class="btn btn-xs btn-default fa fa-arrow-left btn-group-btn"
onClick="@command('initialLoad')" title="Save and Go Back" />
<h:a
class="btn btn-xs btn-default fa fa-undo btn-group-btn"
onClick="@command('onCancel', form=fx)"
title="Cancel and Go Back" />
</n:div>
</n:div>
</n:div><!--class="panel panel-primary" -->
<n:div class="row">
<!-- ### General Box ### -->
<n:div class="col-sm-12">
<n:div class="panel panel-orange">
<n:div class="panel-heading">
General Information
</n:div>
<n:div class="panel-body">
<n:div class="col-md-3">
<n:div class="form-group">
<ox_label_required value="Code" />
<textbox id="inscode"
value="@bind(fx.code)" sclass="form-control" name="inscode"
maxlength="20" width="100%" />
</n:div>
</n:div>
<n:div class="col-md-3">
<n:div class="form-group">
<ox_label_required value="Name" />
<textbox id="insname"
value="@bind(fx.name)" sclass="form-control" name="insname"
maxlength="20" width="100%" />
</n:div>
</n:div>
<n:div class="col-md-3">
<n:div class="form-group">
<ox_label_required
value="Claims Payer ID" />
<textbox id="claimpayerid"
value="@bind(fx.payerID)"
sclass="form-control" name="claimpayerid" maxlength="20"
width="100%" />
</n:div>
</n:div>
<n:div class="col-md-3">
<n:div class="form-group">
<label
value="Eligibility Payer ID" />
<textbox id="elipayerid"
value="@bind(fx.eligibilityPayerID)" sclass="form-control"
name="elipayerid" maxlength="20" width="100%" />
</n:div>
</n:div>
</n:div>
</n:div>
</n:div>
<!-- ### End of General Box ### -->
<!-- ### Address Box ### -->
<n:div class="col-sm-6">
<n:div class="panel panel-orange">
<n:div class="panel-heading">
Address Information
</n:div>
<n:div class="panel-body">
<n:div class="form-group">
<label value="Address1" />
<textbox maxlength="25"
value="@bind(fx.address1)" sclass="form-control" width="100%" />
</n:div>
<n:div class="form-group">
<label value="Address2" />
<textbox maxlength="25"
value="@bind(fx.address2)" sclass="form-control" width="100%" />
</n:div>
<n:hr />
<n:div class="row">
<n:div class="col-md-4">
<n:div class="form-group">
<ox_label_required
value="City" />
<textbox id="City"
value="@bind(fx.city)" sclass="form-control" name="city"
maxlength="20" width="100%" />
</n:div>
</n:div>
<n:div class="col-md-4">
<n:div class="form-group">
<ox_label_required
value="State" />
<EnumDrpDown labelFormat="3"
value="@bind(fx.state)" sclass="form-control"
showDesc="false" width="100%" dropDownType="1"
EnumType="STATE" />
</n:div>
</n:div>
<n:div class="col-md-4">
<n:div class="form-group">
<ox_label_required
value="ZipCode" />
<textbox id="zipcode"
value="@bind(fx.zip)" sclass="form-control" name="zipcode"
maxlength="9" width="100%" />
</n:div>
</n:div>
</n:div>
</n:div>
</n:div>
</n:div>
<!-- ### End of Address Box ### -->
<!-- ### Contact Box ### -->
<n:div class="col-sm-6">
<n:div class="panel panel-orange">
<n:div class="panel-heading">
Contact Information
</n:div>
<n:div class="panel-body">
<n:div class="form-group">
<label value="Phone" />
<MaskBox id="Phone" checkSize="10"
format="(999) 999-9999" name="phone" width="100%"
value="@bind(fx.phone) @converter('com.product.webapp.component.MaskConverter')" />
</n:div>
<n:div class="form-group">
<label value="Fax" />
<MaskBox id="fax" checkSize="10"
value="@bind(fx.fax)" format="(999) 999-9999" name="fax"
width="100%" />
</n:div>
<n:div class="form-group">
<label value="Email" />
<textbox id="email" name="email"
value="@bind(fx.email)" maxlength="200" width="100%" />
</n:div>
</n:div>
</n:div>
</n:div>
<!-- ### End of Contact Box ### -->
</n:div>
</div><!-- form="@id('fx') @init(vm.crudForm) @load(vm.sele... -->
</n:div><!-- class="container-fluid"-->
</window>
</zk>
Here is My VM
package com.product.webapp.admin;
import java.util.HashMap;
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.zkoss.bind.annotation.BindingParam; 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.bind.annotation.Init; import org.zkoss.bind.annotation.NotifyChange; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.select.Selectors; import org.zkoss.zk.ui.select.annotation.Wire; import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zul.Messagebox; import org.zkoss.zul.Window;
import com.product.business.service.CRUDService; import com.product.domain.Insurance; import com.product.webapp.enums.RecordMode; import com.product.webapp.utilities.ExceptionHandler; import com.product.webapp.utilities.Infrastructure;
public class InsuranceCRUDVM {
static final Logger LOG = LoggerFactory.getLogger(InsuranceCRUDVM.class);
@Wire("#insuranceCRUD")
private Window win;
@WireVariable
private CRUDService CRUDService;
final HashMap<String, Object> callerArg = new HashMap<String, Object>();
private Insurance selectedRecord;
private RecordMode recordMode;
private boolean makeAsReadOnly;
private boolean onLinkOpen = false;
public RecordMode getRecordMode() {
return recordMode;
}
public void setRecordMode(RecordMode recordMode) {
this.recordMode = recordMode;
}
public boolean isMakeAsReadOnly() {
return makeAsReadOnly;
}
public void setMakeAsReadOnly(boolean makeAsReadOnly) {
this.makeAsReadOnly = makeAsReadOnly;
}
public boolean isOnLinkOpen() {
return onLinkOpen;
}
public void setOnLinkOpen(boolean onLinkOpen) {
this.onLinkOpen = onLinkOpen;
}
public Insurance getSelectedRecord() {
return selectedRecord;
}
public void setSelectedRecord(Insurance selectedRecord) {
this.selectedRecord = selectedRecord;
}
@Init
public void initSetup(@ContextParam(ContextType.VIEW) Component view,
@ExecutionArgParam("selectedRecord") Insurance insurance, @ExecutionArgParam("recordMode") RecordMode mode,
@ExecutionArgParam("container") Component container) {
Selectors.wireComponents(view, this, false);
callerArg.put("container", container);
this.selectedRecord = insurance;
if (mode.equals(RecordMode.ADD)) {
this.selectedRecord = new Insurance();
this.selectedRecord.setActive(1);
}
if (mode.equals(RecordMode.EDIT) || mode.equals(RecordMode.READ)) {
this.selectedRecord = insurance;
}
if (mode.equals(RecordMode.READ)) {
setMakeAsReadOnly(true);
}
}
@Command
@NotifyChange("selectedRecord")
public void saveThis() {
try {
CRUDService.Save(this.selectedRecord);
Infrastructure.showSuccessmessage();
} catch (Exception e) {
ExceptionHandler.handleException(e, "Referring Provider ", this.selectedRecord, ": SaveThis");
}
}
@Command
public void onCancel(@BindingParam("form") Form form) {
Messagebox.show(" d" + form);
}
}
In OnCancel, Form returns null
Here is the runnable example. Please download from here
Hi Senthil,
thanks for a working example. Everything works as expected the parameter "form" is not passed as a NULL reference. I got the actual form proxy instance:
To debug a bit better here 2 amended methods to give additional debug information:
@Command("cancel")
@NotifyChange("currentInsurance")
public void onCancel(@BindingParam("form") Insurance form) {
// Messagebox.show("Form Object " + form); Messagebox.show("cancelled REAL Object " + this.currentInsurance + " : ignored values " + form.getCode() + ", " + form.getName()); }
@Command
public void save() {
Messagebox.show("saved REAL Object " + this.currentInsurance);
}
when you previously called Messagebox.show("Form Object " + form);
it didn't output
"Form Object null" but instead it returned "Form Object form null - null" where "null - null" is the result of your toString method, which doesn't work in a proxied instance. You cannot access the instance variables directly, if you want this to work implement the toString as follows:
@Override
public String toString() {
return this.getCode() + " - " + this.getName();
}
then the form proxy can call the proxied methods getCode and getName to resolve to the value in the cache.
Robert
It works only if i remove toString method.
So you mean to say, if i remove tostring, it will work ? If then, then it is not correct way ?
Robert
My Opinion on New Form Binding is : ZK Team killed the Form Binding design in ZK 8 by disturbing too much on the domain module side.
I am sure, if i go forward on ZK 8, i will face lot of problems due to this proxy issues. And also you should have two options : Use ZK 7 style and Use ZK 8 proxy style. So that old customers will be happy.
if I use this toString implementation in your example it works:
@Override
public String toString() {
return this.getCode() + " - " + this.getName();
}
I don't know again what you are doing differently, for me the form binding works as expected.
Ok i need to wait for my other team to change the domain pojo.
you dit it in wery interesting way
Asked: 2016-01-04 20:29:54 +0800
Seen: 47 times
Last updated: Jan 08 '16
Try FormProxyObject in stead of Form
chillworld ( 2016-01-04 23:30:25 +0800 )editStill returns Null
Senthilchettyin ( 2016-01-05 02:56:54 +0800 )editit would really be helpful if you could post a runnable and isolated example. just showing the problem. Posting the whole zul file which isn't runnable at all won't make it easier to get help efficiently
cor3000 ( 2016-01-05 03:29:33 +0800 )editapart from that, please always state the ZK version.
cor3000 ( 2016-01-05 03:30:27 +0800 )edit