it not working …
Please show form edit mode but type and customer not fill.
package com.nxpert.DematAdmin;
import java.util.Arrays;
import com.nexpert.DBUtil.CommonDAO;
import com.nxpert.model.Customer;
import com.nxpert.model.Cutomercontact;
import com.nxpert.model.Typecontact;
import com.vaadin.data.Item;
import com.vaadin.data.util.BeanItem;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.DefaultFieldFactory;
import com.vaadin.ui.Field;
import com.vaadin.ui.Form;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.PasswordField;
import com.vaadin.ui.Select;
import com.vaadin.ui.Window;
public class CustomerForm extends Form {
private static final long serialVersionUID = 1L;
private GridLayout ourLayout;
Window subWindow;
String customerconid;
public CustomerForm(Window subWindow2,Cutomercontact cutomercontact,final String customerconid) {
this.customerconid=customerconid;
subWindow = subWindow2;
ourLayout = new GridLayout(2, 3);
ourLayout.setWidth("100%");
System.out.println("ID--->"+customerconid);
// Use top-left margin and spacing
ourLayout.setMargin(true, false, false, true);
ourLayout.setSpacing(true);
setLayout(ourLayout);//Form with grid layout
// FieldFactory for customizing the fields and adding validators
setFormFieldFactory(new CustomerFieldFactory(cutomercontact,customerconid));
// Set up buffering
setWriteThrough(false); // we want explicit 'apply'
setInvalidCommitted(false); // no invalid values in datamodel
//Bean Item to set form-automatic display all field.
//Cutomercontact contact = new Cutomercontact();
final BeanItem<Cutomercontact> customeritem = new BeanItem<Cutomercontact>(cutomercontact);
//set form in bean item
this.setItemDataSource(customeritem);
//form in visible column
setVisibleItemProperties(Arrays.asList(new String[] { "name", "email",
"typecontact", "customer", "addr1", "addr2", "addr3", "mobile",
"phone1", "phone2", "login", "password", "city", "zipcode",
"country", }));
// The cancel save buttons layouts
HorizontalLayout frombuttonslayout = new HorizontalLayout();
frombuttonslayout.setSpacing(true);
//save button
Button apply = new Button("Save", new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
try {
System.out.println("click");
commit();//commit to all data bind in Bean Item Object
System.out.println("commit");
Cutomercontact cutomercontact = new Cutomercontact();//set all bind data in Customer Contact
if(customerconid!=null && customerconid !=""){
cutomercontact.setIdcutomercontact(customeritem.getBean().getIdcutomercontact());
}
cutomercontact.setName(customeritem.getBean().getName());
cutomercontact.setEmail(customeritem.getBean().getEmail());
cutomercontact.setAddr1(customeritem.getBean().getAddr1());
cutomercontact.setAddr2(customeritem.getBean().getAddr2());
cutomercontact.setAddr3(customeritem.getBean().getAddr3());
cutomercontact.setMobile(customeritem.getBean().getMobile());
cutomercontact.setPhone1(customeritem.getBean().getPhone1());
cutomercontact.setPhone2(customeritem.getBean().getPhone2());
cutomercontact.setLogin(customeritem.getBean().getLogin());
cutomercontact.setCity(customeritem.getBean().getCity());
cutomercontact.setPassword(customeritem.getBean().getPassword());
cutomercontact.setZipcode(customeritem.getBean().getZipcode());
cutomercontact.setCountry(customeritem.getBean().getCountry());
//Type Combobox to set data Typecontact
Typecontact typecontact = new Typecontact();
typecontact.setType(customeritem.getBean().getTypecontact().getType());
typecontact.setIdtypecontact(customeritem.getBean().getTypecontact().getIdtypecontact());
cutomercontact.setTypecontact(typecontact);
//Customer Combobox to set data in customer
Customer customer = new Customer();
customer.setCustomerId(customeritem.getBean().getCustomer().getCustomerId());
customer.setCustomerName(customeritem.getBean().getCustomer().getCustomerName());
cutomercontact.setCustomer(customer);
//Save All Data In Customer Contact Table
CommonDAO.setInsertUpdateData(cutomercontact);
discard();
} catch (Exception e) {
// Ingnored, we'll let the Form handle the errors
}
}
});
//Cancel Button to Reset Data
frombuttonslayout.addComponent(apply);
Button discardChanges = new Button("Cancel",
new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
discard();
(subWindow.getParent()).removeWindow(subWindow);
}
});
frombuttonslayout.addComponent(discardChanges);
//set Save and Cancel Button in ad form header
this.getFooter().setMargin(true);
this.getFooter().addComponent(frombuttonslayout);
}
}
//Customize Field Factory Class
class CustomerFieldFactory extends DefaultFieldFactory {
final ComboBox typecontactseelct = new ComboBox("Type");//User Type Combo
final ComboBox Customerseelct = new ComboBox("Customer");//Customer Type Comobo
String customerconid;
Cutomercontact cutomercontact;
public CustomerFieldFactory(Cutomercontact cutomercontact,String customerconid) {
this.customerconid=customerconid;
this.cutomercontact=cutomercontact;
}
@Override
public Field createField(Item item, Object propertyId, Component uiContext) {
Field f = null;
//fill Type Combo and display form in combobox
if ("typecontact".equals(propertyId)) {
BeanItemContainer<Typecontact> container = new BeanItemContainer<Typecontact>(Typecontact.class);
container.addAll(CommonDAO.getData("Typecontact"));
typecontactseelct.setContainerDataSource(container);
typecontactseelct.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_EXPLICIT);
typecontactseelct.setItemCaptionPropertyId("type");
typecontactseelct.setNullSelectionAllowed(false);
typecontactseelct.setFilteringMode(ComboBox.FILTERINGMODE_STARTSWITH);
if(customerconid != null){
System.out.print("Type------>"+cutomercontact.getTypecontact().getType());
typecontactseelct.setValue(cutomercontact.getTypecontact().getType());
}
return typecontactseelct;
} else if ("customer".equals(propertyId)) {
BeanItemContainer<Customer> custcontainer = new BeanItemContainer<Customer>(Customer.class);
custcontainer.addAll(CommonDAO.getData("Customer"));
Customerseelct.setContainerDataSource(custcontainer);
Customerseelct.setItemCaptionMode(Select.ITEM_CAPTION_MODE_PROPERTY);
Customerseelct.setItemCaptionPropertyId("customerName");
Customerseelct.setNullSelectionAllowed(false);
Customerseelct.setFilteringMode(ComboBox.FILTERINGMODE_STARTSWITH);
if(customerconid != null){
System.out.print("Customer--->"+cutomercontact.getCustomer().getCustomerName());
Customerseelct.setValue(cutomercontact.getCustomer().getCustomerName());
}
return Customerseelct;
} else if ("password".equals(propertyId)) {
f = createPasswordField(propertyId);
} else {
f = super.createField(item, propertyId, uiContext);
}
return f;
}
//Display Password Field in form
private PasswordField createPasswordField(Object propertyId) {
PasswordField pf = new PasswordField();
pf.setCaption(DefaultFieldFactory.createCaptionByPropertyId(propertyId));
return pf;
}
}
please show all code
how to setvalue in combobox ???
