Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    JPA storage

    My JPA pojos are sort of
    Code:

    @Entity
    class Master{
    ...

    @ManyToOne
    Set<Slave> slaves;
    }

    I can create and save a Master object in a ListGrid (my "dao" service is called) but I cannot populate the slaves collection since your classes claim that the id is missing (of course is there with all the needed getters/setters).

    Code:
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.data.Criteria;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.types.ListGridEditEvent;
    import com.smartgwt.client.types.VisibilityMode;
    import com.smartgwt.client.util.KeyCallback;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Label;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.SelectItem;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.grid.ListGridRecord;
    import com.smartgwt.client.widgets.grid.events.SelectionChangedHandler;
    import com.smartgwt.client.widgets.layout.SectionStack;
    import com.smartgwt.client.widgets.layout.SectionStackSection;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class OrderManagement implements EntryPoint {
    
    	private static final int MAXWIDTH = 1024 - 80;
    	private SelectItem shipTo = new SelectItem("MyShipTo");
    
    	/**
    	 * Creates a new instance of JPADS
    	 */
    	public OrderManagement() {
    	}
    
    	/**
    	 * The entry point method, called automatically by loading a module that
    	 * declares an implementing class as an entry-point
    	 */
    	public void onModuleLoad() {
    
    		KeyIdentifier debugKey = new KeyIdentifier();
    		debugKey.setCtrlKey(true);
    		debugKey.setKeyName("D");
    
    		Page.registerKey(debugKey, new KeyCallback() {
    			public void execute(String keyName) {
    				SC.showConsole();
    			}
    		});
    
    		Label orderListLabel = new Label();
    		orderListLabel.setContents("Order List");
    		orderListLabel.setWidth("90%");
    
    		final DataSource orderDS = DataSource.get("order_DataSource");
    
    		ListGrid orderList = new ListGrid();
    		orderList.setDataSource(orderDS);
    		orderList.setWidth(MAXWIDTH);
    		orderList.setHeight(150);
    		orderList.setAlternateRecordStyles(true);
    		orderList.setAutoFetchData(true);
    		orderList.setDataPageSize(50);
    		orderList.setCanRemoveRecords(true);
    
    		IButton newOrderButton = new IButton("Add New Order");
    		newOrderButton.setWidth(120);
    
    		VLayout orderListLayout = new VLayout();
    		orderListLayout.addMember(orderListLabel);
    		orderListLayout.addMember(orderList);
    		orderListLayout.addMember(newOrderButton);
    
    		final SectionStack sectionStack = new SectionStack();
    		sectionStack.setVisibilityMode(VisibilityMode.MULTIPLE);
    		sectionStack.setWidth(MAXWIDTH);
    		sectionStack.setHeight(1280 - 80);
    
    		SectionStackSection section1 = new SectionStackSection("Order Header");
    		section1.setExpanded(true);
    		section1.setResizeable(true);
    
    		// final DynamicForm orderForm = new DynamicForm();
    		// orderForm.setDataSource(orderDS);
    
    		final DynamicForm orderForm = new DynamicForm();
    		orderForm.setDataSource(orderDS);
    		shipTo.setOptionDataSource(DataSource.get("stakeholder_DataSource"));
    		shipTo.setPickListCriteria(new Criteria("schema", "SHIPTO"));
    		shipTo.setAutoFetchData(true);
    
    		orderForm.setItems(shipTo);
    
    		section1.addItem(orderForm);
    
    		sectionStack.addSection(section1);
    		sectionStack.collapseSection(0);
    
    		// lista prodotti
    		SectionStackSection section2 = new SectionStackSection("Product Search");
    		section2.setExpanded(true);
    		section2.setResizeable(true);
    
    		final DataSource productDS = DataSource.get("product_DataSource");
    
    		final ListGrid productGrid = new ListGrid();
    		productGrid.setAlternateRecordStyles(true);
    		productGrid.setDataSource(productDS);
    		productGrid.setWidth(MAXWIDTH);
    		productGrid.setHeight(150);
    		productGrid.setAlternateRecordStyles(true);
    		productGrid.setAutoFetchData(true);
    		productGrid.setDataPageSize(50);
    		productGrid.setShowFilterEditor(true);
    
    		section2.addItem(productGrid);
    		/*
    		 * section2.addItem(newProductButton);
    		 * section2.addItem(saveProductButton);
    		 */
    		sectionStack.addSection(section2);
    
    		// lista stakeholder
    		SectionStackSection section3 = new SectionStackSection("StakeHolder");
    		section3.setExpanded(false);
    		section3.setResizeable(true);
    
    		final DataSource stakeholderDS = DataSource.get("stakeholder_DataSource");
    
    		final ListGrid stakeholderGrid = new ListGrid();
    		stakeholderGrid.setAlternateRecordStyles(true);
    		stakeholderGrid.setDataSource(stakeholderDS);
    		stakeholderGrid.setWidth(MAXWIDTH);
    		stakeholderGrid.setHeight(150);
    		stakeholderGrid.setAlternateRecordStyles(true);
    		stakeholderGrid.setAutoFetchData(true);
    		stakeholderGrid.setDataPageSize(50);
    		stakeholderGrid.setShowFilterEditor(true);
    		stakeholderGrid.setCanEdit(true);
    		stakeholderGrid.setEditEvent(ListGridEditEvent.CLICK);
    		stakeholderGrid.setCanRemoveRecords(true);
    		ListGridField addressSH = new ListGridField("address", "address");
    		ListGridField citySH = new ListGridField("city", "city");
    		ListGridField countrySH = new ListGridField("country", "country");
    		ListGridField descriptionSH = new ListGridField("description", "description");
    		ListGridField idTransmitterSH = new ListGridField("idTransmitter", "idTransmitter");
    		ListGridField nameSH = new ListGridField("name", "name");
    		ListGridField schemaSH = new ListGridField("schema", "schema");
    		ListGridField companySH = new ListGridField("company", "company");
    		ListGridField creditTermsCodeSH = new ListGridField("creditTermsCode", "creditTermsCode");
    		ListGridField truckRequirementsSH = new ListGridField("truckRequirements", "truckRequirements");
    		ListGridField divisionSH = new ListGridField("division", "division");
    		ListGridField paymentFormSH = new ListGridField("paymentForm", "paymentForm");
    		ListGridField districtSH = new ListGridField("district", "district");
    		stakeholderGrid.setFields(descriptionSH, nameSH, countrySH, citySH, addressSH, idTransmitterSH, schemaSH, companySH,
    				creditTermsCodeSH, truckRequirementsSH, divisionSH, paymentFormSH, districtSH);
    
    		IButton newStakeholderGridButton = new IButton("New Stakeholder");
    		newStakeholderGridButton.addClickHandler(new ClickHandler() {
    			@Override
    			public void onClick(ClickEvent event) {
    				stakeholderGrid.startEditingNew();
    				// stakeholderGrid.setEditValue(0, "version", 1);
    				stakeholderGrid.setEditValue(0, "schema", "SHIPTO");
    				stakeholderGrid.setEditValue(0, "company", "100");
    				stakeholderGrid.setEditValue(0, "creditTermsCode", "1");
    				stakeholderGrid.setEditValue(0, "truckRequirements", "1");
    				stakeholderGrid.setEditValue(0, "division", "12");
    				stakeholderGrid.setEditValue(0, "paymentForm", "1");
    				stakeholderGrid.setEditValue(0, "district", "1");
    			}
    		});
    
    		IButton saveStakeholderButton = new IButton("Save Stakeholder");
    		saveStakeholderButton.addClickHandler(new ClickHandler() {
    			public void onClick(ClickEvent event) {
    				// SC.warn("number of orderLines to save:" +
    				// orderLineList.getRecords().length);
    				stakeholderGrid.saveAllEdits();
    			}
    		});
    
    		section3.addItem(stakeholderGrid);
    		section3.addItem(newStakeholderGridButton);
    		section3.addItem(saveStakeholderButton);
    		sectionStack.addSection(section3);
    
    		SectionStackSection section4 = new SectionStackSection("Order Lines");
    		section4.setExpanded(true);
    		section4.setResizeable(true);
    
    		final DataSource orderLineDS = DataSource.get("orderLine_DataSource");
    
    		final ListGrid orderLineList = new ListGrid();
    		orderLineList.setDataSource(orderLineDS);
    		orderLineList.setWidth(MAXWIDTH);
    		orderLineList.setHeight(224);
    		orderLineList.setAlternateRecordStyles(true);
    		orderLineList.setSaveLocally(true);
    		orderLineList.setSaveByCell(true);
    		orderLineList.setShowFilterEditor(true);
    		orderLineList.setCanEdit(true);
    		orderLineList.setEditEvent(ListGridEditEvent.CLICK);
    		orderLineList.setCanRemoveRecords(true);
    		ListGridField quantity = new ListGridField("quantity", "Quantity");
    		ListGridField unitPrice = new ListGridField("unitPrice", "Unit Price");
    		unitPrice.setCanEdit(false);
    		ListGridField product = new ListGridField("product", "Product");
    		product.setCanEdit(false);
    		// ListGridField version = new ListGridField("version", "Version");
    		// product.setValueField(productGrid.getSelectedRecord().getAttribute("id"));
    		orderLineList.setFields(quantity, unitPrice, product);
    
    		/*
    		 * IButton newOrderLineButton = new IButton("Add New OrderLine");
    		 * newOrderLineButton.addClickHandler(new ClickHandler() { public void
    		 * onClick(ClickEvent event) { orderLineList.startEditingNew(); } });
    		 */
    
    		IButton saveOrderLineButton = new IButton("Save Order");
    		saveOrderLineButton.addClickHandler(new ClickHandler() {
    			public void onClick(ClickEvent event) {
    				SC.logDebug("number of orderLines to save:" + orderLineList.getRecords().length);
    				orderForm.setValue("orderLines", orderLineList.getRecords());
    				orderForm.saveData();
    			}
    		});
    
    		section4.addItem(orderLineList);
    		// section4.addItem(newOrderLineButton);
    		section4.addItem(saveOrderLineButton);
    		sectionStack.addSection(section4);
    
    		VLayout layout = new VLayout();
    		layout.setTop("45px");
    		layout.setStyleName("ordermanagement_container");
    
    		layout.addMember(orderListLayout);
    		layout.addMember(sectionStack);
    
    		orderList.addSelectionChangedHandler(new SelectionChangedHandler() {
    			@Override
    			public void onSelectionChanged(com.smartgwt.client.widgets.grid.events.SelectionEvent event) {
    				if (event.getState()) {
    					// SC.warn("number of orderLines:" +
    					// event.getSelectedRecord().getAttributeAsRecordArray("orderLines").length);
    					sectionStack.setDisabled(false);
    					sectionStack.expandSection(0);
    					orderLineList.setData(event.getSelectedRecord().getAttributeAsRecordArray("orderLines"));
    					orderForm.editRecord(event.getSelectedRecord());
    				} else {
    					sectionStack.setDisabled(true);
    				}
    
    			}
    		});
    
    		productGrid.addSelectionChangedHandler(new SelectionChangedHandler() {
    			@Override
    			public void onSelectionChanged(com.smartgwt.client.widgets.grid.events.SelectionEvent event) {
    				orderLineList.startEditingNew();
    				sectionStack.expandSection(3);
    				orderLineList.setEditValue(0, "unitPrice", productGrid.getSelectedRecord().getAttributeAsLong("unitPrice"));
    				orderLineList.setEditValue(0, "quantity", 1);
    			}
    		});
    
    		newOrderButton.addClickHandler(new ClickHandler() {
    			public void onClick(ClickEvent event) {
    				sectionStack.setDisabled(false);
    				sectionStack.expandSection(0);
    				shipTo.fetchData();
    				orderLineList.setData(new ListGridRecord[0]);
    				orderForm.editNewRecord();
    			}
    		});
    
    		layout.draw();
    	}
    }
    _About project environment_
    My app's architecture is roughly based on:
    * data access layer: spring-roo managed data-access core classes based on JPA-HIBERNATE-DB2
    * business layer: spring-mvc webapp with thymeleaf templating engine
    * presentation layer: twitter boostrap responsive design HTML framework

    See http://forums.smartclient.com/showpo...53&postcount=3 for datasources and version info.

    Thank you
    -Luca
    Last edited by lrkwz; 28 Dec 2012, 10:29. Reason: added required info.
Working...
X