0

How to inform Composer on selected item in combobox ?

asked 2009-12-02 06:31:09 +0800

marioosh gravatar image marioosh
75 1 3

How to get in MyComposer which item is selected from combobox ? I get null :(

<window id="autowin" apply="ui.MyComposer">
	<combobox id="combo" selectedIndex="@{autowin$MyComposer.selected}"/>
</window>

public class AutoComposer extends GenericForwardComposer {
            Object selected;

	public void onChanging$combo(Event evt) {
		System.out.println(selected); // null
	}
}

delete flag offensive retag edit

12 Replies

Sort by » oldest newest

answered 2011-06-08 21:14:37 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

If you set a model to the combobox, you can set the selection to model,
please refer to the component reference.

link publish delete flag offensive edit

answered 2011-06-03 23:56:00 +0800

ajaidka gravatar image ajaidka
196 4

Thanks caclark

I tried this way before, but control was not coming in onCreate method, reason could be I declared this method without 'ForwardEvent' paramater. Will try this too.

Meanwhile, there is another way around :
In .zul file
<combobox id="billCountry"
onCreate="self.setSelectedIndex(editCompanyInfoWin$composer.getCurrentBillCountryIndex())">
.....
.....
</combobox>


Many thanks,
AJaikda

link publish delete flag offensive edit

answered 2011-06-03 19:21:34 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

Hook the onCreate event of that component in your composer and do whatever you need to do...

public void onCreate$myComponentId(ForwardEvent event)
{
    ((Listbox)event.getOrigin()).setSelectedIndex(....)
}

link publish delete flag offensive edit

answered 2011-06-03 04:30:12 +0800

ajaidka gravatar image ajaidka
196 4

Can I pass some variable in onCreate='self.setSelectedIndex(0); instead of Zero. I want to pick this value from composer.

Any idea?

link publish delete flag offensive edit

answered 2009-12-04 03:24:03 +0800

marioosh gravatar image marioosh
75 1 3

updated 2009-12-04 03:24:33 +0800

Thank You very much as1225 :)

link publish delete flag offensive edit

answered 2009-12-04 01:21:15 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

<combobox onCreate='self.setSelectedIndex(0);'>

link publish delete flag offensive edit

answered 2009-12-04 01:04:01 +0800

marioosh gravatar image marioosh
75 1 3

updated 2009-12-04 01:04:24 +0800

My combo another:

<combobox id="autoType">
	<comboitem label="osobowy" value="0"/>
	<comboitem label="ciężarowy" value="1"/>
</combobox>


How to set first value selected by default ?

I've tried:
<combobox id="autoType" selectedIndex="0">


and in composer:
combo.setSelectedIndex(0);


but i get index out of bounds. (org.zkoss.zk.ui.UiException: Out of bound: 0 while size=0)

link publish delete flag offensive edit

answered 2009-12-04 00:17:53 +0800

baskaraninfo gravatar image baskaraninfo
526 2 2 9

As said by as1225, you can set the combobox as readonly.
So, users can only choose from the available options.

link publish delete flag offensive edit

answered 2009-12-03 18:52:11 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi,marioosh
you can try

<zk>
 <combobox id="cb" >
     <comboitem label="Simple and Rich"/>
     <comboitem label="Cool!"/>
     <comboitem label="Ajax and RIA"/>
 </combobox>
<button label="readonly" onClick='cb.setReadonly(true);'/>
<button label="disable" onClick='cb.setDisabled(true);'/>
<button label="edit" onClick='cb.setReadonly(false);cb.setDisabled(false);'/>

</zk>

link publish delete flag offensive edit

answered 2009-12-03 04:02:47 +0800

marioosh gravatar image marioosh
75 1 3

updated 2009-12-03 04:09:32 +0800

I have another question: How to block user for input something isn't in combobox ? :)
Do I have to do it myself or is there any method in api which does that ?

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-12-02 06:31:09 +0800

Seen: 4,607 times

Last updated: Jun 08 '11

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