facebook

Customize GWT

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

    I’m an italian student and I have bought myeclipse for spring.
    I have to learn to use GWT UI for my application.
    I have read your tutorial about generating an application with Scaffolding help.
    I have generated my first application with yours suggestions and using my db.
    Now I want to understand well the life cicle of GWT and I have to adding new features, new functions to application created.
    I want to understand very well what Scaffold have generated and I want to be able to adding my logic to
    the application, not just CRUD operations.

    Is there another tutorial, another guide that can help me to adding new fuction to my application?

    I’m sure that you can help me. I hope you want to do it.
    Great regards.

    #317628 Reply

    jkennedy
    Member

    Hello,
    Glad to hear that you are using the product, and thanks for the post.

    I hope that the scaffolding capability helps you to move forward quickly in your understanding of GWT and the other related technologies.

    I understand your question about looking to add additional “non crud” based functionality to the application, and we of course would like to help you. You will need to make an investment in understanding the code that was generated as a next step however.

    Can you tell me which version of GWT you generated for?

    We do not have a broader tutorial on GWT as a language, etc since this is the domain of the Google team and its community, but once you understand the best practices that are being employed, and the code that was generated in support of those best practices, then it will become easier for you to see the path for adapting the code to other goals.

    If you are using GWT 2.1 or greater, I would recommend that you review information about GWT MVP architecture.

    Also, understanding RequestFactory is ideal: http://code.google.com/webtoolkit/doc/latest/DevGuideRequestFactory.html as well as Places and Activities: http://code.google.com/webtoolkit/doc/latest/DevGuideMvpActivitiesAndPlaces.html

    Thanks,
    Jack

    #317757 Reply

    Thanks for your answer and for your links.
    I’ve studied all documents, and now i’ve a more clean idea about GWT 2.2 UI flow. But another one help is necessary.
    i’ve created an elementary DB with two tables (Suppliers and Requests) joined n to n relation resolved with a
    third table named Suppliers_has_Requests.
    So, with this DB and MyEclipse4Spring I’ve created a scaffolding project named myproject (you can see it at
    the following link: http://code.google.com/p/myproject-stasbranger/source/browse).
    Now, I want to add another functionality at the CRUD operation just created. I want, for example, to list all
    the Requests sent to a specific Supplier in a range of dates.
    So I want to add two calendar widgets and one button to UI and I want to add relative logic at the project.
    Can you help me to develop this use case?

    If you want you can dowload my project. My db is in WEB/myDB folder.
    http://code.google.com/p/myproject-stasbranger/source/browse

    Thanks a lot in advance.

    #317887 Reply

    jkennedy
    Member

    Hello,
    Sorry for the delay in responding.

    And so if we break your use case down into its two main parts, it sounds like you are asking.

    1. How do I add the back end capability to return a list of Requests that fall between two dates
    2. How do I add two date fields to a user interface and pass them to the server to load the result set into the list

    As with most coding tasks, there are a few ways you could do it, i will cover the basics of one approach.

    Lets start with the Service. We already have the RequestService and RequestServiceImpl that has a findAllRequests(Integer start, Integer maxRows) method.

    You can add a new method to the Service interface and Service impl called findAllRequestsByDate(Integer start, Integer max, Date after, Date before) that will return Requests within your date range.

    Now we have our Service contract for this capability defined, and you can implement the findAllRequestsByDate() method with the code to load the data.
    To implement that method, add code like this: (You can look at the NamedQueries in your entity for guidance on the query strings).

    
    public List<Request> findAllRequestsByDate(Integer startResult, Integer maxRows, Date after, Date before) {
            Query query = requestDAO.createQuery("select myRequest from Request myRequest where myRequest.submitted > ?1 and myRequest.submitted < ?2", startResult, maxRows, after, before);
            return new java.util.ArrayList<Request>(query.getResultList());
        }
    

    Now we need to update the Class that controls the Service access to the GWT Layer.
    Open RequestRequest and add a line for your new method (look at the existing findAllRequests method in this class for guidance.

    OK, that is the back end, for the front end, again you have a few options, but here are the basic concepts.

    Open the RequestRequest interface that you just modified, and double click on the findAllRequests method name, right click, and select References / Workspace

    This will help you find the code that is calling from the GWT front end to the GWT RequestHandler that is managing calls to your Service.

    You will see that the only caller is the RequestListActivity class.

    The code should read something like:

    
    protected Request<List<gwt.client.managed.request.RequestProxy>> createRangeRequest(Range range) {
            return requests.requestRequest().findAllRequests(range.getStart(), range.getLength());
        }
    

    Change this method to call your findAllRequestsByDate method and leave the dates blank for now, we will next add the UI code to collect the dates to pass in.

    Lets start by adding the ability for ProxyListView’s to expose SearchCriteria. You can make your own object model here, but to demonstrate, open ProxyListView and add a method like:

    
    Object[] getSearchCriteria()
    

    Next, we will want to add the actual Date fields to the view.
    Open the RequestListView.ui.xml file and add something like this above the <b:CellTable>:

    
     After:<dp:DateBox ui:field='after'></dp:DateBox>
     Before:<dp:DateBox ui:field='before'></dp:DateBox
    

    Next, you need to add the Java entries in the RequestListView.java for these controls.
    Open RequestListView.java and add:

    
    @UiField
    DateBox after;
        
    @UiField
    DateBox before;
    

    Now add code to implement the getSearchCriteria in the RequestListView object

    
    @Override
        public Object[] getSearchCriteria() {
            return new Object[] {after.getValue(), before.getValue()};
        }
    

    Add this code to the constructor of RequestListView to register code that will refresh the list when the date values change. You can do additional work to move this code out of the view, this is an example.

    
    ValueChangeHandler<Date> dateRangeHandler = new ValueChangeHandler<Date>() {
                @Override
                public void onValueChange(ValueChangeEvent<Date> arg0) {
                    asHasData().setVisibleRange(asHasData().getVisibleRange());
                }
            };
            
            after.addValueChangeHandler(dateRangeHandler);
            before.addValueChangeHandler(dateRangeHandler);
    

    Now we can go back and fill in our blank dates in RequestListActivity with dates from the UI.
    open the createRangeRequest method and change it to look like:

    
    protected Request<List<gwt.client.managed.request.RequestProxy>> createRangeRequest(Range range) {
            Object[] params = getView().getSearchCriteria();
            Date after = (Date)params[0];
            Date before = (Date)params[1];
            
            if (after != null && before != null)
                return requests.requestRequest().findAllRequestsByDate(range.getStart(), range.getLength(), after, before);
            else
                return requests.requestRequest().findAllRequests(range.getStart(), range.getLength());
        }
    

    Obviously, you need to clean this up, add null checking, error handling, and likely a full fledged Object for managing SearchCriteria. You could also pass SearchCriteria back and forth to the Server if you like.
    The goal of this post was to give you some specific examples of how you could modify the generated code and to see the major touchpoints.

    Hope this helps.
    Jack

    #317927 Reply

    Ok Jack your help is very appreciated and I’ve implemented all. It’s works fine.

    But I’ve a question: why you have to call createRangeRequest method and in particular way why it doesn’t refresh the view when I type a date?

    I explain better: when you insert the date (after and before) the requests list doesn’t refresh itself.
    It works only if I run another action for example I add or delete an item from list.

    So when I click delete button the placeController calls goTo(getEditButtonPlace()) then updates the list
    view. I’ve tried to add another button near After and Before fields. This button has to update the list view.
    So in RequestsListActivity class I’ve added this code:

    public void searchClicked() {
    requests.requestsRequest().fire(new Receiver<Void>() {
    public void onSuccess(Void ignore) {
    // Go back to the previous place.
    placeController.goTo(getBackButtonPlace());
    }
    });

    but this placeController.goTo method doesn’t work fine and doesn’t update the view.

    How can you help me? what I’m mistaking? Thanks.

    #317958 Reply

    jkennedy
    Member

    Sorry, I updated this code locally but neglected to update the code in the post before submitting.

    You need to change this:
    asHasData().setVisibleRange(asHasData().getVisibleRange());

    to this:
    asHasData().setVisibleRangeAndClearData(asHasData().getVisibleRange(), true);

    Sorry about that!
    Jack

    #317972 Reply

    have you got some document to explain the lifecycle of GWT generated by ME4S???

    #317990 Reply

    jkennedy
    Member

    Hey there,
    All of our documentation is public at this point, we do not have a lifecycle document.

    Thanks,
    jack

    #318002 Reply

    how can i know which are the lifecycle create on ME4S??? it’s important for me to modify properly my project! Please help me

    #318003 Reply

    how can i know which are the lifecycle create on ME4S??? it’s important for me to modify properly my project! Please help me

    #318005 Reply

    jkennedy
    Member

    Sorry, it is not clear to me what you are asking for?

    We have been working to try to assist you on your path towards learning GWT. The tooling provides you with generated code, we have provided you with an example of how to modify and extend that generated code, and we have pointed you to documentation on GWT best practices as provided by the GWT community.

    We do not have anything additional to offer you at this point, but as always we look forward to your feedback.

    Thanks,
    Jack

Viewing 11 posts - 1 through 11 (of 11 total)
Reply To: Customize GWT

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