Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I guess <a href="https://github.com/chieukam/gwt-spring-hibernate-tutorial" rel="nofollow">this one</a> using <a href="https://github.com/chieukam/gwt-spring-hibernate-tutorial/blob/master/pom.xml#L15" rel="nofollow">gwt 2.5.0-rc1</a>, <a href="https://github.com/chieukam/gwt-spring-hibernate-tutorial/blob/master/pom.xml#L16" rel="nofollow">Spring 3.1.2.RELEASE</a> and <a href="https://github.com/chieukam/gwt-spring-hibernate-tutorial/blob/master/pom.xml#L94" rel="nofollow">Hibernate 4</a> will be helpful. This project is using <a href="http://maven.apache.org/download.cgi" rel="nofollow">maven</a>, so install maven which will take care of required dependencies. <code>git clone</code> it, <a href="http://maven.apache.org/run-maven/index.html" rel="nofollow">command-line build</a> with <code>$ mvn clean install</code> and dive into.</p> <h2>The basic gwt server-shared-client architecture is </h2> <h2>Entity</h2> <pre><code>@Entity @Table(name = "TBL_BOOK") public class Book implements Serializable { private static final long serialVersionUID = -687874117917352477L; @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "ID") private Long id; @Column(name = "TITLE", nullable = false) private String title; @Column(name = "SUBTITLE") private String subtitle; @Column(name = "AUTOR", nullable = false) private String autor; @Column(name = "DESCRIPTION") private String description; @Column(name = "ISBN") private String isbn; @Column(name = "GENRE") private String genre; @Temporal(TemporalType.DATE) @Column(name = "PUBLISHED_DATE") private Date publishedDate; @Column(name = "PUBLISHER") private String publisher; public Book() { } public Book(Long id, String title, String subtitle, String autor, String description, String isbn, String genre, Date publishedDate, String publisher) { this.id = id; this.title = title; this.subtitle = subtitle; this.autor = autor; this.description = description; this.isbn = isbn; this.genre = genre; this.publishedDate = publishedDate; this.publisher = publisher; } public Book(Book bookDTO) { this.id = bookDTO.getId(); this.title = bookDTO.getTitle(); this.subtitle = bookDTO.getSubtitle(); this.autor = bookDTO.getAutor(); this.description = bookDTO.getDescription(); this.isbn = bookDTO.getIsbn(); this.genre = bookDTO.getGenre(); this.publishedDate = bookDTO.getPublishedDate(); this.publisher = bookDTO.getPublisher(); } //getters and setters @Override public String toString() { return "Book [id=" + id + ", title=" + title + ", subtitle=" + subtitle + ", author=" + autor + ", description=" + description + ", isbn=" + isbn + ", genre=" + genre + ", publishedDate=" + publishedDate + ", publisher=" + publisher + "]"; } } </code></pre> <h2>web configuration</h2> <pre><code>&lt;!-- SpringGwt remote service servlet --&gt; &lt;servlet&gt; &lt;servlet-name&gt;springGwtRemoteServiceServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;org.spring4gwt.server.SpringGwtRemoteServiceServlet&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;springGwtRemoteServiceServlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/GwtSpringHibernate/springGwtServices/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <h2>Client side stub for RPC</h2> <pre><code>/** * The client side stub for the RPC service. */ @RemoteServiceRelativePath("springGwtServices/bookService") public interface BookService extends RemoteService { public void saveOrUpdate(Book book) throws Exception; public void delete(Book book) throws Exception; public Book find(long id); public List&lt;Book&gt; findAllEntries(); } </code></pre> <h2>Server</h2> <pre><code>@Service("bookService") public class BookServiceImpl extends RemoteServiceServlet implements BookService { private static final long serialVersionUID = -6547737229424190373L; private static final Log LOG = LogFactory.getLog(BookServiceImpl.class); @Autowired private BookDAO bookDAO; @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public void saveOrUpdate(Book book) throws Exception { // } @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public void delete(Book book) throws Exception { // } public Book find(long id) { return bookDAO.findById(id); } public List&lt;Book&gt; findAllEntries() { // } } </code></pre> <h2>Client View</h2> <pre><code>/** * Entry point classes define &lt;code&gt;onModuleLoad()&lt;/code&gt;. */ public class GwtSpringHibernate implements EntryPoint { /** * The message displayed to the user when the server cannot be reached or * returns an error. */ private static final String SERVER_ERROR = "An error occurred while " + "attempting to contact the server. Please check your network " + "connection and try again."; /** * Create a remote service proxy to talk to the server-side Book service. */ private final BookServiceAsync bookService = GWT.create(BookService.class); /** * This is the entry point method. */ public void onModuleLoad() { DateBox.DefaultFormat defaultFormatter = new DateBox.DefaultFormat(DateTimeFormat.getFormat("dd.MM.yyyy")); // Add new Book Area final TextBox titleField = new TextBox(); titleField.setFocus(true); final TextBox subtitleField = new TextBox(); final TextBox autorField = new TextBox(); final TextBox descriptionField = new TextBox(); final TextBox isbnField = new TextBox(); final TextBox genreField = new TextBox(); final DateBox publishedDateField = new DateBox(); publishedDateField.setFormat(defaultFormatter); final TextBox publisherField = new TextBox(); final Button saveButton = new Button("Save"); saveButton.addStyleName("button"); final Button retrieveButton = new Button("Retrieve"); retrieveButton.addStyleName("button"); final Label errorLabel = new Label(); // Add fields to the Rootpanel RootPanel.get("title").add(titleField); RootPanel.get("subtitle").add(subtitleField); RootPanel.get("autor").add(autorField); RootPanel.get("description").add(descriptionField); RootPanel.get("isbn").add(isbnField); RootPanel.get("genre").add(genreField); RootPanel.get("publishedDate").add(publishedDateField); RootPanel.get("publisher").add(publisherField); RootPanel.get("btnSave").add(saveButton); RootPanel.get("btnRetrieveAllEntries").add(retrieveButton); RootPanel.get("errorLabelContainer").add(errorLabel); // Create the popup dialog box final DialogBox dialogBox = new DialogBox(); dialogBox.setText("Remote Procedure Call"); dialogBox.setAnimationEnabled(true); final Button closeButton = new Button("Close"); // We can set the id of a widget by accessing its Element closeButton.getElement().setId("closeButton"); final Label textToServerLabel = new Label(); final HTML serverResponseLabel = new HTML(); VerticalPanel dialogVPanel = new VerticalPanel(); dialogVPanel.addStyleName("dialogVPanel"); dialogVPanel.add(new HTML("&lt;b&gt;Sending request to the server:&lt;/b&gt;")); dialogVPanel.add(textToServerLabel); dialogVPanel.add(new HTML("&lt;b&gt;Server replies:&lt;/b&gt;")); dialogVPanel.add(serverResponseLabel); dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT); dialogVPanel.add(closeButton); dialogBox.setWidget(dialogVPanel); // Add a handler to close the DialogBox closeButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { dialogBox.hide(); saveButton.setEnabled(true); saveButton.setFocus(true); retrieveButton.setEnabled(true); } }); class SaveBookHandler implements ClickHandler, KeyUpHandler { public void onKeyUp(KeyUpEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { saveBook(); } } public void onClick(ClickEvent arg0) { saveBook(); } private void saveBook() { errorLabel.setText(""); String _title = titleField.getText(); String _subtitle = subtitleField.getText(); String _autor = autorField.getText(); String _desc = descriptionField.getText(); String _isbn = isbnField.getText(); String _genre = genreField.getText(); Date _publishedDate = publishedDateField.getValue(); String _publisher = publisherField.getText(); // First, we validate the input. if (Validator.isBlank(_title) || Validator.isBlank(_autor)) { String errorMessage = "Please enter at least the Title and the Autor of the book"; errorLabel.setText(errorMessage); return; } Book bookDTO = new Book(null, _title, _subtitle, _autor, _desc, _isbn, _genre, _publishedDate, _publisher); saveButton.setEnabled(false); serverResponseLabel.setText(""); textToServerLabel.setText(bookDTO.toString()); bookService.saveOrUpdate(bookDTO, new AsyncCallback&lt;Void&gt;() { public void onFailure(Throwable caught) { dialogBox.setText("Remote Procedure Call - Failure"); serverResponseLabel.addStyleName("serverResponseLabelError"); serverResponseLabel.setHTML(SERVER_ERROR + caught.toString()); dialogBox.center(); closeButton.setFocus(true); } public void onSuccess(Void noAnswer) { dialogBox.setText("Remote Procedure Call"); serverResponseLabel.removeStyleName("serverResponseLabelError"); serverResponseLabel.setHTML("OK"); dialogBox.center(); closeButton.setFocus(true); } }); } } // Add a handler to send the book info to the server SaveBookHandler saveBookHandler = new SaveBookHandler(); saveButton.addClickHandler(saveBookHandler); publisherField.addKeyUpHandler(saveBookHandler); // Create a handler for the retrieveButton class RetrieveAllEntriesHandler implements ClickHandler { /** * Fired when the user clicks on the retrieveButton. */ public void onClick(ClickEvent event) { retrieveAllEntries(); } private void retrieveAllEntries() { // Nothing to validate here // Then, we send the input to the server. retrieveButton.setEnabled(false); errorLabel.setText(""); textToServerLabel.setText(""); serverResponseLabel.setText(""); bookService.findAllEntries( new AsyncCallback&lt;List&lt;Book&gt;&gt;() { public void onFailure(Throwable caught) { // Show the RPC error message to the user dialogBox.setText("Remote Procedure Call - Failure"); serverResponseLabel.addStyleName("serverResponseLabelError"); serverResponseLabel.setHTML(SERVER_ERROR + caught.toString()); dialogBox.center(); closeButton.setFocus(true); } public void onSuccess(List&lt;Book&gt; data) { dialogBox.setText("Remote Procedure Call"); serverResponseLabel.removeStyleName("serverResponseLabelError"); if(data != null &amp;&amp; !data.isEmpty()){ StringBuffer buffer = new StringBuffer(); for (Book book : data) { buffer.append(book.toString()); buffer.append("&lt;br /&gt;&lt;br /&gt;"); } serverResponseLabel.setHTML(buffer.toString()); } else { serverResponseLabel.setHTML("No book information store in the database."); } dialogBox.center(); closeButton.setFocus(true); } }); } } // Add a handler RetrieveAllEntriesHandler retrieveAllEntriesHandler = new RetrieveAllEntriesHandler(); retrieveButton.addClickHandler(retrieveAllEntriesHandler); } } </code></pre> <p>For more widgets, go through <a href="https://developers.google.com/web-toolkit/doc/1.6/RefWidgetGallery" rel="nofollow">official widget library</a>, <a href="https://developers.google.com/web-toolkit/tools/gwtdesigner/wizards/gwt/uibinder_composite" rel="nofollow">UiBinder</a>. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload