-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have created a dynamic tree. I am able to add the nodes dynamically.
But the problem is that I am unable to save in database.
What is the way to do so?
Pls help as i am new to ZUL.
Hi,cros
Could you post your sample code
how did you add the nodes? maybe you can get the new node in add function and save it in DB
//jimmy
Hi Jimmy,
This is my ZUL file (clientList.zul) ---
<?xml version="1.0" encoding="UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?page zscriptLanguage="GroovyGrails"?>
<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">
<include src="/topmenu.zul"/>
<window id="clientWin" width="99%" height="93%" border="normal" apply="ClientNewComposer">
<borderlayout>
<north border="none">
<label id="statusBar"/>
</north>
<west size="20%"> <!-- splittable="true" flex="true" -->
<vbox spacing="0" width="100%" >
<menubar id="submenubarlist" orient="horizontal" >
<menuitem id="menuNew" label="New" />
</menubar>
<tree id="treeClient" >
<treechildren>
<treeitem open="false" value="1">
<treerow draggable="true" onDrop="move(event.dragged)" >
<treecell label="Hospital" />
</treerow>
<treechildren>
<treeitem value="2">
<treerow draggable="true" >
<treecell label="Hospital1" />
</treerow>
</treeitem>
<treeitem value="3">
<treerow draggable="true">
<treecell label="Hospital2" />
</treerow>
</treeitem>
</treechildren>
</treeitem>
<treeitem open="false" value="4">
<treerow draggable="true" onDrop="move(event.dragged)">
<treecell label="Clinic" />
</treerow>
<treechildren>
<treeitem value="5">
<treerow draggable="true">
<treecell label="Clinic1" />
</treerow>
</treeitem>
<treeitem value="6">
<treerow draggable="true">
<treecell label="Clinic2" />
</treerow>
</treeitem>
</treechildren>
</treeitem>
<treeitem open="false" value="7">
<treerow droppable="true"
onDrop="move(event.dragged)">
<treecell label="Lab" />
</treerow>
<treechildren>
<treeitem value="8">
<treerow draggable="true">
<treecell label="Lab1" />
</treerow>
</treeitem>
<treeitem value="9">
<treerow draggable="true">
<treecell label="Lab2" />
</treerow>
</treeitem>
</treechildren>
</treeitem>
<treeitem open="false" value="10">
<treerow droppable="true"
onDrop="move(event.dragged)">
<treecell label="Facility" />
</treerow>
<treechildren>
<treeitem value="11">
<treerow draggable="true">
<treecell label="Facility1" />
</treerow>
</treeitem>
<treeitem value="12">
<treerow draggable="true">
<treecell label="Facility2" />
</treerow>
</treeitem>
</treechildren>
</treeitem>
</treechildren>
</tree>
</vbox>
</west>
<center>
<vbox spacing="0">
<menubar id="submenubaredit" orient="horizontal">
<menuitem id="menuSave" label="Save" />
</menubar>
<tabbox>
<tabs>
<tab id="tabMain" label="Main"/>
</tabs>
<tabpanels>
<tabpanel> <vbox spacing="0" width="100%">
<!--Hospital Menu starts-->
<label value="Hospitals" id="nameHospital"/>
<hbox spacing="0" id="boxHospital">
<vbox spacing="0">
<menubar id="subsubmenubarHospitalEdit" orient="horizontal">
<menuitem id="menuSaveHospital" label="Add" />
</menubar>
<listbox id="gridCtlHospitalItem">
<listhead sizable="true">
<listheader label="Name"/>
<listheader label="Value"/>
</listhead>
<listitem><listcell>Type:</listcell> <listcell><combobox id="HospitalType" autodrop="true"/></listcell></listitem>
<listitem><listcell>Name:</listcell><listcell><textbox id="HospitalName" /></listcell> </listitem>
<listitem><listcell>Parent:</listcell> <listcell><textbox id="HospitalParent" /></listcell></listitem>
<listitem><listcell>Billable:</listcell> <listcell><checkbox id="HospitalBillable"/></listcell></listitem>
</listbox>
</vbox>
</hbox>
<!--Hospita Menu ends-->
</vbox></tabpanel>
</tabpanels>
</tabbox>
</vbox>
</center>
</borderlayout>
<zscript ><![CDATA[
void move(Component dragged) {
self.parent.insertBefore(dragged, self.getNextSibling());
self.appendChild(dragged);
}
treeClient.onSelect = { ev ->
Treeitem itemSelected = treeClient.getSelectedItem()
def id = itemSelected.label
nameHospital.value=id
enableEditControls(false)
}
getselectedClient = {
Treeitem itemSelected = treeClient.getSelectedItem()
if(itemSelected == null)
return null
def id = itemSelected.label
return Client.get(id)
}
setEditValues = {
def client = new Client();
HospitalType.value=client.type;
HospitalName.value=client.name;
HospitalParent.value=client.parent;
HospitalBillable.checked= client.billable;
System.out.println("EXITING setEditValues Client");
}
menuNew.onClick = { ev ->
enableEditControls(false)
nameHospital.setVisible(false)
clearEditValues()
statusBar.value = "Ready"
}
getEditValues = { client ->
client.type=HospitalType.value;
client.name=HospitalName.value;
client.parent=HospitalParent.value;
client.billable=HospitalBillable.checked;
}
clearEditValues = {
HospitalType.value = null
HospitalName.value = null
HospitalParent.value = null
HospitalBillable.checked = false
}
menuSave.onClick = { ev ->
Treeitem itemSelected = treeClient.getSelectedItem()
if(itemSelected == null)
return null
def id = itemSelected.value
def client=Client.get(id)
if (client == null)
client = new Client();
getEditValues(client)
client.save();
}
// Main Client Edit Area
enableEditControls = { e ->
nameHospital.setVisible(true)
}
// Main init routine
init = {
HospitalType.setModel(new SimpleListModel(Client.constraints.type.inList))
enableEditControls(false)
HospitalParent.setDisabled(true)
nameHospital.setVisible(false)
statusBar.value = "Ready"
}
init()
]]></zscript>
</window>
</zk>
=======================
and below is my java file (ClientNewComposer.java) ---
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.*;
import java.util.*;
public class ClientNewComposer extends GenericForwardComposer {
private Textbox HospitalName,HospitalParent;
private Tree treeClient;
private Label statusBar;
private Label nameHospital;
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
}
public void onClick$menuSaveHospital() {
String parentName=nameHospital.getValue();
Treeitem parent = null;
boolean flag=true;
for(Object treeItem:treeClient.getItems()){
Treerow treeRow = ((Treeitem)treeItem).getTreerow();
Treecell treeCell = (Treecell)treeRow.getFirstChild();
if(treeCell.getLabel().equals(parentName)){
parent = (Treeitem)treeItem;
break;
}else flag=false;
}
//check if a Client is selected or not.
if(flag==false && parent == null){
statusBar.setValue("Error: Please select a Client");
return;
}
//if client is not null and client is selected
if (flag==false && HospitalName.getValue()!=""){
statusBar.setValue("Client added successfully");
}
// if Client name is kept blank
if (HospitalName.getValue()==""){
statusBar.setValue("Error: Please enter Client name");
HospitalName.setValue("");
HospitalName.setFocus(true);
return;
}
//check for duplicate nodes
Treeitem currentItem=null;
Treechildren children = treeClient.getTreechildren();
if (children != null) {
for (Object o: children.getItems()) {
Treeitem child = (Treeitem) o;
if(child.getLabel().equals(HospitalName.getValue())){
statusBar.setValue("Duplicate : Client ["+HospitalName.getValue()+"] already exists");
return;
}
}
}
Treechildren treeChildren = parent.getTreechildren();
if(treeChildren == null){
treeChildren = new Treechildren();
parent.appendChild(treeChildren);
}
Treeitem ti =new Treeitem();
Treerow tr = new Treerow();
tr.appendChild(new Treecell(HospitalName.getValue()));
tr.setParent(ti);
treeChildren.appendChild(ti);
}
}
=======
I have to save the values of the details(like Type,Name,Parent,Billable) of a particular node i.e any Client into Database. Can u help me?
Asked: 2009-10-07 14:02:01 +0800
Seen: 199 times
Last updated: Oct 08 '09