2

Anyone Give Pure Java Binding example with Listbox?

asked 2012-12-06 13:10:27 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Anyone Have Zk databinding example with listbox? I dont want to use @bind in Zul file rather than i will want to a example Binding of Listcell value from Java Code.
Thanks in Advance.

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2012-12-06 13:46:11 +0800

gganassin gravatar image gganassin flag of Luxembourg
540 6
http://www.hybris.com/

updated 2012-12-06 13:46:27 +0800

http://books.zkoss.org/wiki/ZK_Component_Reference/Data/Listbox#Auto-sorting_on_Fields

Here (and in many other places within the forum & docs) you can find example of the old Java bindings.
If you have a more specific complex scenario to implement... please try to describe it better :)

Giovanni

link publish delete flag offensive edit

answered 2012-12-06 15:13:42 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

THanks for your reply i describe my problem Here. If you some demo sample please let me know
thanks

link publish delete flag offensive edit

answered 2012-12-06 16:42:28 +0800

gganassin gravatar image gganassin flag of Luxembourg
540 6
http://www.hybris.com/

updated 2012-12-06 16:45:38 +0800

I'd say you have 2 ways:

<?xml version="1.0" encoding="UTF-8"?>
<zk>
	<vlayout apply="demo.ListboxBindComposer" width="300px">
		<label value="Way one" ></label>
		<listbox model="@{persons}" itemRenderer="demo.ListboxBindRenderer" height="300px" ></listbox>
		<space height="5px" ></space>
		<label value="Way two" ></label>
		<listbox model="@{persons}" height="300px">
			<listitem self="@{each='person'}">
				<listcell>
					<textbox hflex="1" value="@{person.name}" inplace="true" ></textbox>
				</listcell>
			</listitem>
		</listbox>
		<button label="check" forward="onClick=onCheckMe" ></button>
	</vlayout>
</zk>

public class ListboxBindComposer extends GenericForwardComposer {

	private AnnotateDataBinder binder;

	private List<Person> persons = new ArrayList<Person>() {
		{
			add(new Person("Giovanni"));
			add(new Person("Lorenzo"));
			add(new Person("Enrico"));
		}
	};

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		this.binder = new AnnotateDataBinder(comp);
		this.binder.bindBean("persons", persons);
		this.binder.loadAll();
		
	}

	public void onCheckMe(ForwardEvent event) {
		for (Person person : this.persons) {
			System.out.println(person.getName());
		}
	}
}

public class ListboxBindRenderer implements ListitemRenderer<Person> {

	@Override
	public void render(Listitem item, final Person person, int index) throws Exception {
		item.setValue(person);

		Textbox tb = new Textbox();
		tb.setValue(person.getName());
		tb.addEventListener(Events.ON_CHANGE, new EventListener<InputEvent>() {
			@Override
			public void onEvent(InputEvent ie) throws Exception {
				Component target = ie.getTarget();
				if(target instanceof Textbox) {
					person.setName(((Textbox)target).getValue());
				}
			}
		});
		tb.setHflex("1");
		
		Listcell cell = new Listcell();
		cell.appendChild(tb);
		
		item.appendChild(cell);
	}

}

A third way should be something like in the renderer:

		Map<String, String[]> args = new HashMap<String, String[]>();
		args.put("value", new String[] { "each.name" });
		tb.addAnnotation("value", "bind", args);

But i never understood why is not working to be honest ;D
hope it helps anyway!
Giovanni

link publish delete flag offensive edit

answered 2012-12-06 17:22:51 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Thanks For your example and reply,
Let me explain you my problem in details .I have a Listbox which is creating by Java Code

getItemRendered()

Is creating Listbox for me now ...
public ListitemRenderer getItemRenderer() {
		ListitemRenderer _rowRenderer = null;
		if (_rowRenderer == null) {
			_rowRenderer = new ListitemRenderer() {
				public void render(Listitem row, Object data, int index) throws Exception {
					final TaskListData dataBean = (TaskListData) data;

					if (_selected != null) {

						for (Object obj : _selected) {
							if ("Type".equals(obj))
								new Listcell(dataBean.getFolderType()).setParent(row);
							else if ("Sub Type".equals(obj))
								new Listcell(dataBean.getSubType()).setParent(row);
							else if ("F.P.".equals(obj))
								new Listcell(dataBean.getFolderPriority().toString()).setParent(row);
							else if ("P.P.".equals(obj)) {
								Listcell cell = new Listcell();
								Intbox intbox = new Intbox();
								intbox.setInplace(true);
								intbox.setMaxlength(3);
								if (dataBean.getProcessPriority() != null && !dataBean.getProcessPriority().trim().equals(""))
									intbox.setValue(Integer.parseInt(dataBean.getProcessPriority()));
								cell.appendChild(intbox);
								row.appendChild(cell);
							} else if ("Process".equals(obj))
								new Listcell(dataBean.getProcessName()).setParent(row);
							else if ("Status".equals(obj))
								new Listcell(dataBean.getStatus()).setParent(row);
							else if ("Due To Start".equals(obj))
								new DateListcell(dataBean.getDueStartDate()).setParent(row);
							else if ("Due To End".equals(obj))
								new DateListcell(dataBean.getDueEndDate()).setParent(row);
							else if ("Vio".equals(obj))
								new Listcell(dataBean.getViolationFlag()).setParent(row);
							else if ("People Name".equals(obj))
								new Listcell(dataBean.getPeopleName()).setParent(row);
							else if ("Folder Number".equals(obj))
								new Listcell(dataBean.getFolderNumber()).setParent(row);
							else if ("Reference File #".equals(obj))
								new Listcell(dataBean.getReferenceFile()).setParent(row);
							else if ("House Number".equals(obj))
								new Listcell(dataBean.getHouseNumber()).setParent(row);
							else if ("Street Name".equals(obj))
								new Listcell(dataBean.getStreetName()).setParent(row);
							else if ("Street City".equals(obj))
								new Listcell(dataBean.getStreetCity()).setParent(row);
							else if ("Inspection Request Comment".equals(obj))
								new Listcell(dataBean.getInspectionRequestComment()).setParent(row);

						}
					}
				}

			};
		}
		return _rowRenderer;
	}

And Here is my Zul page code
<lazyListbox multiple="true" model="@load(vm.model)" vflex="1"
			id="taskList" sizedByContent="true"
			emptyMessage="${a:resource('LABEL_NOROWS')}"
			itemRenderer="@load(vm.itemRenderer)" sclass="con">

			<listhead children="@load(vm.headerList)" sizable="true">
				<template name="children" var="headerName">

					<listheader label="@load(headerName)"></listheader>
				</template>
			</listhead>

</lazyListbox>
My Main problem is that user can change value of any column and when user will click on save button i have to data into databse If i am creating Listbox then it is easy to use @bind with each cell now how can i use bind here and get data when user click on save button after changing any row or cell
Thanks

link publish delete flag offensive edit

answered 2012-12-07 02:00:28 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

@sjoshi,

http://books.zkoss.org/wiki/Small_Talks/2012/August/MVVM_In_Java

link publish delete flag offensive edit

answered 2012-12-07 05:50:28 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Thanks for your reply but here they are updating only single row not multiple row.

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: 2012-12-06 13:10:27 +0800

Seen: 140 times

Last updated: Dec 07 '12

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