Suggested case list:
Using timer to refresh a grid
383guest172.69.33.12125nk0uiMay 7, 2020 7:23:47 AMlinkuser model to move item to another listbox
120guest162.158.193.148d0n3krApr 2, 2020 5:28:28 AMlinkDisabled list item row passed to VM-1981
296fatih123160.83.36.13025nk0uiFeb 13, 2018 4:25:44 PMlinkDisabled list item row passed to VM-1981
295fatih123160.83.36.13025nk0uiFeb 13, 2018 4:25:16 PMlinkDisabled list item row passed to VM-1981
294fatih123160.83.36.13225nk0uiFeb 13, 2018 3:30:44 PMlinkgrid sample with ListModel/RowRenderer
816guest80.82.2.1312vah9ajFeb 21, 2017 11:42:21 AMlinkgrid sample with ListModel/RowRenderer
809guest175.98.113.1622vah9ajJan 26, 2017 9:19:33 AMlinkgrid sample with ListModel/RowRenderer
196guest79.185.142.402vah9ajApr 26, 2014 10:53:57 PMlinkgrid sample with ListModel/RowRenderer
195guest79.185.142.402vah9ajApr 26, 2014 10:53:54 PMlinkgrid sample with ListModel/RowRenderer
194guest79.185.142.402vah9ajApr 26, 2014 10:53:51 PMlinkgrid sample with ListModel/RowRenderer
193guest79.185.142.402vah9ajApr 26, 2014 10:53:48 PMlinkgrid sample with ListModel/RowRenderer
192guest79.185.142.402vah9ajApr 26, 2014 10:53:44 PMlinkgrid sample with ListModel/RowRenderer
191guest79.185.142.402vah9ajApr 26, 2014 10:53:40 PMlinkHierarchy table without using ZK PE/EE
1aaknai151.28.135.2131s871daJul 29, 2013 11:02:46 PMlinkgrid sample with ListModel/RowRenderer
128aaknai151.28.135.2132vah9ajJul 29, 2013 7:20:00 PMlinkuser model to move item to another listbox
1TonyQ114.25.109.94d0n3krApr 21, 2012 10:43:27 AMlinkUsing timer to refresh a grid
1TonyQ220.133.44.3725nk0uiFeb 17, 2012 3:17:34 AMlinkFire a event from child iframe
1TonyQ220.133.44.372eupjotFeb 3, 2012 5:04:52 AMlinkTextbox input restriction sample
1TonyQ72.21.245.2431b3nlr0Dec 20, 2011 10:09:10 AMlinkTest web core taglib in ZUL
1TonyQ198.203.175.175ofqkemDec 17, 2011 3:36:08 AMlinkLatest 10 Fiddles :
Another new ZK fiddle
1guest172.69.33.235f88dquJan 9, 2025 8:48:48 AMlinkEvent keys java
21guest172.70.216.118vlu4qqJan 8, 2025 2:44:03 PMlinkEvent keys java
20guest172.70.57.218vlu4qqJan 8, 2025 2:21:32 PMlinkEvent keys java
19guest172.70.57.219vlu4qqJan 8, 2025 2:10:39 PMlinktestSplit
7guest172.69.195.1612fql387Jan 8, 2025 9:33:17 AMlinkDate Range
55guest172.71.186.1971rd7sdhJan 8, 2025 7:03:30 AMlinkmenupopup example
1guest172.70.216.166d9vcfJan 7, 2025 12:39:10 PMlinknested grid detail mvvm
1guest172.71.158.237puu6hlJan 7, 2025 3:28:45 AMlinknested grid detail mvvm
1guest172.71.158.2373ot90vpJan 7, 2025 3:26:38 AMlinknested grid detail mvvm
28guest172.71.158.23635slue2Jan 7, 2025 3:24:59 AMlinkEvent keys java
20guest172.70.57.218vlu4qqJan 8, 2025 2:21:32 PMlinkresources
index.zulzul<zk>
<window border="none" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('pkg$.controllerVM')">
<div style="display: flex; margin-bottom: 10px;">
<div sclass="works-div-dparam-col1">
<label value="code"></label>
</div>
<div sclass="works-div-dparam-col2">
<textbox value="@bind(vm.beanMap.code)" width="100%" constraint="no empty" />
</div>
</div>
<div style="display: flex; margin-bottom: 10px;">
<div sclass="works-div-dparam-col1">
<label value="name"></label>
</div>
<div sclass="works-div-dparam-col2">
<textbox value="@bind(vm.beanMap.name)" width="100%" constraint="no empty" />
</div>
</div>
<div style="display: flex; margin-bottom: 10px;">
<div sclass="works-div-dparam-col1">
<label value="address"></label>
</div>
<div sclass="works-div-dparam-col2">
<textbox value="@bind(vm.beanMap.address)" width="100%" constraint="no empty" />
</div>
</div>
<div style="display: flex; margin-bottom: 10px;">
<div sclass="works-div-dparam-col1">
<label value="phone"></label>
</div>
<div sclass="works-div-dparam-col2">
<textbox value="@bind(vm.beanMap.phone)" width="100%" constraint="no empty" />
</div>
</div>
<div style="display: flex; margin-bottom: 10px;">
<div sclass="works-div-dparam-col1">
<label value="phone"></label>
</div>
<div sclass="works-div-dparam-col2">
<textbox value="@bind(vm.beanMap.phone)" width="100%" constraint="no empty" />
</div>
</div>
</window>
</zk>
TestComposer.javajava
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Div;
import org.zkoss.zul.Textbox;
public class TestComposer extends SelectorComposer<Div>{
@Override
public void doAfterCompose(Div comp) throws Exception {
super.doAfterCompose(comp);
//on root > affect every location of the page
comp.setCtrlKeys("^v");
comp.addEventListener(Events.ON_CTRL_KEY, new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
Clients.log("do something at page level");
}
});
// on a child > affected only when child has focus
Textbox tb = new Textbox();
tb.setParent(comp);
tb.setCtrlKeys("^c");
tb.addEventListener(Events.ON_CTRL_KEY, new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
Clients.log("do something at comp level");
}
});
}
}
controllerVM.javajavaimport org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import org.zkoss.zul.*;
import org.zkoss.bind.annotation.AfterCompose;
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.Executions;
import org.zkoss.zk.ui.select.Selectors;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Bandbox;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Toolbarbutton;
import org.zkoss.zul.Window;
import java.util.Map;
import java.util.HashMap;
public class controllerVM {
private BeanObject beanMap = new BeanObject();
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) throws Exception {
Selectors.wireEventListeners(view, this);
}
@Init
public void init() throws Exception {
beanMap.put("code","0001");
beanMap.put("name","caciopee");
beanMap.put("address","rabat");
BeanObject bank = new BeanObject();
bank.put("name","sgmb");
bank.put("city","rabat");
beanMap.put("bank",bank);
}
public BeanObject getBeanMap() {
return beanMap;
}
public void setBeanMap(BeanObject beanMap) {
this.beanMap = beanMap;
}
}
BeanObject.javajava
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
* @author Achraf
*/
public class BeanObject implements Map, Serializable {
private static final long serialVersionUID = 5035002165118813347L;
public static final String WORKS_BEAN_ACTION = "worksBeanAction";
public static final String WORKS_BEAN_IS_DUPLICATED = "worksBeanIsDuplicated";
public static final String WORKS_BEAN_IS_NEW = "worksBeanIsNew";
public static final String WORKS_BEAN_IS_UPDATED = "worksBeanIsUpdated";
public static final String WORKS_BEAN_IS_CLONED = "worksBeanIsCloned";
public static final String WORKS_BEAN_IS_CLONE = "worksBeanIsClone";
public static final String WORKS_BEAN_IS_DELETED = "worksBeanIsDeleted";
public static final String WORKS_CLONE_SOURCE = "worksCloneSource";
private HashMap<String, Object> beanMap = new HashMap<>();
public static final int MIN_LEVEL = 1;
public static final String ATTRIBUTE_ID = "id";
private static final String PARAMETRE_ID = "parametreId";
private static final String WORKS_CLONE_SOURCE_ID = "worksCloneSource";
private static final String TO_DELETE = "toDelete";
private static final String TO_DELETE_COMPOSANT = "toDeleteComposant";
private static final String ATTRIBUTS_ALREADY_PARSED = "attributsAlreadyParsed";
private static final String NEW_WORKS_INSTANCE = "newWorksInstance";
private static final String DOT = ".";
private int convertLevel = MIN_LEVEL;
private boolean passed = false;
private boolean changed = false;
private boolean moved = false;
private transient Set<BeanObject> parents = new HashSet<>();
private transient Map<String, BeanObject> parentsRel = new HashMap<>();
private Map<String, Integer> attributsVersion = new HashMap<>();
private Map<String, Long> attributsIds = new HashMap<>();
private transient Map<String, Object> oldValues = new HashMap<>();
private transient Set<BeanObject> boNotified = new HashSet<>();
private Set<String> updatedKey = new HashSet<>();
private transient Map<String, BeanObject> deletedChilds = new HashMap<>(); // String = relationKey
public BeanObject() {
this.beanMap = new HashMap<>();
}
public BeanObject(Object bean) {
this();
}
public BeanObject(Object bean, boolean skipUnsupportedTypes) {
this();
}
public BeanObject(Object bean, int level) {
this();
convertLevel = level;
}
public BeanObject(Object bean, int level, Set<String> fieldsToIgnore) {
this();
convertLevel = level;
}
public BeanObject(Object bean, String[] filters) {
this(bean);
}
public Set<String> getUpdatedKey() {
if (updatedKey == null) {
updatedKey = new HashSet<>();
}
return updatedKey;
}
public void setUpdatedKey(Set<String> updatedKey) {
this.updatedKey = updatedKey;
}
/**
* moukha
*/
@Override
public String toString() {
if (this.beanMap.containsKey("beanToString")) {
return getString("beanToString");
}
return "";
}
private boolean isSupportedType(Object valueObject) {
return !(valueObject instanceof Map || valueObject.getClass().isPrimitive());
}
/*
* @param key @param value
*/
public void put(String key, Object value) {
put(key, value, true);
}
public void put(String key, Object value, boolean changed) {
if (this.beanMap.containsKey(key)) {
Object oldValue = this.beanMap.get(key);
if ((oldValue != null && !oldValue.equals(value)) || (oldValue == null && value != null)) {
if (checkNotEqualsNumber(value, oldValue) && checkNotEqualsDate(value, oldValue) && checkNotEqualsDP(value, oldValue)) {
if (changed) {
getUpdatedKey().add(key);
}
if (changed) {
}
}
}
if (oldValue instanceof BeanObject) {
}
} else if (value != null) {
if (changed) {
getUpdatedKey().add(key);
}
}
if (value instanceof BeanObject || TO_DELETE.equals(key)) {
}
if (value instanceof ArrayList) {
// TODO te be verify (first load changed !!)
this.put(key, (ArrayList) value, changed);
} else if (value instanceof GenieList) {
// TODO te be verify (first load changed !!)
this.put(key, (GenieList) value, changed);
} else {
this.beanMap.put(key, value);
}
}
private boolean checkNotEqualsDP(Object value, Object oldValue) {
return !(oldValue instanceof BeanObject) || !(value instanceof String) || !(value.equals(((BeanObject) oldValue).get("id")));
}
private boolean checkNotEqualsNumber(Object value, Object oldValue) {
return !(oldValue instanceof Number) || !(value instanceof Number) || (new BigDecimal("" + oldValue).compareTo(new BigDecimal("" + value)) != 0);
}
private boolean checkNotEqualsDate(Object value, Object oldValue) {
return !(oldValue instanceof Date) || !(value instanceof Date) || (((Date) oldValue).getTime() != ((Date) value).getTime());
}
/**
* @param key
* @param value
*/
public void put(String key, List<BeanObject> value) {
put(key, value, true);
}
public void put(String key, List<BeanObject> value, boolean changed) {
if (value instanceof ArrayList) {
// TODO te be verify (first load changed !!)
GenieList list = null;
if (value instanceof GenieList) {
list = (GenieList) value;
// si le beanObject est {changed} alors on garde {changed a true} sinon on recupere l'infos {changed} de la liste
if (!changed) {
changed = ((GenieList) value).isChanged();
}
} else {
list = new GenieList((ArrayList) value);
}
list.addParent(key, this);
beanMap.put(key, list);
if (changed) {
} else {
this.getUpdatedKey().remove(key);
}
} else if (value instanceof GenieList) {
GenieList list = (GenieList) value;
if (!changed) {
changed = list.isChanged();
}
list.addParent(key, this);
beanMap.put(key, list);
if (changed) {
} else {
this.getUpdatedKey().remove(key);
}
} else {
beanMap.put(key, value);
}
}
/**
* @param key
* @param value
*/
public void put(String key, BeanObject value) {
put(key, value, true);
}
/**
* @param key
* @param value
* @param changed
*/
public void put(String key, BeanObject value, boolean changed) {
if (value != null) {
value.addParent(key, this);
}
if (this.beanMap.containsKey(key)) {
Object oldValue = this.beanMap.get(key);
if (oldValue != null && oldValue instanceof BeanObject && oldValue != value) {
}
}
if (changed) {
getUpdatedKey().add(key);
}
beanMap.put(key, value);
}
/**
*
* @param bean
* @author Youssef ELKASSIB
*/
public void copy(BeanObject bean) {
if (bean != null) {
this.beanMap.putAll(bean.beanMap);
}
}
/**
*
* @param key
* @return
* @author Youssef ELKASSIB
*/
public Object remove(String key) {
return remove(key, true);
}
public Object remove(String key, boolean changed) {
return this.beanMap.remove(key);
}
/**
* @param key
* @return
*/
public Object get(String key) {
return beanMap.get(key);
}
public HashMap<String, Object> getMap() {
return beanMap;
}
public Set<String> getAttributes() {
return beanMap.keySet();
}
/**
* @author Adil Moukkadem
* @param path
* @param arg1
* @description setting value on specified path
*/
public void fillPathValue(String path, Object arg1) throws Exception {
BeanObject map = this;
String[] split = path.split("\\.");
if (split.length == 1) {
put(path, arg1);
} else {
for (int i = 0; i < split.length - 1; i++) {
if (map.get(split[i]) == null) {
BeanObject bean = new BeanObject();
map.put(split[i], bean);
map = bean;
} else if (map.get(split[i]) instanceof BeanObject) {
BeanObject bean = (BeanObject) map.get(split[i]);
map = bean;
} else {
throw new Exception("key " + split[i] + " from Path: " + path + " must be a BeanObject ...");
}
}
map.put(split[split.length - 1], arg1);
}
// return map;
}
public void setProperty(String path, Object arg1) throws Exception {
fillPathValue(path, arg1);
}
public void addProperty(String path, Object arg1) throws Exception {
fillPathValue(path, arg1);
}
public void putProperty(String path, Object arg1) throws Exception {
fillPathValue(path, arg1);
}
public void setProperty(String path, Object arg1, boolean updateKeys) throws Exception {
if (updateKeys) {
fillPathValue(path, arg1);
} else {
fillPathValueWithoutChangeUpdatedKey(path, arg1);
}
}
public void fillPathValueWithoutChangeUpdatedKey(String path, Object arg1) throws Exception {
BeanObject map = this;
String[] split = path.split("\\.");
if (split.length == 1) {
this.getMap().put(path, arg1);
} else {
for (int i = 0; i < split.length - 1; i++) {
if (map.get(split[i]) == null) {
BeanObject bean = new BeanObject();
bean.getMap().put(split[i], bean);
map = bean;
} else if (map.get(split[i]) instanceof BeanObject) {
BeanObject bean = (BeanObject) map.get(split[i]);
map = bean;
} else {
throw new Exception("key " + split[i] + " from Path: " + path + " must be a BeanObject ...");
}
}
map.getMap().put(split[split.length - 1], arg1);
}
// return map;
}
/**
* @author Adil Moukkadem
* @param path
* @return object
* @throws Exception
* @description get value of specified path
*/
@Deprecated
public Object getValueOfPath(String path) throws Exception {
if (path == null || path.equals("")) {
return null;
}
boolean hasPathList = false;
if (path.contains("[")) {
hasPathList = true;
}
BeanObject map = this;
String[] split = path.split("\\.");
if (split.length == 1) {
return hasPathList && path.contains("[") ? getBeanFromList(map, path) : this.beanMap.get(path);
} else {
String part = null;
for (int i = 0; i < split.length - 1; i++) {
part = split[i];
if (hasPathList && part.contains("[")) {
map = getBeanFromList(map, part);
} else if (map != null && map.get(part) != null) {
if (map.get(part) instanceof BeanObject) {
BeanObject bean = (BeanObject) map.get(part);
map = bean;
} else if (map.get(part) instanceof List) {
return map.get(part); // return List
} else {
throw new Exception("key " + part + " from Path: " + path + " must be a BeanObject or List ...");
}
} else {
return null;
}
}
if (hasPathList && split[split.length - 1].contains("[")) {
return getBeanFromList(map, split[split.length - 1]);
} else if (map != null) {
return map.get(split[split.length - 1]);
} else {
return null;
}
// return hasPathList && split[split.length - 1].contains("[") ?
// getBeanFromList(map, split[split.length - 1]) :
// map.get(split[split.length - 1]);
}
}
public String getMultipleKeyOfPath(String path) throws Exception {
BeanObject map = this;
String[] split = path.split("\\.");
if (split.length == 1) {
return (map.get(path) instanceof List) ? path : null;
} else {
String part = null;
for (int i = 0; i < split.length - 1; i++) {
part = split[i];
if (map != null && map.get(part) != null) {
if (map.get(part) instanceof BeanObject) {
BeanObject bean = (BeanObject) map.get(part);
map = bean;
} else if (map.get(part) instanceof List) {
return part; // return List
}
}
}
}
return null;
}
private BeanObject getBeanFromList(BeanObject beanObject, String part) throws Exception {
BeanObject bean = null;
String path = part.replaceAll("\\[.*\\]", "");
if (beanObject != null && beanObject.getValueOfPath(path) instanceof Collection<?> && (Collection) beanObject.getValueOfPath(path) != null && !((Collection) beanObject.getValueOfPath(path)).isEmpty()) {
List<BeanObject> listBeans = (List<BeanObject>) beanObject.getValueOfPath(path);
String lstIdx = part.substring(part.indexOf("[") + 1, part.indexOf("]"));
Integer indexElement = new Integer(lstIdx);
bean = listBeans.get(indexElement);
}
return bean;
}
/**
* @author Adil Moukkadem
* @param path
* @return Boolean
* @description check if path exist or not
*/
public Boolean containsPath(String path) {
if (path == null) {
return false;
}
BeanObject map = this;
String[] split = path.split("\\.");
if (split.length == 1) {
return this.containsKey(path);
} else {
for (int i = 0; i < split.length; i++) {
if (map == null || !map.containsKey(split[i])) {
return false;
}
if (map.get(split[i]) instanceof BeanObject) {
map = (BeanObject) map.get(split[i]);
} else {
map = null;
}
}
}
return true;
}
/**
* Override MAP Methods
*
*/
public void clear() {
this.beanMap.clear();
}
public boolean containsKey(Object key) {
return this.beanMap.containsKey(key);
}
public boolean containsValue(Object value) {
return this.beanMap.containsValue(value);
}
public Set entrySet() {
return this.beanMap.entrySet();
}
public Object get(Object key) {
return this.beanMap.get(key);
}
public BeanObject getBo(String key) {
if (key == null) {
return null;
}
BeanObject value = null;
Object classTypeObj = null;
try {
classTypeObj = this.getProperty(key);
value = (BeanObject) classTypeObj;
} catch (Exception e) {
alert("BeanObject", classTypeObj, key);
}
return value;
}
public BeanObject getBo(String key, boolean create) {
if (key == null) {
return null;
}
BeanObject value = getBo(key);
if (value == null && create) {
value = new BeanObject();
put(key, value);
}
return value;
}
public BeanObject getDp(String key) {
return null;
}
public String getDpId(String key) {
return null;
}
public boolean isEmpty() {
return this.beanMap.isEmpty();
}
public Set<String> keySet() {
return this.beanMap.keySet();
}
public void putAll(Map m) {
this.beanMap.putAll(m);
this.getUpdatedKey().addAll(m.keySet());
}
public Object remove(Object key) {
return remove(key, true);
}
public Object remove(Object key, boolean changed) {
return this.beanMap.remove(key);
}
public int size() {
return this.beanMap.size();
}
public Collection values() {
return this.beanMap.values();
}
public Object put(Object key, Object value) {
if (value instanceof BeanObject || value instanceof List || TO_DELETE.equals(key)) {
}
return this.beanMap.put(key.toString(), value);
}
/**
* END MAP Methods
*/
public void initUpdatedKeys() {
passed = true;
for (Object value : this.beanMap.values()) {
if (value instanceof BeanObject && !((BeanObject) value).passed) {
((BeanObject) value).initUpdatedKeys();
} else if (value instanceof Collection) {
for (Object object : (Collection) value) {
if (object instanceof BeanObject && !((BeanObject) object).passed) {
((BeanObject) object).initUpdatedKeys();
}
}
}
}
this.getUpdatedKey().clear();
passed = false;
}
/**
* @author azamani @ Specific getters WRKS-503
* @param classTypeObj
* @param mapping
*/
private void alert(String type, Object classTypeObj, String mapping) {
if (classTypeObj != null) {
} else {
}
}
public String getString(String mapping) {
String value = null;
Object classTypeObj = null;
try {
classTypeObj = this.getProperty(mapping);
value = (String) classTypeObj;
} catch (Exception e) {
alert("String", classTypeObj, mapping);
}
return value;
}
public String getString(String mapping, String defaultValue) {
String value = getString(mapping);
if (value == null) {
value = defaultValue;
}
return value;
}
public Double getDouble(String mapping) {
Number number = getNumber(mapping);
if (number != null) {
return number.doubleValue();
}
return null;
}
public byte[] getByteArray(String mapping) {
byte[] value = null;
Object classTypeObj = null;
try {
classTypeObj = this.getProperty(mapping);
value = (byte[]) classTypeObj;
} catch (Exception e) {
alert("byte[]", classTypeObj, mapping);
}
return value;
}
public Long getLong(String mapping) {
Number number = getNumber(mapping);
if (number != null) {
return number.longValue();
}
return null;
}
public Number getNumber(String mapping) {
Number value = null;
Object classTypeObj = null;
try {
classTypeObj = this.getProperty(mapping);
value = (Number) classTypeObj;
} catch (Exception e) {
alert("Number", classTypeObj, mapping);
}
return value;
}
public Integer getInteger(String mapping) {
Number number = getNumber(mapping);
if (number != null) {
return number.intValue();
}
return null;
}
public Integer getInteger(String mapping, int defaultValue) {
Number number = getNumber(mapping);
if (number == null) {
return defaultValue;
}
return number.intValue();
}
public BigDecimal getBigDecimal(String mapping) {
BigDecimal value = null;
Object classTypeObj = null;
try {
classTypeObj = this.getProperty(mapping);
value = (BigDecimal) classTypeObj;
} catch (Exception e) {
alert("BigDecimal", classTypeObj, mapping);
}
return value;
}
public Boolean getBoolean(String mapping) {
Boolean value = null;
Object classTypeObj = null;
try {
classTypeObj = this.getProperty(mapping);
value = (Boolean) classTypeObj;
} catch (Exception e) {
alert("Boolean", classTypeObj, mapping);
}
return value;
}
public Boolean getBoolean(String mapping, boolean defaultValue) {
Boolean value = getBoolean(mapping);
if (value == null) {
value = defaultValue;
}
return value;
}
public Object getId() {
Object value = null;
try {
value = this.getProperty(ATTRIBUTE_ID);
} catch (Exception e) {
}
return value;
}
public String getIdAsString() {
String value = null;
Object objValue = null;
try {
objValue = this.getProperty(ATTRIBUTE_ID);
if (objValue != null) {
value = String.valueOf(objValue);
}
} catch (Exception e) {
alert("String", objValue, ATTRIBUTE_ID);
}
return value;
}
public Long getIdAsLong() {
Long value = null;
Object objValue = null;
try {
objValue = this.getProperty(ATTRIBUTE_ID);
if (objValue instanceof String) {
value = Long.valueOf((String) objValue);
} else if (objValue instanceof Long) {
value = (Long) objValue;
} else {
alert("Long", objValue, ATTRIBUTE_ID);
}
} catch (Exception e) {
alert("Long", objValue, ATTRIBUTE_ID);
}
return value;
}
public Date getDate(String mapping) {
Date value = null;
Object classTypeObj = null;
try {
classTypeObj = this.getProperty(mapping);
value = (Date) classTypeObj;
} catch (Exception e) {
alert("Date", classTypeObj, mapping);
}
return value;
}
public String getDateAsString(String mapping, String format) {
String value = null;
Object classTypeObj = null;
try {
SimpleDateFormat sDateFormat = new SimpleDateFormat(format);
classTypeObj = this.getProperty(mapping);
value = sDateFormat.format((Date) classTypeObj);
} catch (Exception e) {
alert("Date", classTypeObj, mapping);
}
return value;
}
public Calendar getCalendar(String mapping) {
Calendar value = null;
Object classTypeObj = null;
try {
classTypeObj = this.getProperty(mapping);
value = (Calendar) classTypeObj;
} catch (Exception e) {
alert("Date", classTypeObj, mapping);
}
return value;
}
public List<?> getList(String mapping) {
List<?> value = null;
Object classTypeObj = null;
try {
classTypeObj = this.getProperty(mapping);
value = (List<?>) classTypeObj;
} catch (Exception e) {
alert("List", classTypeObj, mapping);
}
return value;
}
public List<BeanObject> getBOList(String mapping) {
List<BeanObject> value = null;
Object classTypeObj = null;
try {
classTypeObj = this.getProperty(mapping);
value = (List<BeanObject>) classTypeObj;
} catch (Exception e) {
alert("List", classTypeObj, mapping);
}
return value;
}
public List<BeanObject> getBOList(String key, boolean create) {
List<BeanObject> value = getBOList(key);
if (value == null && create) {
value = new ArrayList<>();
put(key, value);
}
return value;
}
public BeanObject getChild(String mapping) {
BeanObject value = null;
Object classTypeObj = null;
try {
classTypeObj = this.getProperty(mapping);
value = (BeanObject) classTypeObj;
} catch (Exception e) {
alert("BeanObject", classTypeObj, mapping);
}
return value;
}
public Object getProperty(String path) throws Exception {
return getValueOfPath(path);
}
public void prepareObject() {
if (containsKey("objectAlreadyParsed")) {
return;
}
put("objectAlreadyParsed", true, false);
for (String key : keySet()) {
if (get(key) instanceof BeanObject) {
getBo(key).prepareObject();
} else if (get(key) instanceof Collection<?>) {
for (BeanObject beanChild : getBOList(key)) {
beanChild.prepareObject();
}
} else {
if (get(key) instanceof Date) {
put(key, "date:" + dateToString(getDate(key), "/"), false);
}
}
}
}
public String dateToString(Date date, String separator) {
String formattedDate = null;
if (date != null) {
GregorianCalendar grCal = new GregorianCalendar();
grCal.setTime(date);
int year = grCal.get(GregorianCalendar.YEAR);
int month = grCal.get(GregorianCalendar.MONTH);
int day = grCal.get(GregorianCalendar.DAY_OF_MONTH);
month++;
formattedDate = day + separator + month + separator + year;
}
return formattedDate;
}
public void addParent(String relName, BeanObject parent) {
if (parent != null && !this.containsKey(PARAMETRE_ID)) {
// les BOs cachés (CacheDP) deviennent de plus en plus volumineux (for each bean dp.addParent)
getParents().add(parent);
getParentsRel().put(relName, parent);
}
}
public Set<BeanObject> getParents() {
if (parents == null) {
parents = new HashSet<>();
}
return parents;
}
public void setParents(Set<BeanObject> parents) {
this.parents = parents;
}
public <T, E> Set<T> getKeysByValue(Map<T, E> map, E value) {
Set<T> keys = new HashSet<T>();
for (Entry<T, E> entry : map.entrySet()) {
if (Objects.equals(value, entry.getValue())) {
keys.add(entry.getKey());
}
}
return keys;
}
public Set<BeanObject> getBoNotified() {
if (boNotified == null) {
boNotified = new HashSet<>();
}
return boNotified;
}
public void setBoNotified(Set<BeanObject> boNotified) {
this.boNotified = boNotified;
}
public Map<String, BeanObject> getParentsRel() {
if (parentsRel == null) {
parentsRel = new HashMap<>();
}
return parentsRel;
}
public void setParentsRel(Map<String, BeanObject> parentsRel) {
this.parentsRel = parentsRel;
}
public Map<String, Integer> getAttributsVersion() {
if (attributsVersion == null) {
attributsVersion = new HashMap<>();
}
return attributsVersion;
}
public void setAttributsVersion(Map<String, Integer> attributsVersion) {
this.attributsVersion = attributsVersion;
}
public Map<String, Object> getOldValues() {
if (oldValues == null) {
oldValues = new HashMap<>();
}
return oldValues;
}
public void setOldValues(Map<String, Object> oldValues) {
this.oldValues = oldValues;
}
public Map<String, Long> getAttributsIds() {
if (attributsIds == null) {
attributsIds = new HashMap<>();
}
return attributsIds;
}
public void setAttributsIds(Map<String, Long> attributsIds) {
this.attributsIds = attributsIds;
}
public Map<String, BeanObject> getDeletedChilds() {
if (deletedChilds == null) {
deletedChilds = new HashMap<>();// transient
}
return deletedChilds;
}
public void setDeletedChilds(Map<String, BeanObject> deletedChilds) {
this.deletedChilds = deletedChilds;
}
}
GenieList.javajavaimport java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
/**
*
* @author moukha
*
* @param <E>
*/
public class GenieList<E> implements List<E>, java.io.Serializable {
private static final long serialVersionUID = -3807483565174197345L;
private boolean changed = false;
private transient Set<BeanObject> parents = new HashSet<>();
private transient Map<String, BeanObject> parentsRel = new HashMap<>();
private Set<BeanObject> beansToDelete = new HashSet<>();//transient (deepClone)
/**
* la liste internalList (ArrayList) dans certains cas devient (GenieList), donc je gère ces cas avec un instanceOf pour ne pas notifier son parent ex: com.caciopee.genie.soa.client.result.GenieList.add(int, E, boolean)
*/
private List<E> internalList;
public GenieList() {
internalList = new ArrayList<>();
}
public GenieList(List<E> internalList) {
this.internalList = internalList;
}
public GenieList(int i) {
internalList = new ArrayList<>(i);
}
public boolean add(E paramE) {
return this.add(paramE, true);
}
public void add(int paramInt, E paramE) {
add(paramInt, paramE, true);
}
public void add(int paramInt, E paramE, boolean changed) {
setChanged(changed);
if (internalList instanceof GenieList) {
((GenieList) internalList).add(paramInt, paramE, changed);
} else {
internalList.add(paramInt, paramE);
}
}
public boolean add(E paramE, boolean changed) {
if (changed) {
setChanged(true);
}
if (internalList instanceof GenieList) {
return ((GenieList) internalList).add(paramE, changed);
} else {
return internalList.add(paramE);
}
}
@Override
public boolean remove(Object paramObject) {
setChanged(true);
return internalList.remove(paramObject);
}
@Override
public E remove(int paramInt) {
setChanged(true);
return internalList.remove(paramInt);
}
public boolean isChanged() {
return changed;
}
public void setChanged(boolean changed) {
this.changed = changed;
if (changed) {
notifyParent();
}
}
public boolean equals(Object paramObject) {
return internalList.equals(paramObject);
}
public int size() {
return internalList.size();
}
public boolean isEmpty() {
return internalList.isEmpty();
}
public boolean contains(Object paramObject) {
return internalList.contains(paramObject);
}
public int indexOf(Object paramObject) {
return internalList.indexOf(paramObject);
}
public int lastIndexOf(Object paramObject) {
return internalList.lastIndexOf(paramObject);
}
public int hashCode() {
return internalList.hashCode();
}
public Object clone() {
if (internalList instanceof GenieList) {
return ((GenieList) internalList).clone();
} else if (internalList instanceof ArrayList) {
return ((ArrayList) internalList).clone();
}
return null;
}
public boolean containsAll(Collection<?> paramCollection) {
return internalList.containsAll(paramCollection);
}
public Object[] toArray() {
return internalList.toArray();
}
public <T> T[] toArray(T[] paramArrayOfT) {
return internalList.toArray(paramArrayOfT);
}
public E get(int paramInt) {
return internalList.get(paramInt);
}
public E set(int paramInt, E paramE) {
return set(paramInt, paramE, true);
}
public E set(int paramInt, E paramE, boolean changed) {
if (changed) {
setChanged(changed);
}
if (internalList instanceof GenieList) {
return (E) ((GenieList) internalList).set(paramInt, paramE, changed);
} else {
return internalList.set(paramInt, paramE);
}
}
public String toString() {
return internalList.toString();
}
public void clear() {
setChanged(true);
internalList.clear();
}
public boolean addAll(Collection<? extends E> paramCollection) {
return addAll(paramCollection, true);
}
public boolean addAll(Collection<? extends E> paramCollection, boolean changed) {
if (changed) {
setChanged(changed);
}
if (internalList instanceof GenieList) {
return ((GenieList) internalList).addAll(paramCollection, changed);
} else {
return internalList.addAll(paramCollection);
}
}
public boolean addAll(int paramInt, Collection<? extends E> paramCollection) {
setChanged(true);
return internalList.addAll(paramInt, paramCollection);
}
public boolean removeAll(Collection<?> paramCollection) {
return internalList.removeAll(paramCollection);
}
public boolean retainAll(Collection<?> paramCollection) {
return internalList.retainAll(paramCollection);
}
public ListIterator<E> listIterator(int paramInt) {
return internalList.listIterator(paramInt);
}
public ListIterator<E> listIterator() {
return internalList.listIterator();
}
public Iterator<E> iterator() {
return internalList.iterator();
}
public List<E> subList(int paramInt1, int paramInt2) {
return internalList.subList(paramInt1, paramInt2);
}
public void addParent(String relName, BeanObject parent) {
if (parent != null) {
getParents().add(parent);
getParentsRel().put(relName, parent);
}
}
private void notifyParent() {
for (BeanObject parent : this.getParents()) {
/** to be verified (recursive) */
// if (!parent.isChanged()) {
// }
}
}
public Set<BeanObject> getParents() {
if (parents == null) {
parents = new HashSet<>();
}
return parents;
}
public void setParents(Set<BeanObject> parents) {
this.parents = parents;
}
public String showParentsIds() {
StringBuilder toString = new StringBuilder();
for (BeanObject parent : this.getParents()) {
toString.append("- parentId : " + parent.getIdAsString());
}
if (this.getParentsRel() != null) {
for (String keyParent : this.getParentsRel().keySet()) {
}
}
return toString.toString();
}
public Set<BeanObject> getBeansToDelete() {
if (beansToDelete == null) {
beansToDelete = new HashSet<>();
}
return beansToDelete;
}
public void setBeansToDelete(Set<BeanObject> beansToDelete) {
if (beansToDelete!=null && !beansToDelete.isEmpty()) {
Set<BeanObject> beans2Delete = new HashSet<>();
for (BeanObject beanToDelete : beansToDelete) {
BeanObject bean2Deleted = new BeanObject();
bean2Deleted.put("id", beanToDelete.getIdAsLong());
beans2Delete.add(bean2Deleted);
}
this.beansToDelete = beans2Delete;
} else {
this.beansToDelete = beansToDelete;
}
}
public void addBeanToDelete(BeanObject beanToDelete) {
if (beanToDelete != null) {
BeanObject bean2Deleted = new BeanObject();
bean2Deleted.put("id", beanToDelete.getIdAsLong());
getBeansToDelete().add(bean2Deleted);
}
}
public Map<String, BeanObject> getParentsRel() {
if (parentsRel == null) {
parentsRel = new HashMap<>();
}
return parentsRel;
}
public void setParentsRel(Map<String, BeanObject> parentsRel) {
this.parentsRel = parentsRel;
}
}