0

Databinding with GenericForwardComposer controller issue

asked 2010-06-12 04:08:02 +0800

abosetti gravatar image abosetti
21 2

Hi all

I have a strange problem. ZK5.02 PE Spring.

In the snippet below, the listbox is fed by controllerUser, which is declared as a spring bean and extends the GenericForwardComposer class. The AnnotateDataBinderInit provides automatic databinding for the edit box below. This only works if the listbox declares the
selectedIted as a local variable as this: selectedItem="@{selectedUser}".

If I wish to store the variable in the controller as this
selectedItem="@{controllerUser.selectedUser}", and obviously change the edit box as
<textbox id="username" width="150px" value="@{controllerUser.selectedUser.username,load-when='listUsers.onSelect'}" />

it doesn't work.

The controller barely declares a variable selectedUser and I have tried to also add the onSelect event handler, but nothing changes.

What am I missing?


Below are the relevant parts of my page

Thank you in advance
Alessandro
<?page title="User Manager" contentType="text/html;charset=UTF-8"?>
<?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="userwindow" border="none" apply="${controllerUsers}" width="100%" height="100%" xmlns:a="http://www.zkoss.org/2005/zk/annotation">
......

<listbox id="listUsers" multiple="false" model="@{controllerUsers.allUsers}"
selectedItem="@{selectedUser}"
style="border:none">
<listhead sizable="true">
<listheader id="useridHeader" label="Username" width="150px"/>
<listheader id="adminHeader" label="Admin" width="20px"/>


</listhead>
<listitem self="@{each=zx1}">
<listcell label="@{zx1.username}" />
<listcell label="@{zx1.admin}" />
</listitem>
</listbox>
......

<label value="UserName" width="150px" />
<textbox id="username" width="150px" value="@{selectedUser.username,load-when='listUsers.onSelect'}" />

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2010-06-12 05:09:03 +0800

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

Try to declare an Alias-name for the controller to use in the zul-file.

	// Databinding
	private AnnotateDataBinder binder;
	private CustomerMainCtrl customerMainCtrl;

	// ServiceDAOs / Domain Classes
	CustomerService customerService;
	TenantService tenantService;

	/**
	 * default constructor.<br>
	 */
	public CustomerListCtrl() {
		super();
	}

	@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);
	}

	// +++++++++++++++++++++++++++++++++++++++++++++++++ //
	// +++++++++++++++ Component Events ++++++++++++++++ //
	// +++++++++++++++++++++++++++++++++++++++++++++++++ //

	/**
	 * Automatically called method from zk.
	 * 
	 * @param event
	 * @throws Exception
	 */
	public void onCreate$windowCustomerList(Event event) throws Exception {

		if (logger.isDebugEnabled()) {
			logger.debug("--> " + event.toString());
		}

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

		// get the params map that are overhanded by creation.
		Map<String, Object> args = getCreationArgsMap(event);

		/*
		 * BINDING STUFF:
		 * 
		 * Get the selectedItem from the Mainmodule.
		 */
		if (args.containsKey("mainCustomerController")) {
			setCustomerMainCtrl((CustomerMainCtrl) args.get("mainCustomerController"));

			// SET THIS CONTROLLER TO THE MainController
			getCustomerMainCtrl().setCustomerListCtrl(this);

			// get the selected obj
			// check if this Controller if created on first time. If so,
			// than the selectedCustomer should be null
			if (getCustomerMainCtrl().getSelectedCustomer() != null) {
				setSelectedCustomer(getCustomerMainCtrl().getSelectedCustomer());
			}
		} else {
			setSelectedCustomer(null);
		}

		doFillListbox();
		binder.loadAll();
	}

.
pieces of zul

<?xml version="1.0" encoding="UTF-8"?>
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>

<zk xmlns="http://www.zkoss.org/2005/zul"
	xmlns:h="http://www.w3.org/1999/xhtml"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">

	<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++ -->
	<!-- DataBinding Initiator.                              -->
	<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++ -->
	<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./windowCustomerList" ?>

	<window id="windowCustomerList" apply="${customerListCtrl}"
		border="none" width="100%">

       .  .  .

		
				<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%" />
						<listheader id="listheader_CstMatchcode"
							image="/images/icons/create_doc.gif"
							label="${c:l('Customer.Matchcode')}" sort="auto" width="15%" />
						<listheader id="listheader_CstName1"

                         .  .  .

link publish delete flag offensive edit

answered 2010-06-14 09:28:05 +0800

abosetti gravatar image abosetti
21 2

I still don't understand way, but is working

Thanks a million
Alex

link publish delete flag offensive edit

answered 2010-07-14 13:02:13 +0800

eptx gravatar image eptx
130 3

It would be really helpful to have this rolled into a how-to with explanation. Even better would be a cleaner solution. Too much boilerplate code (and magic) to integrate MVC with data-aware components.

link publish delete flag offensive edit

answered 2010-07-14 14:13:52 +0800

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

take a look at the Javadoc: http://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/util/GenericComposer.html for this paragraph:

since 3.6.1, this composer would be assigned as a variable of the given component per the naming convention composed of the component id and composer Class name. 
e.g. If the applied component id is "xwin" and this composer class is org.zkoss.MyComposer, then the variable name would be "xwin$MyComposer". 
You can reference this composer with Component.getAttributeOrFellow(java.lang.String, boolean) or via EL as ${xwin$MyComposer} of via annotate data 
binder as @{xwin$MyComposer}, etc. If this composer is the first composer applied to the component, a shorter variable name composed of the component id 
and a String "composer" would be also available for use. Per the above example, you can also reference this composer with the name "xwin$composer"

link publish delete flag offensive edit

answered 2010-07-14 16:27:13 +0800

eptx gravatar image eptx
130 3

Still trying to get the UI to bind to a ListModelList 'hits" variable declared in the GenericForwardComposer. When the user enters a value in a textbox, an event listener calls an updateList() method in the composer that populates the hits variable. This works, but the listbox UI bound to hits does not get the new data. This worked well in zscript but migrating to use the composer is proving difficult. Any ideas on how to track this down? Thanks!


  public void doAfterCompose(Component comp) throws Exception {
    super.doAfterCompose(comp);

binder = new AnnotateDataBinder(comp);
binder.bindBean("searchVal", searchVal);
binder.bindBean("hits", hits);
binder.loadAll();

  }



ZUL

<listbox id="hitsbb" rows="20"  model="@{hits}">


link publish delete flag offensive edit

answered 2010-07-15 02:51:55 +0800

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

updated 2010-07-15 02:52:37 +0800

Look at Roberts sample codes No.6 here and correct your codes.

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-12 04:08:02 +0800

Seen: 1,549 times

Last updated: Jul 15 '10

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