0

Populating listbox from GenericForwardComposer

asked 2010-06-15 02:09:26 +0800

Arsen gravatar image Arsen
383 4

Houston, we've had a problem here)))
Hi, folks. I've got some strange behaviour while populating listbox from Composer.
zul

<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<zk xmlns="http://www.zkoss.org/2005/zul">

<window id="myWindow" border="none" apply="${myComposer}">
      <listbox id="utilityList" fixedLayout="true" vflex="true">
          <listhead>
            <listheader label="Position"/>
            <listheader label="Name"/>
         </listhead>
         <listitem self="@{each=utility}">
              <listcell label="@{utility.position}"/>
             <listcell label="@{utility.name}"/>
          </listitem>
</window>

and Composer

public void doAfterCompose(..){
    ... 
     List<Utility> utiliteis = ...
     utilityList.setModel(new BindingListModelList(utilities, true));

listbox on page is populated, but it has only one column with wich is populated with utility.toString() values. I seems that

         <listitem self="@{each=utility}"> 
              <listcell label="@{utility.position}"/>
             <listcell label="@{utility.name}"/>
          </listitem>

has not been applied.

But at the same time, if I use controller ("use" atribute) instead of composer ("apply" attribute), it works perfect: 2 columns with correct values.
I can use renderer in composer (utilityList.setItemRenderer(...)), but why can't I use databinding?

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2010-06-15 02:17:44 +0800

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

Look here

Stephan

link publish delete flag offensive edit

answered 2010-06-15 02:56:42 +0800

Arsen gravatar image Arsen
383 4

Thanks for reply, Stephan.
But I'm a little bit confused with code label="${c:l('Customer.Matchcode')}". Is it a way to defining renderer? Where is variable "Customer" defined? Maybe your code provide me some links to tutorial?
I'm setting new model for listbox not only inside afterCompose, but also anytime in GUI event, when I need to refresh data in listbox. Will it be problem?

link publish delete flag offensive edit

answered 2010-06-15 03:39:49 +0800

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

updated 2010-06-15 03:47:11 +0800

label="${c:l('Customer.Matchcode')}" is only for localisation see <?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
--------------------------------------------

Seems you mix it. Why not declare the model for the listbox in the zul and start the init of it in the onCreate() event.

1. in zul-template use an Alias name for the controller
model="@{controller.customers}"

        		<listbox id="listBoxCustomer"
					model="@{controller.customers}"
					selectedItem="@{controller.selectedCustomer}" vflex="true"
					tooltiptext="${c:l('listbox.tooltiptext')}" width="99.9%"
					height="100%" multiple="false">
					<listhead sizable="true">
						<listheader id="listheader_CstNo"
							image="/images/icons/builder.gif"
							label="${c:l('Customer.CustomerNo')}" sort="auto" width="10%" />
                                       .  .  .

					<listitem id="listBoxCustomerListItem"
						self="@{each='customer'}" value="@{customer}"
						forward="onDoubleClick=onDoubleClickedCustomerItem">

						<listcell label="@{customer.customerNo}"
							style="text-align: right" />
.  .  .


2. in afterComposer set the AliasName for the controller / so Zkoss replaced it by processing

	
        @Override
	public void doAfterCompose(Component window) throws Exception {

		super.doAfterCompose(window);

		/**
		 * Set an 'alias' for this composer name in the zul file for access.<br>
		 * Set the parameter 'recurse' to 'false' to avoid problems with
		 * managing more than one zul-file in one page. Otherwise it would be
		 * overridden and ends in curious error messages.
		 */
		if (self != null)
			self.setAttribute("controller", this, false);
	}

3. in onCreate init the Model and get the Binder/ loadAll

      // Instance Vars

     // Databinding
      private AnnotateDataBinder binder;
      private BindingListModelList customers; // + getters/setters
      private Customer selectedCustomer;


	public void onCreate$windowCustomerList(Event event) throws Exception {

		binder = (AnnotateDataBinder) event.getTarget().getAttribute("binder", true);

                setCustomers( myDBService().findAllCustomers() );

		binder.loadAll();
            }


to 3. I started most time to select the first row by init of the list programmatically.

	public void onCreate$windowCustomerList(Event event) throws Exception {

		binder = (AnnotateDataBinder) event.getTarget().getAttribute("binder", true);

		// Set the BindingListModel
		getPagedBindingListWrapper().init(searchObj, getListBoxCustomer(), pagingCustomerList);
		BindingListModelList lml = (BindingListModelList) getListBoxCustomer().getModel();
		setCustomers(lml);

		// check if first time opened and init databinding for selectedBean
		if (getSelectedCustomer() == null) {
			// init the bean with the first record in the List
			if (lml.getSize() > 0) {
				int rowIndex = 0;
				// only for correct showing after Rendering. No effect as an
				// Event
				// yet.
				getListBoxCustomer().setSelectedIndex(rowIndex);
				// get the first entry and cast them to the needed object
				setSelectedCustomer((Customer) lml.get(0));

				// call the onSelect Event for showing the objects data in the
				// statusBar
				Events.postEvent("onSelect", getListBoxCustomer(), getSelectedCustomer());
			}
		}

		binder.loadAll();
}


Stephan

link publish delete flag offensive edit

answered 2010-06-15 03:56:47 +0800

Arsen gravatar image Arsen
383 4

Thank you, Stephan, for you attention to my problem. Now it'clear, I'll try this solution.

link publish delete flag offensive edit

answered 2010-06-15 12:36:11 +0800

Arsen gravatar image Arsen
383 4

OK, here is investigation result: my binding

  <listitem self="@{each=utility}">
              <listcell label="@{utility.position}"/>
             <listcell label="@{utility.name}"/>
</listitem>

is applied only if I set model not in AfterCompose method. So I've made a little trick
@Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);
        self.addEventListener(Events.ON_CREATE, new EventListener() {

            public void onEvent(Event event) throws Exception {
                presenter.setView(UtilityListComposer.this);
            }
        });

    }

Hope this would help someone.

link publish delete flag offensive edit

answered 2010-06-16 00:01:57 +0800

argopinathyadav gravatar image argopinathyadav
12

Jun 04, 2010



hi,
Anybody can tell me how to play the wav file from client .actually my wav files are stored in my server in d drive. now i have to play the wav file from the client system. how can i set the wav file path in zk player. if anybody knows pzl tell me.
my mail id [email protected]


Thanks in Advance
Gopinath yadav a.r

link publish delete flag offensive edit

answered 2010-06-16 01:15:56 +0800

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

please open a new thread for your question.

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: 2010-06-15 02:09:26 +0800

Seen: 692 times

Last updated: Jun 16 '10

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