0

Get value from listbox and pass value to other zul

asked 2014-11-28 09:05:10 +0800

dearest555 gravatar image dearest555
111

updated 2014-11-28 12:12:19 +0800

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

How to code if I would like to get value from selected item in listbox and pass to other zul file

1.Select a oem value such as BMW 2.select only model in the selected oem value such as X1

form.zul

<hbox>
    <label>OEM</label>
    <label value="*" style="color:red"/>
    <textbox id="tx"/>  
</hbox> 
<vbox hflex="1">
    <listbox mold="select"
                   id="oemDescs" 
                   model="@load(vm.oemDescs)" 
                   selectedItem="@bind(request.oem) @validator(vm.requiredValidator)"
                   visible="@load(vm.saveAllowed and !vm.requestSubmitted)"
                   onSelect="tx.setValue(self.getSelectedItem().getLabel());">
        <template
            name="model">
            <listitem
                label="@load(each eq NULL?'NONE':each.oemDesc)" />
        </template>
    </listbox>
    <label  
        visible="@load(vm.requestSubmitted)"
        value="@load(request.oem)" />
</vbox>

model.zul

void searchByName(String oem) {
    if (name.getValue() != null && !name.getValue().equals("")) {
        Search search = new Search(NewPhaseModel.class);
        search.addFilterLike("modelName", "%" + name.getValue() + "%");
        employees = generalDAO.search(search);
        employeeModel = new ListModelList(employees);
        userList.setModel(employeeModel);
    }
}
delete flag offensive retag edit

Comments

Your post is not readable. Please edit your post using the [code] tags.

cyiannoulis ( 2014-11-28 11:01:01 +0800 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-11-28 12:36:50 +0800

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

updated 2014-11-28 19:21:28 +0800

Hi there.

First of all I have mine questions about the validator for the selectedItem in the listbox, is that really needed?

You could work in different approach.
You didn't speak of your other zul is a new window popup or just other screen.
If your window is a popup you could do :

I put here some static code in the VM, with me this is located in an AbstractVM witch all mine VM extends so you can easily call the method.

<hbox>
    <label>OEM</label>
    <label value="*" style="color:red"/>
    <textbox id="tx"/>  
</hbox> 
<vbox hflex="1">
    <listbox mold="select"
                   id="oemDescs" 
                   model="@load(vm.oemDescs)" 
                   selectedItem="@bind(vm.selectedOem) @validator(vm.requiredValidator)"
                   visible="@load(vm.saveAllowed and !vm.requestSubmitted)"
                   onSelect="tx.setValue(self.getSelectedItem().getLabel());">
        <template name="model">
            <listitem
                label="@load(each eq NULL?'NONE':each.oemDesc)" />
        </template>
    </listbox>
    <label  
        visible="@load(vm.requestSubmitted)"
        value="@load(request.oem)" />
</vbox>

java:

@Command
public void openASpecifModalWindow() throws InterruptedException {
    Map<String, Object> args = new HashMap<>();
    args.put("oem", selectedOem);
    openModal("/WEB-INF/yourPath/yourPage.zul", args);
}

public static void openModal(final String page,
        final Map<String, Object> obMap) throws InterruptedException {
    openModal(page, obMap, null);
}

public static void openModal(final String page,
        final Map<String, Object> obMap,
        final EventListener<Event> onCloseListener)
        throws InterruptedException {
    openModal(page, null, obMap, onCloseListener);
}

public static void openModal(final String page, final Component parent,
        final Map<String, Object> obMap,
        final EventListener<Event> onCloseListener)
        throws InterruptedException {
    for (final Map.Entry<String, Object> entry : obMap.entrySet()) {
        Executions.getCurrent().setAttribute(entry.getKey(),
                entry.getValue());
    }
    Executions.getCurrent().setAttribute(Composition.PARENT, null);
    final Component createComponents = Executions.createComponents(page,
            parent, obMap);
    Component parent1 = createComponents;
    parent1 = getWindow(parent1);
    if (parent1 instanceof Window) {
        final Window window = (Window) parent1;
        if (onCloseListener != null) {
            window.addEventListener(Events.ON_CLOSE, onCloseListener);
            window.addEventListener(Events.ON_CANCEL, onCloseListener);
        }
        // window.setClosable(true);
        window.doModal();
    }
}

VM new zul :

@Init
public final void init(@BindingParam("oem") YourObject oem) {
    if (oem==null) {
        throw new AssertionError("oem is empty");
    } // or do something else when oem is empty.
    this.oem = oem;
}
link publish delete flag offensive edit
0

answered 2014-11-28 15:37:03 +0800

dearest555 gravatar image dearest555
111

Thank you so much for prompt response. For the question 1.the validator for the selectedItem in the listbox, is that really needed? Ans: Yes .Validate this field need to select

2.your other zul is a new window popup or just other screen. Ans: my other zul is a new window popup.

link publish delete flag offensive edit

Comments

so the code I posted can do the trick. If you add a button to your main zul what triggers the command => you have your popup working.

chillworld ( 2014-11-28 19:20:10 +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-11-28 09:05:10 +0800

Seen: 52 times

Last updated: Nov 28 '14

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