-
FEATURED COMPONENTS
First time here? Check out the FAQ!
ZK 3.63
I have a listbox with two columns (string,BigDecimal). What I want to be able to do is
- populate list box in readonly state first
- click on an 'edit button' to enable the decimal field entry
- allow changes, and use 'save' button to commit changes
I can populate listbox fine and have decimalbox within listcell which is initially disabled
When i click edit I 'try' to programmatically access the decimalbox to enable it but the code only seems to see
1 column (listItem.getChildren() returning 1) and certainly none of the listcells is returning ANY children.
The listbox.itemcount is returning correct count (8 lines)
Zul
<listbox id="listBoxXXX" vflex="true"
width="99.5%"height="100%" multiple="false">
<listhead sizable="true">
<listheader id="listheader_1" label="col 1'" sort="none" width="60%" />
<listheader id="listheader_2" label="col2" sort="none" align="right" width="40%" />
</listhead>
</listbox>
// populate code
List<XXObj> lstArr =myService.get...();
ListModelList lst1 = new ListModelList();
lst1.addAll(lstArr);
listBox_XXX.setModelList(lst1);
listBox_XXX..setItemRenderer(new MyItemRenderer());
// Renderer
...
public void render(Listitem item, Object data)
{
MyObj obj = (MyObj)data;
Listcell lc = new Listcell(obj.getDescription());
item.appendChild(lc);
Decimalbox dBox = new Decimalbox();
dBox.setValue(new BigDecimal(obj.getValue()));
lc = new Listcell();
lc.appendChild(dBox);
item.appendChild(lc);
}
// Code to set readonly (trying to use objects at moment while I understand structure) ..
List<Listitem> lstArr = listBox_XXX.getItems();
logger.debug("Count items :" + listBox_XXX.getItemCount());
// for (Listitem lstItem : lstArr)
for (Object item : listBox_XXX.getItems()) {
logger.debug("item :" + item);
if (item instanceof Listitem) {
Listitem lstItem = (Listitem) item;
for (Object cell : ((Listitem) lstItem).getChildren()) {
logger.debug("cell :" + cell);
// CHILDREN COUNT is ALWAYS 1
if (cell instanceof Listcell) {
Listcell listcell = (Listcell) cell;
logger.debug("cell :" + listcell.getLabel());
for (Object innercell : listcell.getChildren()) {
// NEVER GET HERE
Probably in wrong forum - moving to help ..
Ok I appear to have solved this by 'simply' using two ListItemRenderers
For the readonly I just use a Listcell and set its text.
lc = new Listcell(String.format("%.2f", obj.getDeclaredValue())); item.appendChild(lc);
When I want to edit the listcell, I simply
change the ItemRender to one with a decimalbox for the value and catch the onchange event
which I then use to update the data stored with the listitem itself (item.setAttribute("data", someObj");
Decimalbox dBox = new Decimalbox(); dBox.setValue(new BigDecimal(obj.getDeclaredValue())); dBox.addEventListener(Events.ON_CHANGE, new EventListener(){ public void onEvent(Event arg0) throws Exception{ Decimalbox dBox = (Decimalbox) arg0.getTarget(); ... ;} }); lc = new Listcell(); lc.appendChild(dBox); item.appendChild(lc);
I have checked your code in the other thread :-(
So, that's exactly, why not do cross post :-)
best
Stephan
Asked: 2010-02-25 08:12:02 +0800
Seen: 604 times
Last updated: Feb 26 '10