我在代码中有两个 sectionstacksection,onw 显示输入数据的动态表单,第二个 sectionstacksection 显示 listgrid,当我在动态表单部分中点击保存按钮时,它将显示输入数据。
我创建了三个类,一个是扩展动态表单的 EmployeeApplicationForm,第二个是扩展 listgrid 的 EquiryList,第三个是扩展 ListGridRecord 的 getter 和 setter 的 EnquiryFormRecord。
我已经完成了获取文本框数据并调用 EnquiryFormRecord 构造函数来获取和设置“数据”变量中的数据。但我无法将这个“数据”变量访问到我的 EnquiryList 类以在 listGird 字段中访问“setData(数据)”。
我的代码是这样的。请分享您解决此问题的想法 EmployeeApplicationClass 和 EnquiryList:
class EmployeeApplicationForm extends DynamicForm {
ButtonItem saveButton;
ButtonItem resetButton;
EnquiryFormRecord[] data;
public EmployeeApplicationForm() {
setNumCols(6);
setWidth100();
setHeight(135);
setErrorOrientation(FormErrorOrientation.RIGHT);
final TextItem fname = new TextItem("FirstName");
final TextItem lname = new TextItem("LastName");
saveButton = new ButtonItem("Save");
saveButton.setStartRow(true);
saveButton.setEndRow(false);
resetButton = new ButtonItem("Reset");
resetButton.setStartRow(false);
resetButton.setEndRow(false);
saveButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
// if validation passes then show user an alert message box
if (valid()) {
SC.say("Form passed validation");
}
String fn = fname.getValueAsString();
String ln = lname.getValueAsString();
data = new EnquiryFormRecord[] { new EnquiryFormRecord(fn, ln) };
}
});
resetButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
resetForm();
}
});
setFields(fname, lname, saveButton, resetButton);
}
private boolean valid() {
return this.validate();
}
private void resetForm() {
this.reset();
}
}
class EnquiryList extends ListGrid {
public EnquiryList(EnquiryFormRecord[] data) {
ListGridField fname = new ListGridField("fname","First Name");
ListGridField lname = new ListGridField("lname","Last Name");
setFields(fname, lname);
setData(data);------/*Hera I am getting error. I cannot access the EmployeeAppliocationForm class "data" variable here*/
setCanEdit(true);
setShowAllRecords(true);
// setSortField(0);
setAlternateRecordStyles(true);
setCanDragRecordsOut(true);
setHoverWidth(200);
setHoverHeight(20);
setSelectionType(SelectionStyle.SINGLE);
}
}