Created
May 20, 2015 20:11
-
-
Save dardison/15526a453a732525d8b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface AddressProxy { | |
| public void setStreet(String street); | |
| public String getStreet(); | |
| public void setTown(String town); | |
| public String getTown(); | |
| } | |
| public class AddressForm implements AddressProxy { | |
| private String street; | |
| private String town; | |
| public String getStreet() { | |
| return street; | |
| } | |
| public void setStreet(String street) { | |
| this.street = street; | |
| } | |
| public String getTown() { | |
| return town; | |
| } | |
| public void setTown(String town) { | |
| this.town = town; | |
| } | |
| } | |
| public interface ClientProxy { | |
| public String getName(); | |
| public void setName(String name); | |
| public void setId(Long id); | |
| public Long getId(); | |
| public void setLicensor(Boolean isLicensor); | |
| public Boolean isLicensor(); | |
| public void setAddress(AddressProxy address); | |
| public AddressProxy getAddress(); | |
| } | |
| public class ClientForm implements ClientProxy { | |
| private String name; | |
| private Long id; | |
| private Boolean licensor; | |
| private AddressProxy address; | |
| public String getName() { | |
| return name; | |
| } | |
| public void setName(String name) { | |
| this.name = name; | |
| } | |
| public Long getId() { | |
| return id; | |
| } | |
| public void setId(Long id) { | |
| this.id = id; | |
| } | |
| public Boolean isLicensor() { | |
| return licensor; | |
| } | |
| public void setLicensor(Boolean licensor) { | |
| this.licensor = licensor; | |
| } | |
| public AddressProxy getAddress() { | |
| return address; | |
| } | |
| public void setAddress(AddressProxy address) { | |
| this.address = address; | |
| } | |
| } | |
| public interface SaveClientRequest { | |
| ClientProxy getModel(); | |
| void setModel(ClientProxy model); | |
| } | |
| public class SaveClientRequestImpl implements SaveClientRequest { | |
| private ClientProxy model; | |
| public ClientProxy getModel() { | |
| return model; | |
| } | |
| public void setModel(ClientProxy model) { | |
| this.model = model; | |
| } | |
| } | |
| import com.google.gwt.core.shared.GWT; | |
| import com.google.web.bindery.autobean.shared.AutoBean; | |
| import com.google.web.bindery.autobean.shared.AutoBeanFactory; | |
| import com.sencha.gxt.data.shared.writer.JsonWriter; | |
| public class JsonWriterTester { | |
| private JsonWriter<SaveClientRequest> writer; | |
| public interface ClientAutoBeanFactory extends AutoBeanFactory { | |
| AutoBean<ClientProxy> getModel(); | |
| AutoBean<AddressProxy> address(); | |
| AutoBean<SaveClientRequest> request(); | |
| } | |
| private static ClientAutoBeanFactory factory=GWT.create(ClientAutoBeanFactory.class); | |
| public void testWriter(SaveClientRequest request){ | |
| try{ | |
| this.writer=new JsonWriter<SaveClientRequest>(factory, SaveClientRequest.class); | |
| String json=this.writer.write(request); | |
| System.out.println(json); | |
| }catch(Exception ex){ | |
| ex.printStackTrace(); | |
| } | |
| } | |
| public SaveClientRequest buildRequest(){ | |
| SaveClientRequestImpl request=new SaveClientRequestImpl(); | |
| ClientForm client=new ClientForm(); | |
| AddressForm address=new AddressForm(); | |
| address.setStreet("Av Corriente 3221"); | |
| address.setTown("Ciudad Autonoma de Buenos Aires"); | |
| client.setId(null); | |
| client.setName("Test Client"); | |
| client.setAddress(address); | |
| client.setLicensor(true); | |
| request.setModel(client); | |
| return request; | |
| } | |
| } | |
| import com.google.gwt.core.client.EntryPoint; | |
| import com.google.gwt.event.shared.SimpleEventBus; | |
| import com.google.gwt.user.client.ui.RootPanel; | |
| import com.sencha.gxt.widget.core.client.button.TextButton; | |
| import com.sencha.gxt.widget.core.client.container.Viewport; | |
| import com.sencha.gxt.widget.core.client.event.SelectEvent; | |
| import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler; | |
| public class VBITest implements EntryPoint { | |
| private TextButton jsonButton; | |
| @Override | |
| public void onModuleLoad() { | |
| this.jsonButton=new TextButton("JSON Writer"); | |
| this.jsonButton.addSelectHandler(new SelectHandler() { | |
| @Override | |
| public void onSelect(SelectEvent event) { | |
| processSelection(); | |
| } | |
| }); | |
| RootPanel.get().add(jsonButton); | |
| } | |
| protected void processSelection(){ | |
| JsonWriterTester tester=new JsonWriterTester(); | |
| SaveClientRequest request=tester.buildRequest(); | |
| tester.testWriter(request); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment