The window context variable is share by all tab and can get mix up when user navigate from one tab to another. This patch recreate the window context variable before entering a tab to solve the potential conflict issue.

Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2959339
This commit is contained in:
Heng Sin Low 2010-02-26 02:07:55 +00:00
parent cd210e3170
commit fa569115e1
2 changed files with 76 additions and 11 deletions

View File

@ -1278,6 +1278,19 @@ public class GridField
m_inserting = inserting; m_inserting = inserting;
m_error = false; // reset error m_error = false; // reset error
updateContext();
// Does not fire, if same value
Object oldValue = m_oldValue;
if (inserting)
oldValue = INSERTING;
m_propertyChangeListeners.firePropertyChange(PROPERTY, oldValue, m_value);
} // setValue
/**
* Update env. context with current value
*/
public void updateContext() {
// Set Context // Set Context
if (m_vo.displayType == DisplayType.Text if (m_vo.displayType == DisplayType.Text
|| m_vo.displayType == DisplayType.Memo || m_vo.displayType == DisplayType.Memo
@ -1286,15 +1299,15 @@ public class GridField
|| m_vo.displayType == DisplayType.RowID || m_vo.displayType == DisplayType.RowID
|| isEncrypted()) || isEncrypted())
; // ignore ; // ignore
else if (newValue instanceof Boolean) else if (m_value instanceof Boolean)
{ {
backupValue(); // teo_sarca [ 1699826 ] backupValue(); // teo_sarca [ 1699826 ]
Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.ColumnName, Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.ColumnName,
((Boolean)newValue).booleanValue()); ((Boolean)m_value).booleanValue());
Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, m_vo.ColumnName, Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, m_vo.ColumnName,
m_value==null ? null : (((Boolean)m_value) ? "Y" : "N")); m_value==null ? null : (((Boolean)m_value) ? "Y" : "N"));
} }
else if (newValue instanceof Timestamp) else if (m_value instanceof Timestamp)
{ {
backupValue(); // teo_sarca [ 1699826 ] backupValue(); // teo_sarca [ 1699826 ]
Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.ColumnName, (Timestamp)m_value); Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.ColumnName, (Timestamp)m_value);
@ -1309,13 +1322,7 @@ public class GridField
Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, m_vo.ColumnName, Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, m_vo.ColumnName,
m_value==null ? null : m_value.toString()); m_value==null ? null : m_value.toString());
} }
}
// Does not fire, if same value
Object oldValue = m_oldValue;
if (inserting)
oldValue = INSERTING;
m_propertyChangeListeners.firePropertyChange(PROPERTY, oldValue, m_value);
} // setValue
/** /**
* Set Value and Validate * Set Value and Validate

View File

@ -18,14 +18,18 @@
package org.adempiere.webui.component; package org.adempiere.webui.component;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.adempiere.webui.panel.ADSortTab;
import org.adempiere.webui.panel.ADTabpanel; import org.adempiere.webui.panel.ADTabpanel;
import org.adempiere.webui.panel.IADTabpanel; import org.adempiere.webui.panel.IADTabpanel;
import org.adempiere.webui.part.AbstractUIPart; import org.adempiere.webui.part.AbstractUIPart;
import org.compiere.model.DataStatusEvent; import org.compiere.model.DataStatusEvent;
import org.compiere.model.GridField;
import org.compiere.model.GridTab; import org.compiere.model.GridTab;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Evaluator; import org.compiere.util.Evaluator;
/** /**
@ -119,6 +123,7 @@ public abstract class AbstractADTab extends AbstractUIPart implements IADTab
canJump = canNavigateTo(oldIndex, newIndex); canJump = canNavigateTo(oldIndex, newIndex);
if (canJump) if (canJump)
{ {
prepareContext(newIndex, newTab);
doTabSelectionChanged(oldIndex, newIndex); doTabSelectionChanged(oldIndex, newIndex);
} }
} }
@ -126,6 +131,59 @@ public abstract class AbstractADTab extends AbstractUIPart implements IADTab
return canJump; return canJump;
} }
private void prepareContext(int newIndex, IADTabpanel newTab) {
//update context
if (newTab != null)
{
List<Integer> parents = new ArrayList<Integer>();
//get parent list
if (newIndex > 0)
{
int currentLevel = newTab.getTabLevel();
for (int i = newIndex - 1; i >= 0; i--)
{
IADTabpanel adtab = tabPanelList.get(i);
if (adtab.getGridTab() == null) continue;
if (adtab instanceof ADSortTab) continue;
if (adtab.getTabLevel() < currentLevel || i == 0)
{
parents.add(i);
currentLevel = adtab.getTabLevel();
}
}
Collections.reverse(parents);
}
//clear context
for (int i = 0; i < tabPanelList.size(); i++)
{
IADTabpanel adtab = tabPanelList.get(i);
if (adtab.getGridTab() == null) continue;
if (adtab instanceof ADSortTab) continue;
GridField[] fields = adtab.getGridTab().getFields();
for (GridField gf : fields)
{
Env.setContext(Env.getCtx(), gf.getWindowNo(), gf.getColumnName(), "");
}
}
//add parent value to context
if (!parents.isEmpty())
{
for(int i : parents)
{
IADTabpanel adtab = tabPanelList.get(i);
GridField[] fields = adtab.getGridTab().getFields();
for (GridField gf : fields)
{
gf.updateContext();
}
}
}
}
}
protected abstract void doTabSelectionChanged(int oldIndex, int newIndex); protected abstract void doTabSelectionChanged(int oldIndex, int newIndex);
public boolean isDisplay(int index) { public boolean isDisplay(int index) {