-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I am unable to view the list. Please help me following is the code
.zul
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<zk>
<window id="mst_state" title="State Master" border="normal" xmlns:a="http://www.zkoss.org/2005/zk/annotation">
<zscript>
import com.drishti.masters.StateRegistration;
final com.drishti.masters.StateRegistration state = new com.drishti.masters.StateRegistration();
</zscript>
<portallayout droppable="true" >
<portalchildren>
<panel>
<panelchildren>
<tabbox width="100%" height="100%">
<tabs width="100%" height="100%">
<tab label="Entry" />
<tab label="Search" />
</tabs>
<tabpanels>
<tabpanel>
<grid>
<rows>
<row>
<label value="ID" /> <intbox id="state_id" value="@{state.state_id}"/>
</row>
<row>
<label value="State" /> <textbox id="state_name" value="@{state.state_name}"/>
</row>
<row>
<button label="Save" onClick="save_all()"/>
</row>
</rows>
</grid>
</tabpanel>
<tabpanel>
<listbox id="lbstatelist" rows="10" model="@{states}" onCreate="call_statelist()">
<listhead>
<listheader label="State-ID" sort="auto" />
<listheader label="State Name" sort="auto" />
</listhead>
<listitem forEach="@{states}">
<listcell label="@{states.state_id}"/>
<listcell label="@{states.state_name}" />
</listitem>
</listbox>
</tabpanel>
</tabpanels>
</tabbox>
</panelchildren>
</panel>
</portalchildren>
</portallayout>
<zscript><![CDATA[
import java.util.*;
import com.drishti.masters.StateRegistrationTable;
public void save_all() {
state.insertState(state);
}
public void call_statelist()
{
StateRegistrationTable statetab;
List states = new ArrayList();
states = state.StateList();
}
]]>
</zscript>
</window>
</zk>
Java Code
public List <StateRegistrationTable> StateList()
{
List <StateRegistrationTable> statelist=new ArrayList<StateRegistrationTable>();
RealtyOneConnection rconn=new RealtyOneConnection();
try{
//System.out.println("Debug from start of method CityName");
StateRegistration qreg = new StateRegistration();
SqlMapSession session=rconn.currentSession();
statelist = session.queryForList("StateList", qreg);
session.commitTransaction();
session.endTransaction();
} catch (SQLException se) {
System.out.println("Some SQL Exceptions from State List :" + se);
}//catch
finally{
rconn.closeSession();
System.out.println("State List Created...");
}//finally
return statelist;
}
public class StateRegistrationTable {
/**
* All the mapped Columns of quick registration table
* **/
private int State_id=0;
private String State_name="";
public int getState_id() {
return State_id;
}
public void setState_id(int State_id) {
this.State_id = State_id;
}
public String getState_name() {
return State_name;
}
public void setState_name(String State_name) {
this.State_name = State_name;
}
}
public class StateRegistrationTable {
/**
* All the mapped Columns of quick registration table
* **/
private int State_id=0;
private String State_name="";
public int getState_id() {
return State_id;
}
public void setState_id(int State_id) {
this.State_id = State_id;
}
public String getState_name() {
return State_name;
}
public void setState_name(String State_name) {
this.State_name = State_name;
}
}
First, you'll be glad to learn that you can use tags to surround your code examples so that all the lines are not jammed on the left. Use [ c o d e ] and [ / c o d e ] without the spaces and it will make things much more readable.
Secondly, you've mixed metaphor's. You cannot use forEach with databinding because they're processed in different phases. When a forEach is processed, it's done in the rendering phase and its resulting UI components are never changed. Using databinding is pretty much the opposite: the rendering phase does nothing with it but the databinding modifies the DOM at runtime.
Your original code (surrounded with tags)
<listbox id="lbstatelist" rows="10" model="@{states}" onCreate="call_statelist()"> <listhead> <listheader label="State-ID" sort="auto" /> <listheader label="State Name" sort="auto" /> </listhead> <listitem forEach="@{states}"> <listcell label="@{states.state_id}"/> <listcell label="@{states.state_name}" /> </listitem> </listbox>
try these simple changes:
<listbox id="lbstatelist" rows="10" model="@{states}" onCreate="call_statelist()"> <listhead> <listheader label="State-ID" sort="auto" /> <listheader label="State Name" sort="auto" /> </listhead> <listitem self="@{each='state'}" value="@{state}" > <listcell label="@{state.state_id}"/> <listcell label="@{state.state_name}" /> </listitem> </listbox>
This creates the listitems and assigns the state instance to them as the "value" (this is good for reference when you're dealing with a selected item)
HTH,
Thanks caclark
yes problem solved.
Thanks again for given me good suggestions.
Asked: 2010-02-19 00:49:40 +0800
Seen: 711 times
Last updated: Feb 19 '10