1

how to add component into groupbox after button click

asked 2014-03-17 07:50:17 +0800

demizon gravatar image demizon
179 1 6

Hello,

can someone help me how to add(generate) new combobox into zul page(groupbox) after i click on the button? At first i was thinking about generating all comboboxes when the zul page is generated and making them invisible, and after i click button set them visible, but its quiet uneffective.

this is how my page looks like:

image description

zul source code:

...

<groupbox title="Moduly vo variante" width="700px" height="230px">

               <vlayout>
                    <hlayout>
                    <textbox value="@bind(mevm.selectedModul11)" width="150px"/>
                    <label value="or:" visible="@bind(mevm.modul11Vis)" width="150px"/>
                    <textbox value="@bind(mevm.selectedModul12)" width="150px"/>
                    <button mold="trendy"  label="+" visible="@bind(not mevm.modul12Vis)"
                                      onClick="@command('addTextBoxHor')"/>
                    </hlayout>




               <button mold="trendy"  label="+"  visible="@bind(not mevm.modul61Vis)"
                                                     onClick="@command('addTextBoxVert')"/>
               </vlayout>


      </groupbox>

...

delete flag offensive retag edit

4 Answers

Sort by ยป oldest newest most voted
1

answered 2014-03-17 08:16:15 +0800

chillworld gravatar image chillworld flag of Belgium
5367 4 9
https://github.com/chillw...

updated 2014-03-17 08:23:17 +0800

Well, you could add the groupbox as parameter with your command like this :

<groupbox id="grpBox" title="Moduly vo variante" width="700px" height="230px">               
    ....
    <button mold="trendy"  label="+" visible="@bind(not mevm.modul12Vis)"onClick="@command('addTextBoxHor', groupbox=grpBox)"/>
    ...
</groupbox>

then you will have your groupbox in your command like this :

@Command
public void addTextBoxHor(@BindingParam("groupbox") Groupbox grpBox) {
    ....
}

Now just create your combobox with code and put it in your groupbox where you want it.

If that is to hard, just create a dummy combobox and do the same but in stead of groupbox take the combobox. Just with the command you make it visible and fill its data.

Take care, if your data is not refreshed, it could be you have to do grpBox.invalidate(); at the end.

Greetz chill.

link publish delete flag offensive edit
0

answered 2014-03-17 10:07:32 +0800

demizon gravatar image demizon
179 1 6

Thank you, it works! :) If i can have two more question...in zul page i did combobox like this:

<combobox width="150px" model="@load(mevm.modulsList)" selectedItem="@bind(mevm.selectedModul11)">
                              <template name="model">
                                   <comboitem label="@load(each.name)"/>
                              </template>
                    </combobox>

1.how do i set that selected item from combbox will be saved into selectedModul11 and 2. how to set template of combobox that it will show attribute "name" in combobox? but in java code.

until now i have in java code something like this:

Combobox combobox = new Combobox();
 combobox.setModel(new ListModelList(modulsList));

i tried

combobox.setSelectedItem(selectedModul11);

but it doesnt work.

link publish delete flag offensive edit
0

answered 2014-03-17 10:26:42 +0800

chillworld gravatar image chillworld flag of Belgium
5367 4 9
https://github.com/chillw...

updated 2014-03-17 10:27:18 +0800

Well,

  • how do i set that selected item from combbox will be saved into selectedModul11

You are doing it : selectedItem="@bind(mevm.selectedModul11)"
This means that when selectedItem is you will save it in mevm.selectedModul11.

@bind is the same as @load @save.

  • how to set template of combobox that it will show attribute "name" in combobox? but in java code.

You can use a renderer. Then you have full control with java of what you can see.

Greetz chill.

link publish delete flag offensive edit
0

answered 2014-03-17 11:13:46 +0800

demizon gravatar image demizon
179 1 6

updated 2014-03-17 11:19:47 +0800

But I am asking how can I get selectedItem from combobox in my java code :) (i know how to handle it if i create combobox in zul file) This is my situation: 1.I click button 2.I create new combobox which contains list of moduls:

Combobox combobox = new Combobox();
combobox.setModel(new ListModelList(modulsList));

Now have to select item from modulsList and save selected item into variable "selectedModul11", but my problem is that i dont know how to set combobox so it will save selected item into "selectedModul11". (in Java code)

i need something like this:

combobox.setSelectedItem(selectedModul11);
link publish delete flag offensive edit

Comments

Ah oke, Then you have to add an eventListener to onSelectet to you combobox and write there the logic in it. Need more explication of eventlistener? Greetz chill.

chillworld ( 2014-03-17 11:56:33 +0800 )edit

i did it some other way...i thought that i have to set variable in which selected item will be stored, but i can get just by calling combobox.getSelectedItem().getValue()...anyway, thankou very much for your time and great help :)

demizon ( 2014-03-17 12:49:33 +0800 )edit

your welcome

chillworld ( 2014-03-17 12:54:28 +0800 )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: 2014-03-17 07:50:17 +0800

Seen: 41 times

Last updated: Mar 17 '14

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