0

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

asked 2009-11-12 12:58:39 +0800

fmcypriano gravatar image 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 flag offensive retag edit

18 Replies

Sort by ยป oldest newest

answered 2009-11-13 05:15:20 +0800

fmcypriano gravatar image 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

link publish delete flag offensive edit

answered 2009-11-13 05:48:23 +0800

baskaraninfo gravatar image baskaraninfo
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.

link publish delete flag offensive edit

answered 2009-11-13 06:04:36 +0800

fmcypriano gravatar image 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.

link publish delete flag offensive edit

answered 2009-11-13 06:12:13 +0800

baskaraninfo gravatar image baskaraninfo
526 2 2 9

I am not using annotations binding. Hence, am not faced any problem with rendering.
I can't help you in this regard.

link publish delete flag offensive edit

answered 2009-11-13 06:24:32 +0800

fmcypriano gravatar image 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

link publish delete flag offensive edit

answered 2009-11-13 09:16:13 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-11-13 09:18:09 +0800

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

link publish delete flag offensive edit

answered 2009-11-13 10:01:11 +0800

fmcypriano gravatar image 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.

link publish delete flag offensive edit

answered 2009-11-13 10:59:57 +0800

fusion35 gravatar image 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());
            }
        }
    }

does this help you in some way?

regards

Devinder

link publish delete flag offensive edit

answered 2009-11-13 12:00:53 +0800

fmcypriano gravatar image 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?

link publish delete flag offensive edit

answered 2009-11-14 00:08:39 +0800

fusion35 gravatar image 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

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-11-12 12:58:39 +0800

Seen: 651 times

Last updated: Nov 30 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More