0

Use EL Expressions to access object from .java to .zul

asked 2019-09-24 01:59:18 +0800

retnuh gravatar image retnuh
1

updated 2019-09-24 02:39:46 +0800

Hi All, I have an EL Expressions problem here. I want to make a grid which has dynamic column, so I try the following code

<column label="Product Number : ${each }" forEach="1,2,3"/>

It is close what I want, and I guess it may work if I could pass the java object to zul, just like EL in JSP. Then I modified my code to

<column label="Product Number : ${each.number }" forEach="${tsProductNumbers }"/>

However, I tried many ways to set object in the Controller.java, such as @WireVariable or implements VariavleResolver, do not work.

Please refer to the entire code below and give me some advice,

thanks you guys!


view.zul

<zk>
<window title="" border="normal" width="99%" height="99%"
    id="window" apply="foo.Controller">
    <borderlayout>
        <north size="20%" splittable="true" collapsible="true"
            open="true">
        </north>

        <center>
            <vlayout hflex="1" vflex="1">
                <hlayout hflex="1" sclass="z-valign-middle"
                    spacing="0" style="background:lightblue">
                    <vlayout>
                        <button id="btnCheck" label="Check" />
                    </vlayout>
                </hlayout>
                <grid id="Mask_Grid" width="100%" sizedByContent="true" emptyMessage="Nothing in list." hflex="1" vflex="1">
                    <columns >
                        <column label="Module" sort="auto" />
                        <column label="Tab" sort="auto" />
                        <column label="Item" />
                        <column label="Product Number : ${each }" forEach="1,2,3"/>
                    </columns>

                </grid>

            </vlayout>
        </center>
    </borderlayout>
</window>

</zk>


Controller.java

public class Controller extends SelectorComposer<Component>{

private static final long serialVersionUID = 1L;

@Wire
private Grid Pord_Grid;

//omit some successfully @wire component

List<ProductVO> sortedProducts = new LinkedList<ProductVO>();

Set<String> tsProductNumbers;

@Listen("onClick=#btnCheck")
public void check(){
    tsProductNumbers = new TreeSet<String>();
    tsProductNumbers.add("123");
    tsProductNumbers.add("456");
    tsProductNumbers.add("789");
    tsProductNumbers.add("012");
    for(String PN : tsProductNumbers){
       ProductVO productVO = new ProductVO();
       porductVO.setPN(PN);     
       sortedProducts.add(productVO);
    }
}
}

ProductVO.java

public class ProductVO {
private String number;

public String getNumber() {
    return number;
}

public void setNumber(String number) {
    this.number = number;
}
}

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2019-09-24 11:24:11 +0800

cor3000 gravatar image cor3000
4791 2 7
ZK Team

There are simple ways to pass objects to a zul page, @WireVariable has a completely different purpose (-> to wire variables into your composer, e.g. from surrounding scopes, and also from spring or cdi)

Here 2 ways which seem most appropriate to your description:

http://zkfiddle.org/sample/4q3451/1-EL-access-to-controller-variables#source-1

As you can see I populate the collection before components are created (doBefore... methods) so that the variables are then available when the EL expressions evaluate.

One way is to use the implicit $composer variable to access a getter on your composer. Another way is to set a custom scoped attribute at the component which is then accessible in a zul page below this component. (Other scopes are page.setAttribute, desktop.setAttribute, session.setAttribute, webapp.setAttribute, execution.setAttribute)

Doing this in a click listener will be too late since the EL expressions evaluate at page creation time. You can create components dynamically after a click using one of the Executions.createComponents(...) methods

If questions remain let me know.

link publish delete flag offensive edit
0

answered 2019-09-28 11:16:50 +0800

retnuh gravatar image retnuh
1

Hi cor3000,

Thanks for your reply. These methods do work for me.

link publish delete flag offensive edit
Your answer
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
1 follower

RSS

Stats

Asked: 2019-09-24 01:59:18 +0800

Seen: 11 times

Last updated: Sep 28

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