-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi, I am having problem to get modified row and it's all attributes when textbox in a row is changed. I want to get row attributes onChange event of textbox Here is my code below. I am using zk 5.0.4
Any help is very appreciated.
Albert
zul
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?>
<?component name="textbox" extends="textbox" constraint="no empty" style="text-align:right; color:blue" inplace="true" width="70px"?>
<window id="win" apply="com.pru.action.EditableGrid" title="Employee List" border="normal" width="700px" >
<grid id="gridEmployees" model="@{win$composer.employees}" width="690px">
<auxhead>
<auxheader label="SomeHeader" colspan="3" align="center"/>
<auxheader label="SomeHeader" colspan="3" align="center"/>
</auxhead>
<auxhead>
<auxheader label="Header1" colspan="2" align="center"/>
<auxheader label="Header2" colspan="2" align="center"/>
<auxheader label="Header3" colspan="2" align="center"/>
</auxhead>
<columns menupopup="auto">
<column sclass="header" label="Emp No" width="80px" sort="auto"/>
<column sclass="header" label="First Name" width="80px" />
<column sclass="header" label="Last Name" width="80px" />
<column sclass="header" label="Department" width="80px" />
<column sclass="header" label="Phone" width="140px" />
<column sclass="header" label="Salary" width="80px" />
</columns>
<rows>
<row self="@{each=employees}">
<cell><textbox value="@{employees.empId}" forward="onChange=onItemChange"></textbox></cell>
<cell><textbox value="@{employees.firstName}" forward="onChange=onItemChange"></textbox></cell>
<cell><textbox value="@{employees.lastName}" forward="onChange=onItemChange"></textbox></cell>
<cell><textbox value="@{employees.workDept}" forward="onChange=onItemChange"></textbox></cell>
<cell><textbox value="@{employees.phone}" forward="onChange=onItemChange"></textbox></cell>
<cell><textbox value="@{employees.salary}" forward="onChange=onItemChange"></textbox></cell>
</row>
</rows>
</grid>
</window>
java
package com.pru.action;
import java.util.ArrayList;
import java.util.List;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Grid;
import org.zkoss.zul.Rows;
public class EditableGrid extends GenericForwardComposer{
private static final long serialVersionUID = 1L;
private List<Employee> employeeList;
private Grid gridEmployees;
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
employeeList = new ArrayList<Employee>();
employeeList.add(new Employee(1,"John","Smith","Accounting","212-222-3333",55200.0));
employeeList.add(new Employee(2,"Richard","Tonner","Accounting","212-222-4444",65300.0));
employeeList.add(new Employee(3,"George","Kovak","Accounting","212-222-5555",60100.0));
employeeList.add(new Employee(4,"Alis","Kennedy","Technology","212-222-6666",40200.0));
employeeList.add(new Employee(5,"Peter","Pan","Technology","212-222-4774",70400.0));
employeeList.add(new Employee(6,"Michael","Bolton","Technology","212-222-3214",90500.0));
}
public void onItemChange(Event event) {
final Rows rows = gridEmployees.getRows();
//how can i get modified row here?
}
public List<Employee> getEmployees(){
return employeeList;
}
public class Employee{
private int empId;
private String firstName;
private String lastName;
private String workDept;
private String phone;
private double salary;
public Employee(int empId, String firstName, String lastName,
String workDept, String phone, double salary) {
super();
this.empId = empId;
this.firstName = firstName;
this.lastName = lastName;
this.workDept = workDept;
this.phone = phone;
this.salary = salary;
}
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getWorkDept() {
return workDept;
}
public void setWorkDept(String workDept) {
this.workDept = workDept;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
}
of course you do. :)
you have two event binding way to go .
one is for cast to InputEvent , it's more convinent .
public void onItemChange(InputEvent event) { //<-- notices that here we declare InputEvent , zk will auto casting Textbox textbox = (Textbox) event.getTarget(); //textbox.getParent() cell //textbox.getParent().getParent(); //row }
The second one is tradition way , go throught ForwareEvent.
public void onItemChange(ForwardEvent event) { //<-- notices that here we declare ForwardEvent , the event go though forward is default to this event. @SuppressWarnings("unused") final Rows rows = gridEmployees.getRows(); InputEvent inputevent = (InputEvent) event.getOrigin(); // get original event here Textbox textbox = (Textbox) inputevent.getTarget(); //textbox.getParent() cell //textbox.getParent().getParent(); //row }
---
some forum tips , using [ code ] [ /code ] to your code will be better. :D
Tony, thank you very much for help. your approach is working well.
Asked: 2010-09-29 10:17:38 +0800
Seen: 695 times
Last updated: Sep 30 '10