facebook

Using generated Services

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #318629 Reply

    jonagy
    Member

    I have the following situation:

    Im using 2 Tables, and generated teh CRUD for them for GWT 2.1.
    In the Detailsview of Entity1 i have to generate Entity2 and save it to the Database.

    How to do that ?

    Here the relevant Code:

    package gwt.client.managed.ui;

    import org.springframework.beans.factory.annotation.Autowired;

    import at.smartengine.seppactivation.domain.ActivatedOffers;
    import at.smartengine.seppactivation.service.ActivatedOffersGWTAdapter;
    import at.smartengine.seppactivation.service.ActivatedOffersService;

    import com.google.gwt.core.client.GWT;

    import com.google.gwt.dom.client.SpanElement;

    import com.google.gwt.event.dom.client.ClickEvent;
    import com.google.gwt.event.dom.client.HasClickHandlers;

    import com.google.gwt.uibinder.client.UiBinder;
    import com.google.gwt.uibinder.client.UiField;
    import com.google.gwt.uibinder.client.UiHandler;

    import com.google.gwt.user.client.Window;

    import com.google.gwt.user.client.ui.Composite;
    import com.google.gwt.user.client.ui.HTML;
    import com.google.gwt.user.client.ui.HTMLPanel;
    import com.google.gwt.user.client.ui.Widget;
    import com.google.inject.Inject;
    import com.google.web.bindery.requestfactory.shared.EntityProxy;
    import com.google.web.bindery.requestfactory.shared.EntityProxyId;

    import gwt.client.managed.request.ActivatedOffersProxy;
    import gwt.client.managed.request.ActivatedOffersRequest;
    import gwt.client.managed.request.ApplicationRequestFactory;
    import gwt.client.managed.request.OfferProxy;

    import gwt.client.scaffold.MainPanel;
    import gwt.client.scaffold.ioc.ScaffoldModule;
    import gwt.client.scaffold.place.ProxyDetailsView;

    /**
    * Details view for Offer proxy.
    */
    public class OfferDetailsView extends Composite implements
    ProxyDetailsView<OfferProxy> {
    interface Binder extends UiBinder<HTMLPanel, OfferDetailsView> {
    }

    private static final Binder BINDER = GWT.create(Binder.class);

    private static OfferDetailsView instance;

    OfferProxy proxy;

    @UiField
    SpanElement offerId;
    @UiField
    SpanElement title;
    @UiField
    SpanElement validityPeriodStartDate;
    @UiField
    SpanElement validityPeriodEndDate;
    //@UiField
    //SpanElement shortDescription;
    @UiField
    HTML longDescription;
    @UiField
    SpanElement termsAndConditions;
    @UiField
    SpanElement savingsCode;
    @UiField
    SpanElement discountAmount;
    @UiField
    SpanElement offerType;
    @UiField
    SpanElement redemption;
    @UiField
    SpanElement awardRule;
    @UiField
    SpanElement purchaseAmount;
    /*
    @UiField
    SpanElement mediaContentRef;
    @UiField
    SpanElement mediaName;
    */
    @UiField
    SpanElement merchantIdse;
    @UiField
    SpanElement status;

    @UiField
    SpanElement activatedOfferses;

    @UiField
    HasClickHandlers edit;
    @UiField
    HasClickHandlers delete;

    private ProxyDetailsView.Delegate delegate;

    public static OfferDetailsView instance() {
    if (instance == null) {
    instance = new OfferDetailsView();
    }

    return instance;
    }

    public OfferDetailsView() {
    initWidget(BINDER.createAndBindUi(this));
    }

    public Widget asWidget() {
    return this;
    }

    public boolean confirm(String msg) {
    return Window.confirm(msg);
    }

    public OfferProxy getValue() {
    return proxy;
    }

    @UiHandler(“delete”)
    public void onDeleteClicked(@SuppressWarnings(“unused”) ClickEvent e) {
    delegate.deleteClicked();
    }

    @UiHandler(“edit”)
    public void onEditClicked(@SuppressWarnings(“unused”) ClickEvent e) {
    //delegate.editClicked();

    //get the RequestFactory
    MainPanel mainpanel=(MainPanel) this.getParent().getParent().getParent().getParent();
    ApplicationRequestFactory requestFactory = mainpanel.getApplication().getRequestFactory();

    ActivatedOffersRequest aor = requestFactory.activatedOffersRequest();
    ActivatedOffersProxy obj=aor.create(ActivatedOffersProxy.class);

    obj.setCardnumber(“30104735918009”);
    obj.setOffer(proxy);

    //activatedOffersService.saveActivatedOffers(obj);
    aor.saveActivatedOffers(obj);
    //delegate.saveClicked();
    Window.alert(“Offer “+title.getInnerText()+” activated !”);
    }

    public void setDelegate(Delegate delegate) {
    this.delegate = delegate;
    }

    public void setValue(OfferProxy proxy) {
    this.proxy = proxy;
    try {
    offerId.setInnerText(String.valueOf(proxy.getOfferId()));
    title.setInnerText(String.valueOf(proxy.getTitle()));
    validityPeriodStartDate.setInnerText(String.valueOf(proxy.getValidityPeriodStartDate()));
    validityPeriodEndDate.setInnerText(String.valueOf(proxy.getValidityPeriodEndDate()));
    //shortDescription.setInnerText(String.valueOf(proxy.getShortDescription()));
    longDescription.setHTML(String.valueOf(proxy.getLongDescription()));
    termsAndConditions.setInnerText(String.valueOf(proxy.getTermsAndConditions()));
    savingsCode.setInnerText(String.valueOf(proxy.getSavingsCode()));
    discountAmount.setInnerText(String.valueOf(proxy.getDiscountAmount()));
    offerType.setInnerText(String.valueOf(proxy.getOfferType()));
    redemption.setInnerText(String.valueOf(proxy.getRedemption()));
    awardRule.setInnerText(String.valueOf(proxy.getAwardRule()));
    purchaseAmount.setInnerText(String.valueOf(proxy.getPurchaseAmount()));
    //mediaContentRef.setInnerText(String.valueOf(proxy.getMediaContentRef()));
    //mediaName.setInnerText(String.valueOf(proxy.getMediaName()));
    merchantIdse.setInnerText(String.valueOf(proxy.getMerchantIdse()));
    status.setInnerText(String.valueOf(proxy.getStatus()));

    activatedOfferses.setInnerText(proxy.getActivatedOfferses() == null ? “” : gwt.client.scaffold.ui.CollectionRenderer.of(ActivatedOffersProxyRenderer.instance()).render(proxy.getActivatedOfferses()));
    } catch (Exception e)
    {
    System.out.println(“Exception in OfferDetailsView.setValue(OfferProxy proxy) “+e.getMessage());
    }
    }
    }

    #318642 Reply

    jkennedy
    Member

    Is there a relationship between your two entities?

    If there is, then there should be an example of how to manage the related objects in the edit view.

    Thanks,
    Jack

    #318667 Reply

    jonagy
    Member

    Hi !

    There is no relation.

    I have the RequestFactory in a Singleton, and accessing them globally right now,
    it seams to working.

    Is there a better was to doing this ?

    ty

    package gwt.client.managed.ui;

    import gwt.client.managed.request.ActivatedOffersProxy;
    import gwt.client.managed.request.ActivatedOffersRequest;
    import gwt.client.managed.request.ApplicationRequestFactory;
    import gwt.client.managed.request.CustomerProxy;
    import gwt.client.managed.request.OfferProxy;
    import gwt.client.scaffold.AppSingleton;
    import gwt.client.scaffold.MainPanel;
    import gwt.client.scaffold.place.ProxyDetailsView;

    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.Date;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Set;

    import at.smartengine.seppactivation.domain.Customer;

    import com.google.gwt.core.client.GWT;
    import com.google.gwt.dom.client.Element;
    import com.google.gwt.dom.client.SpanElement;
    import com.google.gwt.event.dom.client.ClickEvent;
    import com.google.gwt.event.dom.client.HasClickHandlers;
    import com.google.gwt.uibinder.client.UiBinder;
    import com.google.gwt.uibinder.client.UiField;
    import com.google.gwt.uibinder.client.UiHandler;
    import com.google.gwt.user.client.DOM;
    import com.google.gwt.user.client.Window;
    import com.google.gwt.user.client.rpc.core.java.util.Collections;
    import com.google.gwt.user.client.ui.Composite;
    import com.google.gwt.user.client.ui.HTML;
    import com.google.gwt.user.client.ui.HTMLPanel;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.google.gwt.user.client.ui.ValueListBox;
    import com.google.gwt.user.client.ui.Widget;
    import com.google.web.bindery.requestfactory.shared.Request;
    import com.google.web.bindery.requestfactory.shared.Receiver;

    /**
    * Details view for Offer proxy.
    */
    public class OfferDetailsView extends Composite implements
    ProxyDetailsView<OfferProxy> {
    interface Binder extends UiBinder<HTMLPanel, OfferDetailsView> {
    }

    private static final Binder BINDER = GWT.create(Binder.class);

    private static OfferDetailsView instance;

    OfferProxy proxy;

    MainPanel mainpanel;
    ApplicationRequestFactory requestFactory;

    @UiField
    SpanElement offerId;
    @UiField
    SpanElement title;
    @UiField
    SpanElement validityPeriodStartDate;
    @UiField
    SpanElement validityPeriodEndDate;
    //@UiField
    //SpanElement shortDescription;
    @UiField
    HTML longDescription;
    @UiField
    SpanElement termsAndConditions;
    @UiField
    SpanElement savingsCode;
    @UiField
    SpanElement discountAmount;
    @UiField
    SpanElement offerType;
    @UiField
    SpanElement redemption;
    @UiField
    SpanElement awardRule;
    @UiField
    SpanElement purchaseAmount;
    /*
    @UiField
    SpanElement mediaContentRef;
    @UiField
    SpanElement mediaName;
    */
    @UiField
    SpanElement merchantIdse;
    @UiField
    SpanElement status;

    @UiField
    SpanElement activatedOfferses;

    @UiField(provided = true)
    ValueListBox<CustomerProxy> customer = new ValueListBox<CustomerProxy>(CustomerProxyRenderer.instance(), new com.google.web.bindery.requestfactory.gwt.ui.client.EntityProxyKeyProvider<CustomerProxy>());

    @UiField
    HasClickHandlers edit;
    @UiField
    HasClickHandlers delete;

    private ProxyDetailsView.Delegate delegate;

    public static OfferDetailsView instance() {
    if (instance == null) {
    instance = new OfferDetailsView();
    }

    return instance;
    }

    public OfferDetailsView() {
    initWidget(BINDER.createAndBindUi(this));
    // get the request factory
    this.requestFactory=AppSingleton.instance().getRequestFactory();
    }

    public void setCustomerPickerValues(Collection<CustomerProxy> values) {

    customer.setAcceptableValues(values);
    }

    public Widget asWidget() {
    return this;
    }

    public boolean confirm(String msg) {
    return Window.confirm(msg);
    }

    public OfferProxy getValue() {
    return proxy;
    }

    @UiHandler(“delete”)
    public void onDeleteClicked(@SuppressWarnings(“unused”) ClickEvent e) {
    delegate.deleteClicked();
    }

    @UiHandler(“edit”)
    public void onEditClicked(@SuppressWarnings(“unused”) ClickEvent e) {
    //delegate.editClicked();

    //get the RequestFactory
    //MainPanel mainpanel=(MainPanel) this.getParent().getParent().getParent().getParent();
    //ApplicationRequestFactory requestFactory = mainpanel.getApplication().getRequestFactory();

    //mainpanel=(MainPanel) this.getParent().getParent().getParent().getParent();
    //requestFactory = mainpanel.getApplication().getRequestFactory();

    ActivatedOffersRequest aor = requestFactory.activatedOffersRequest();
    ActivatedOffersProxy obj=aor.create(ActivatedOffersProxy.class);

    CustomerProxy cp=customer.getValue();

    obj.setCustomer(cp);
    obj.getCustomer().setCardnumber(cp.getCardnumber());
    obj.setOffer(proxy);
    obj.setActivationTime(new Date());
    obj.setId(3);

    try {
    aor.saveActivatedOffers(obj).fire();
    Window.alert(“Offer “+title.getInnerText()+” activated !”);
    } catch (Exception ex)
    {
    Window.alert(“Offer “+title.getInnerText()+” not activated:”+ex.getLocalizedMessage());
    }
    }

    public void setDelegate(Delegate delegate) {
    this.delegate = delegate;
    }

    public void setValue(OfferProxy proxy) {
    this.proxy = proxy;
    try {
    offerId.setInnerText(String.valueOf(proxy.getOfferId()));
    title.setInnerText(String.valueOf(proxy.getTitle()));
    validityPeriodStartDate.setInnerText(String.valueOf(proxy.getValidityPeriodStartDate()));
    validityPeriodEndDate.setInnerText(String.valueOf(proxy.getValidityPeriodEndDate()));
    //shortDescription.setInnerText(String.valueOf(proxy.getShortDescription()));
    longDescription.setHTML(String.valueOf(proxy.getLongDescription()));
    termsAndConditions.setInnerText(String.valueOf(proxy.getTermsAndConditions()));
    savingsCode.setInnerText(String.valueOf(proxy.getSavingsCode()));
    discountAmount.setInnerText(String.valueOf(proxy.getDiscountAmount()));
    offerType.setInnerText(String.valueOf(proxy.getOfferType()));
    redemption.setInnerText(String.valueOf(proxy.getRedemption()));
    awardRule.setInnerText(String.valueOf(proxy.getAwardRule()));
    purchaseAmount.setInnerText(String.valueOf(proxy.getPurchaseAmount()));
    //mediaContentRef.setInnerText(String.valueOf(proxy.getMediaContentRef()));
    //mediaName.setInnerText(String.valueOf(proxy.getMediaName()));
    merchantIdse.setInnerText(String.valueOf(proxy.getMerchantIdse()));
    status.setInnerText(String.valueOf(proxy.getStatus()));

    activatedOfferses.setInnerText(proxy.getActivatedOfferses() == null ? “” : gwt.client.scaffold.ui.CollectionRenderer.of(ActivatedOffersProxyRenderer.instance()).render(proxy.getActivatedOfferses()));

    // populate the listbox
    requestFactory.customerRequest().findAllCustomers(0, 50).with(CustomerProxyRenderer.instance().getPaths()).fire(new Receiver<List<CustomerProxy>>() {
    public void onSuccess(List<CustomerProxy> response) {
    List<CustomerProxy> values = new ArrayList<CustomerProxy>();
    //values.add(null);
    values.addAll(response);
    customer.setAcceptableValues(values);
    if(values.size()>0)
    {
    customer.setValue(values.get(0));
    }
    }
    });

    //customer.setAcceptableValues(customers);
    } catch (Exception e)
    {
    System.out.println(“Exception in OfferDetailsView.setValue(OfferProxy proxy) “+e.getMessage());
    }
    }
    }

    #319124 Reply

    trainingau
    Member

    thanks…really helpful

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Using generated Services

You must be logged in to post in the forum log in