-
FEATURED COMPONENTS
First time here? Check out the FAQ!
hi,
I have a listbox in which there are rows..I want when I click on the list row then that perticular listrow should get default font style from its bold state. plz help me
If you're doing it in Java:
Listcell lc = new Listcell(); lstm.appendChild(lc);//lstm is your Listitem final Label lbl = new Label("My content"); lc.appendChild(lbl); lstm.addEventListener("onClick", new EventListener() { public void onEvent(Event e) throws Exception { lbl.setStyle("font-weight:bold;");//or lbl.setSclass("bold"); if you have a specified class called "bold" } });
hi thanks for your reply....actually I wanted the same thing in my zul file but somehow it is not being successful.
on listitem I wrote
onClick="setStyle'(font-weight:bold;')"
but it is throwing an exception.
Hi bhushan2169,
Here's the same thing in zul (tested in Sandbox):
<window title="Listbox" border="normal"> <listbox> <listitem> <attribute name="onClick"><![CDATA[ lbl.setStyle("font-weight:bold;");//or lbl.setSclass("bold"); if you have a specified class called "bold" ]]></attribute> <listcell ><label id="lbl" value="This is my content"/></listcell> </listitem> </listbox> </window>
<listbox id="thelistbox" width="205%" height="200px" model="@{mails}" multiple="false" mold="paging" onSelect="readMail(); replyButton.setVisible(true); forwardButton.setVisible(true)">
<listhead>
<listheader label="Sender" width="250px" />
<listheader label="Subject" width="300px" />
<listheader label="Time" width="400px" />
</listhead>
<listitem id="listit" self="@{each='mail'}" onClick="">
<listcell visible="false">
<label value="@{mail.mail_body}" />
</listcell>
<listcell visible="false">
<label value="@{mail.mail_id}" />
</listcell>
<listcell>
<label id="fromListLable" value="@{mail.mail_from}" style="@{mail.read_unread}"/>
</listcell>
<listcell>
<label id="subjectListLable" value="@{mail.mail_subject}" style="@{mail.read_unread}" />
</listcell>
<listcell>
<label id="timeStampListLable" value="@{mail.timestamp}" style="@{mail.read_unread}" />
</listcell>
<attribute name="onClick"><![CDATA[
fromListLable.setStyle("font-weight:bold;");
]]></attribute>
</listitem>
</listbox>
above is my code.....ITs not working here I dont know why it is giving the error Attempt to resolve method: setStyle() on undefined variable or class name: fromListLable : wht could be the problem??
bhushan2169,
Perhaps I could suggest an alternative approach. Since you are using a listbox and want to make the text of the row bold when a user clicks on it, you can take advantage of the fact that ZK uses a different CSS class when a listbox row is selected.
Simply add this to your zul:
<style> tr.seld,td.seld,tr.z-listitem-seld div.z-listcell-cnt{ font-weight: bold; } </style>
Any time the user selects a row in the listbox, the above style will be applied.
You could also change this into an sclass if you wanted to apply this styling to specific listboxes.
Hope that helps,
Todd
I am sorry I m getting dumber...
i didnt get above code...how do I link this with my list box??? where is the name of the List box and in which tag shlould I put it??
bhushan2169,
Please allow me to illustrate what I mean with an example:
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?> <zk> <zscript> class invItem { private String itemu; private String item; private String itemName; public invItem (String iu, String i, String n ) { itemu = iu; item = i; itemName = n; } public String getItemu() { return itemu; } public void setItemu(String itemu) { this.itemu = itemu; } public String getItem() { return item; } public void setItem(String item) { this.item = item; } public String getItemName() { return itemName; } public void setItemName(String itemName) { this.itemName = itemName; } } List invItems = new ArrayList(); invItems.add(new invItem("SKU18237", "44537", "Lorem ipsum dolor sit amet")); invItems.add(new invItem("SKU21410", "32414", "Ut molestie mattis elit ac posuere")); invItems.add(new invItem("SKU44234", "40855", "Sed imperdiet aliquam augue")); invItems.add(new invItem("SKU32869", "85002", "Vivamus molestie nunc in elit posuere egestas")); invItems.add(new invItem("SKU85002", "66804", "Aliquam commodo, sem at dapibus hendrerit")); invItems.add(new invItem("SKU58119", "58119", "In sit amet turpis eget urna dapibus vehicula")); invItems.add(new invItem("SKU79127", "87138", "Nulla egestas justo non tellus eleifend vel accumsan")); invItems.add(new invItem("SKU21410", "21410", "Quisque id orci ante")); invItems.add(new invItem("SKU58119", "41315", "Donec ac arcu sed mauris rhoncus dictum vel vel arcu")); invItems.add(new invItem("SKU21410", "35128", "Donec ut lacus ut leo dapibus ornare id ac quam")); invItems.add(new invItem("SKU11193", "11193", "Nulla a leo vitae nisl mattis ullamcorper suscipit a metus")); invItems.add(new invItem("SKU34544", "34544", "Vestibulum a eros in diam tincidunt aliquet")); invItems.add(new invItem("SKU85011", "89174", "Nullam bibendum libero imperdiet ipsum sollicitudin sollicitudin")); </zscript> <style> tr.seld,td.seld,tr.z-listitem-seld div.z-listcell-cnt{ font-weight: bold; font-size: 1.5em; } </style> <window> <listbox model="@{invItems}" > <listhead > <listheader label="SKU" /> <listheader label="Item" /> <listheader label="Name" /> </listhead> <listitem id="li1" self="@{each=invItem}"> <listcell label="@{invItem.itemu}"/> <listcell label="@{invItem.item}"/> <listcell label="@{invItem.itemName}"/> </listitem> </listbox> </window> </zk>
As you can see, you do not need to associate the CSS to a listbox or tag because the styling overrides ZK's default.
If you have multiple listboxes on the same page and you need different styling, then I would advise using an sclass that you would attach at the listbox level.
Hope that helps,
Todd
hi thanks for your reply
in my code the style tag has no effect...do I need to add any jar file or edit web.xml or zk.xml file???
I don't believe there is anything additional necessary. I'm assuming you are running ZK 5.x? Sorry, I should have asked that before.
In fact, try going to the ZK sandbox (click here). Once there choose listbox, click view source and then add the following to the top of the displayed code:
<zk> <style> tr.seld,td.seld,tr.z-listitem-seld div.z-listcell-cnt{ font-weight: bold; font-size: 1.5em; } </style>
and this to the end of the code:
</zk>
You will be able to see the results once you click the Try me! button and select a row in the listbox.
Todd
Asked: 2011-09-19 05:51:49 +0800
Seen: 326 times
Last updated: Sep 23 '11