0

ListBox Refresh

asked 2010-02-04 00:50:21 +0800

techvts gravatar image techvts
120 2 5

Hi all,

I am trying to refresh a listbox(in one zul) from another zul .. i do this by setting the model of list box , when i
do so object values r reflected in single column in listbox instead of actual values in all columns of row , how
can solve this ? Plz help ..
I cannot redirect the first zul page as it has other components with listbox.

Code

//First zul

<?page id="Main_MI" title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window id="wind1" title="Material Inward" border="normal" style="margin:10px" >
<listbox id="MIitemListview" model="${mySList}" mold="paging" pageSize="10"
multiple="true" width="100%"
rows="${DCount}" >

<listhead sizable="true">

<listheader label="Sr. No." sort="auto(id)"/>
<listheader label="Name" sort="auto(name)"/>
<listheader label="Discount Amt"/>
<listheader label="Discount %"/>
<listheader label="Active"/>
<listheader label="Description" />
<listheader label="Bunit Name"/>
<listheader label="Created By"/>
<listheader label="Created On"/>
<listheader label="Updated By"/>
<listheader label="Updated On"/>
</listhead>
<listitem self="@{each=mySList}" >

<listcell label="@{mySList.discountid}" />
<listcell label="@{mySList.name}" />
<listcell label="@{mySList.disamt}" />
<listcell label="@{mySList.disperc}"/>
<listcell label="@{mySList.isactive}" />
<listcell label="@{mySList.description}" />
<listcell label="@{mySList.bunitCmb}"/>
<listcell label="@{mySList.createdby}" />
<listcell label="@{mySList.createdon}" />
<listcell label="@{mySList.updatedby}"/>
<listcell label="@{mySList.updatedon}"/>
</listitem>
</listbox>
</window>
</zk>


//Second Zul - on a button click refreshfunc() is called


public void refreshfunc()
{

Listbox usersListbox = ((Listbox)Path.getComponent("//Main_MI/wind1/div3").getChildren().get(1));
List l = d.getAllDiscount();
ListModel x = new SimpleListModel(l);
usersListbox.setModel(x);
addMIitemWin.detach();

}

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2010-02-22 19:26:56 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

I think the correct component path should be //Main_MI/wind1/MIitemListview

link publish delete flag offensive edit

answered 2010-02-23 02:22:05 +0800

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

updated 2010-02-23 02:28:29 +0800

I am trying to refresh a listbox(in one zul) from another zul .. i do this by setting the model of list box,  when i 
do so object values r reflected in single column in listbox instead of actual values in all columns of row

I work in the following way:

1. In the case of refreshing a row in a listbox that are created in an other zul-file i 'overhanded' a reference to these listbox component to the zul-file
that will do the refresh. I put these reference in a map and create the second zul-file with this map.
Executions.createComponents("secondZulfile.zul", parent, map).
Your way should work well too. You must check/debug if you have the correct path to your listbox.

		/*
		 * We can call our Dialog zul-file with parameters. So we can call them
		 * with a object of the selected item. For handed over these parameter
		 * only a Map is accepted. So we put the object in a HashMap.
		 */
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("branche", aBranche);
		/*
		 * we can additionally handed over the listBox, so we have in the dialog
		 * access to the listbox Listmodel. This is fine for synchronizing the
		 * data in the customerListbox from the dialog when we do a delete, edit
		 * or insert a customer.
		 */
		map.put("lbBranch", listBoxBranch);

		// call the zul-file with the parameters packed in a map
		try {
			Executions.createComponents(
					"/WEB-INF/pages/branch/branchDialog.zul", null, map);
		} catch (Exception e) {
                }


2. In the second zul-file i read back the param and cast them to listbox

        .  .  .
	// not wired vars
	private Listbox lbBranch; // overhanded per param
        .  .  .

       public void onCreate$mySecondZulWindow(Event event){
       . . .
		// get the params map that are overhanded by creation.
		Map<String, Object> args = getCreationArgsMap(event);
                . . .

		// we get the listBox Object for the branch list. So we have access
		// to it and can synchronize the shown data when we do insert, edit or
		// delete branches here.
		if (args.containsKey("lbBranch")) {
			lbBranch = (Listbox) args.get("lbBranch");
		} else {
			lbBranch = null;
		}

3. For refreshing a single row in the listbox i search the object to refresh in the ListModel and refresh only this object.

Insert/Modify a object in the listboxes model:

			// now synchronize the branches listBox
			ListModelList lml = (ListModelList) lbBranch.getListModel();

			// Check if the branch object is new or updated
			// -1 means that the object is not in the list, so it's new.
			if (lml.indexOf(aBranche) == -1) {
				lml.add(aBranche);
			} else {
				lml.set(lml.indexOf(aBranche), aBranche);
			}



Remove a object in the listboxes model
:

				// now synchronize the branches listBox
				ListModelList lml = (ListModelList) lbBranch.getListModel();

				// Check if the branch object is new or updated
				// -1 means that the object is not in the list, so it's
				// new.
				if (lml.indexOf(aBranche) == -1) {
				} else {
					lml.remove(lml.indexOf(aBranche));
				}


best
Stephan

link publish delete flag offensive edit

answered 2012-06-12 04:48:14 +0800

muha gravatar image muha
15

updated 2012-06-12 04:54:45 +0800

hey, I've got a problem updating listbox too. I want to update the listbox when submit button is clicked. the listbox initially consists of a list of JSONObject, after submit button clicked, the list elements changed and the listbox should update with the change but I can't do this. can you help me upadate the listbox?
this is how I put the list of JSONObject in the listbox

<listbox id="userListbox">
    <listhead>
        <listheader label="Id"></listheader>
        <listheader label="Name"></listheader>
        <listheader label="Address"></listheader>
        <listheader label="Phone"></listheader>
    </listhead>
    <listitem forEach="${userController.list}">
        <listcell label="${each.id}" ></listcell>
        <listcell label="${each.name}" ></listcell>
        <listcell label="${each.address}" ></listcell>
        <listcell label="${each.phone}" ></listcell>
    </listitem>
</listbox>

in class UserController:

private List<JSONObject> list;

@Listen("onClick = #submitButton")
public void onSubmit(Event event) {
    loadUser();
}

private void loadUser() {
    JSONObject input = new JSONObject();
    input.put("name", nameBox.getText());

    list = getUserList(input);
}

public List<JSONObject> getList() {
    return list;
}

public void setList(List<JSONObject> list) {
    this.list = list;
}

how to update the listbox? thank you in advance.

link publish delete flag offensive edit

answered 2012-06-13 14:59:52 +0800

twiegand gravatar image twiegand
1807 3

muha,

I think the main reason for your problem is that you are using Expression Language (EL) for your data.  EL only gets evaluated once and very early in the page's life cycle.  For that reason alone, your data will never be updated after pressing a button.

You need to switch to data binding (e.g. using @ instead of $).  There are lots of examples on the ZK site or in this forum.

Regards,

Todd

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-02-04 00:50:21 +0800

Seen: 4,001 times

Last updated: Jun 13 '12

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