# How could I change, dynamically, components inside a Row?

fmcypriano
612 1 7
http://felipecypriano.com...

Hello,

I've a grid which has two columns that can be edited, this is the grid code:

        <grid id="grdCores" fixedLayout="true" mold="paging" pageSize="10">
<rows>
<row self="@{each=item}">
<label value="@{item.color}"/>
<numberlabel value="@{item.availableQuantity}"/>
<doublebox value="@{item.quantity}" constraint="no negative"/>
<doublebox value="@{item.price}" width="80%" constraint="no negative"
forward="onBlur=onBlurItemPreco, onOK=onBlurItemPreco"/>
</row>
</rows>
</grid>


When the user enter the price, the last doublebox, I want to disable the price doublebox for all rows in the grid. I can access all Row elements but I couldn't find a way to access the Row's component (namely: label, numberlabel, two doublebox).

This is how I access the all the Row elements:

grdCores.getRows().getChildren()

But I can't do this:

grdCores.getRows().getChildren().get(0).getChildren()

Is there a way to iterate through the components inside a row?

Regards

delete retag edit

## 18 Replies

fmcypriano
612 1 7
http://felipecypriano.com...

I'll try to simplify my question. Thinking of a page which has a grid and this grid has some rows and this have two components a label and a doublebox:

        <grid id="grdCores">
<rows>
<row self="@{each=item}">
<label value="@{item.color}"/>
<doublebox value="@{item.price}"/>
</row>
</rows>
</grid>


With this grid the user can edit the color's price, but in some cases I want to disable the doublebox. So I need to iterate through the rows to setDisabled(true). How could I do this?

Regards

526 2 2 9

I have achieved a similar functionality by having my own custom Grid renderer for the grid using Java, not in zul code.

There (In Renderer) you can able to control all the components and listen for their events and take actions appropriately.

fmcypriano
612 1 7
http://felipecypriano.com...

Back them when I was making this grid I tried to use a custom renderer but I couldn't because I don't find a way to add annotations to bind the doublebox to my model. I ask how to do it here http://www.zkoss.org/forum/listComment/8532/ but I get no answer. It was in june.

526 2 2 9

I am not using annotations binding. Hence, am not faced any problem with rendering.

fmcypriano
612 1 7
http://felipecypriano.com...

Ok, I appreciate your help. The problem I had wasn't in doing a renderer but in creating a doublebox component annotated in java code, how to translate this:

<doublebox value="@{item.price}"/>

to java, something like:

new Doublebox()//.setValue("@{item.preco}" just to explaing the idea

9393 3 7 16
http://www.oxitec.de/

Hmmmm, like baskaraninfo i don't use annotateBindings. But i mean to remember that 'robertPic' does such things with so called typeconverters.
Here is a link to his demo page with sources. Or search the forum for converter.

best
Stephan

fmcypriano
612 1 7
http://felipecypriano.com...

Stephan, it's really easy to do bindings in zul files but I can't realize a way to the same thing in java code and hence I can't write a custom renderer. I looked in 'robertPic' demos and don't find any usage of annotated bindings in java code.

I was re-reading my previous thread I realize that I'm facing the same problem again. I need to access data inside each Row and I can't it, seems like it is impossible. I do think that it's not a good component design to not being able to access the Row's children or in other words the Row's content.

fusion35
237 2 5

Hi :

provide the row and look for the component that is instanceof Doublebox

I had a scenario where I had to disable the screen components based on certain condition and also had to ignore some of the components.

    private void lookForComponent(List list) {
if (list != null) {
for (Object obj : list) {
if (obj instanceof InputElement) {
InputElement ie = (InputElement) obj;
ie.setDisabled(ignoreCompomentsIds.contains(ie.getId()) ? ie.isDisabled() : disable);
} else if (obj instanceof Checkbox) {
Checkbox cb = (Checkbox) obj;
cb.setDisabled(ignoreCompomentsIds.contains(cb.getId()) ? cb.isDisabled() : disable);
} else if (obj instanceof Button) {
Button btn = (Button) obj;
btn.setDisabled(ignoreCompomentsIds.contains(btn.getId()) ? btn.isDisabled() : disable);
} else if (obj instanceof Listbox) {
Listbox lb = (Listbox) obj;
lb.setDisabled(ignoreCompomentsIds.contains(lb.getId()) ? lb.isDisabled() : disable);
}
lookForComponent(((AbstractComponent) obj).getChildren());
}
}
}



regards

Devinder

fmcypriano
612 1 7
http://felipecypriano.com...

Hi Devinder,

That's the problem I can access the each Row using this command:

grdCores.getRows().getChildren()

But I can access the rows's children to look for the doublebox. Do you have any tips on how to do this?

fusion35
237 2 5

Hi :

It could be changed to something like this :

    private void lookForComponent(List list) {
if (list != null) {
for (Object obj : list) {
if (obj instanceof Row)
lookForComponent(((AbstractComponent) obj).getChildren());
else if (obj instanceof Doublebox)
((Doublebox) obj).setDisabled(true);
}
}
}


and to invoke it, you need to pass the rows :

   List children = grdCores.getRows().getChildren();
lookForComponent(children);


Are we any closer to the solution ?

regards

Devinder

[hide preview]