0

Checkbox inside Listcell

asked 2010-06-16 02:27:06 +0800

drishtisv gravatar image drishtisv
135 2

updated 2010-06-17 02:14:00 +0800

Hi all

Is any example on following?
he
I am trying to write a code, Listbox will fill with table data using annotation binding. In a listbox a column having a boolean type. user will check/uncheck serially or randomly. After finishing the user work user will click the button and the check /uncheck data will commited to table.

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2010-06-17 02:27:37 +0800

Arsen gravatar image Arsen
383 4

Something like this

<listbox model="@{model}">
   <listhead>
      <listheader label="Boolean column"/>
      <listheader label="Other column"/>
   </listheader>
   <listitem self="@{each=v}">
      <listcell><checkbox checked="@{v.<your boolean property>}"/></listcell>
      <listcell label="@{v.someOtherProperty}"/>
   </listitem>
</listbox>

And inside onClick event of button you retrieve modified objects from listbox's model and put them into db.

link publish delete flag offensive edit

answered 2010-06-17 05:12:54 +0800

drishtisv gravatar image drishtisv
135 2

updated 2010-06-17 08:07:46 +0800

Thanks Arsen

I am newbie can you tell me how to retrieve modified objects from listbox's model.

Thanks in an advance

link publish delete flag offensive edit

answered 2010-06-19 02:07:01 +0800

drishtisv gravatar image drishtisv
135 2

Hi Arsen,

I tried please look at my zul file

<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="sys_logins"?>

<zk>
<window id="sys_logins" title="User Master" closable="true" border="normal" xmlns:a="http://www.zkoss.org/2005/zk/annotation" height="100%" contentStyle="overflow:auto">
<style src="/css/single_de.css"/>
<zscript>
<![CDATA[
import com.drishti.Admin.MstUserRegistration;

com.drishti.Admin.MstUserRegistration user = new com.drishti.Admin.MstUserRegistration();
List users = user.UserList();


com.drishti.Admin.UserMenuAssignController usrmenu = new com.drishti.Admin.UserMenuAssignController();
List usrmenulist = usrmenu.UsermenuList(user.getUser_id());
]]>
</zscript>
<hbox>
<vbox width="20%">
<listbox id="lbuserlist" rows="10" model="@{users}" selectedItem="@{user}" onSelect="clickProc(self.getSelectedItem())" >
<listhead>
<listheader label="User" sort="auto"/>
</listhead>

<listitem self="@{each='user'}" value="@{user}">
<listcell label="@{user.user_id}"/>
</listitem>
</listbox>
</vbox>
<grid>
<rows>
<row>
<vbox width="79%">
<hbox align="start" width="30%">
<button id="updateallRec" label="Update" onClick="Update_all()" />
</hbox>
</vbox>
</row>
<row>
<vbox width="79%">
<listbox id="usrmenulst" width="100%" model="@{usrmenulist}" >
<listhead>
<listheader label="Assigned" />
<listheader label="Menu"/>
<listheader label="Menu Item" />
</listhead>
<listitem id="liusrmenu" self="@{each='usrmenu'}" value="@{usrmenu}">
<listcell id="chkbox">
<!-- <checkbox id="chkb_assigned" checked="@{usrmenu.assigned}"
onCheck="usrmenu.setAssigned(self.checked);if(self.checked){self.parent.setLabel(String.valueOf('Y'));} else {self.parent.setLabel(String.valueOf('N'));};"/>
-->
<checkbox id="chkb_assigned" checked="@{usrmenu.assigned}"/>
</listcell>
<listcell label="@{usrmenu.menu_name}"/>
<listcell label="@{usrmenu.menu_item_name}"/>
</listitem>
</listbox>
</vbox>
</row>
</rows>
</grid>
</hbox>


<zscript>
<![CDATA[
import java.util.*;
import com.drishti.Admin.MstUserRegistrationTable;
import org.zkoss.zul.*;
import org.zkoss.zul.Checkbox;
import org.zkoss.zul.event.*;
import org.zkoss.zkplus.databind.*;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listitem;

public void Update_all()
{
for (int i = 0;i < usrmenulst.getItemCount(); i++) {
Boolean lm = Boolean.valueOf(usrmenulst.getModel().getElementAt(i).toString());
// Listitem li = usrmenulst.getItems().get(i); // get list items from usrmenulst ListBox
alert(lm);
// alert(li.getChildren().get(0).getLabel()); Will Get Listcell value
}
alert("Record Updated ....");
}

public void clickProc(Listitem selItem)
{
// alert(user.getUser_id());
// alert(usrmenu.UsermenuList(user.getUser_id()).size());
model = ListModelList.instance(usrmenu.UsermenuList(user.getUser_id()));
usrmenulst.setModel(model);
}

]]>
</zscript>
</window>
</zk>


Every time I get the "false" value of lm at Update_all()

link publish delete flag offensive edit

answered 2010-06-19 03:35:06 +0800

Arsen gravatar image Arsen
383 4

Strange code

Boolean lm = Boolean.valueOf(usrmenulst.getModel().getElementAt(i).toString());

I guess it should be something like this
Boolean lm = ((UserMenu)usrmenulst.getModel().getElementAt(i)).getAssigned()

or do I miss something?

link publish delete flag offensive edit

answered 2010-06-19 06:40:15 +0800

drishtisv gravatar image drishtisv
135 2

updated 2010-06-19 06:43:02 +0800

Thank you very much Arsen

it works after replacing following statement.



Boolean lm = (usrmenulst.getModel().getElementAt(i)).getAssigned();


can you explain me. How it is works? bcoz i m confused

Thanks in advance

link publish delete flag offensive edit

answered 2010-06-19 07:26:38 +0800

Arsen gravatar image Arsen
383 4

Listbox has model, it some kind of collection of elements which are shown on listbox.
here you assigning this collection to listbox. usrmenulst - listbox, usrmenulist - it's model. Names are very similar, so it's a little bit confusing. I suggest it's better to rename model variable.

<listbox id="usrmenulst" width="100%" model="@{usrmenulist}" >

If model defines what to show (in our case it's collection of UserMenu objects) , the another object - renderer - defines how to show
<listitem id="liusrmenu" self="@{each='usrmenu'}" value="@{usrmenu}">
  <listcell> <!-- no need for id attribute here --> 
  <checkbox checked="@{usrmenu.assigned}"/> <!-- no need for id attribute here --> 
   </listcell> 
  <listcell label="@{usrmenu.menu_name}"/>
  <listcell label="@{usrmenu.menu_item_name}"/>
</listitem>

<checkbox checked="@{usrmenu.assigned}"/> - here you bind checkbox state to property "assigned" of MenuItem object returned by model.
So usrmenulst.getModel().getElementAt(i) - returns element with index i from model of listbox. This element is instance of MenuItem. To get checkbox's state, should check binded property of MenuItem element -getAssigned()

You can also read on this site lot of good tutorials and smalltalks about listmodel's and databinding.

Hope this helps.

link publish delete flag offensive edit

answered 2010-06-19 08:42:36 +0800

drishtisv gravatar image drishtisv
135 2

Thank you Arsen

Now it is cleared.

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-16 02:27:06 +0800

Seen: 671 times

Last updated: Jun 19 '10

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