From de8c0de43e6d00991e93ef18e29d8132a2e63bd3 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 25 Mar 2011 19:54:10 -0500 Subject: [PATCH] Fix problem in zkwebui - resource assignment cannot be created. Steps to reproduce: - Create a Sales Order - Create a line selling Mary Consultant product - Try to create a resource assignment a Null Pointer Exception was thrown --- .../adempiere/webui/component/ListItem.java | 10 ++++++++-- .../org/adempiere/webui/component/Listbox.java | 17 +++++++++++++++-- .../webui/window/WAssignmentDialog.java | 18 +++++++++--------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ListItem.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ListItem.java index b2f33fd5a3..9b8d069903 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ListItem.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ListItem.java @@ -30,10 +30,10 @@ import org.compiere.util.ValueNamePair; */ public class ListItem extends org.zkoss.zul.Listitem { - /** + /** * */ - private static final long serialVersionUID = -3445426943414051896L; + private static final long serialVersionUID = -8052056834118074979L; private PropertyChangeSupport m_propertyChangeListeners = new PropertyChangeSupport(this); public ListItem(String label, Object value) @@ -59,4 +59,10 @@ public class ListItem extends org.zkoss.zul.Listitem public ValueNamePair toValueNamePair() { return new ValueNamePair((String)getValue(), getLabel()); } + + @Override + public String toString() { + return getValue().toString(); + } + } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Listbox.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Listbox.java index 9870d94c21..d9ebf2720d 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Listbox.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Listbox.java @@ -37,10 +37,10 @@ import org.zkoss.zul.Listitem; */ public class Listbox extends org.zkoss.zul.Listbox implements EventListener { - /** + /** * */ - private static final long serialVersionUID = -411510408730815382L; + private static final long serialVersionUID = 2102597724705225997L; private List doubleClickListeners = new ArrayList(); private List onDropListeners = new ArrayList(); private boolean draggable; @@ -327,4 +327,17 @@ public class Listbox extends org.zkoss.zul.Listbox implements EventListener oddRowSclass = scls; super.setOddRowSclass(scls); } + + @Override + public String toString() { + StringBuffer items = new StringBuffer("["); + for (ListItem item : getItems()) { + if (items.length() > 1) + items.append(", "); + items.append(item.toString()); + } + items.append("]"); + return items.toString(); + } + } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAssignmentDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAssignmentDialog.java index 31ff61a1ad..573f99f61f 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAssignmentDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WAssignmentDialog.java @@ -221,16 +221,14 @@ public class WAssignmentDialog extends Window implements EventListener // Set Resource int S_Resource_ID = m_mAssignment.getS_Resource_ID(); - KeyNamePair[] resources = new KeyNamePair[m_lookup.size()]; - m_lookup.keySet().toArray(resources); - for (int i = 0; i < resources.length; i++) - { - if (resources[i].getKey() == S_Resource_ID) - { - fResource.setSelectedIndex(i); + + for (ListItem item : fResource.getItems()) { + if ( (Integer)item.getValue() == S_Resource_ID) { + fResource.setSelectedItem(item); break; } } + ListItem listItem = fResource.getSelectedItem(); KeyNamePair check = new KeyNamePair((Integer)listItem.getValue(), listItem.getLabel()); if (check == null || check.getKey() != S_Resource_ID) @@ -284,7 +282,9 @@ public class WAssignmentDialog extends Window implements EventListener getDateAndTimeFrom(date); Timestamp assignDateFrom = new Timestamp(date.getTimeInMillis()); BigDecimal qty = fQty.getValue(); - KeyNamePair uom = (KeyNamePair)m_lookup.get(fResource.getSelectedItem()); + ListItem listItem = fResource.getSelectedItem(); + KeyNamePair resource = listItem != null ? new KeyNamePair((Integer)listItem.getValue(), listItem.getLabel()) : null; + KeyNamePair uom = (KeyNamePair)m_lookup.get(resource); int minutes = MUOMConversion.convertToMinutes(Env.getCtx(), uom.getKey(), qty); Timestamp assignDateTo = TimeUtil.addMinutess(assignDateFrom, minutes); m_mAssignment.setAssignDateTo (assignDateTo); @@ -367,7 +367,7 @@ public class WAssignmentDialog extends Window implements EventListener // Resource - Look up UOM if (e.getTarget() == fResource) { - Object o = m_lookup.get(fResource.getSelectedItem()); + Object o = m_lookup.get(resource); if (o == null) lUOM.setValue(" ? "); else