Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7932029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:53:30+00:00 2026-06-03T20:53:30+00:00

I’m getting acquainted with GWTP. I tried to output a table, that would contain

  • 0

I’m getting acquainted with GWTP. I tried to output a table, that would contain the JSON values, taken with a help of Piriti mappers. It’s not a real project’s code, it’s just an attempt to understand GWTP, so this may be not the most beautiful solution (in fact, it’s not one for sure). Here are the two presenters that are involved in this procedure:

The FirstPresenter (that uses ProductListPresenter, that is a widget, I’m not sure that widget should be used here, but, according to this conversation, widget may do the trick):

public class FirstPresenter extends
        Presenter<FirstPresenter.MyView, FirstPresenter.MyProxy> {

    public static final Object SLOT_RATE = new Object();
    public static final Object SLOT_PRODUCT = new Object();
    private IndirectProvider<ProductListPresenter> productListFactory;

    public interface MyView extends View {
        public Panel getListProductPanel();
    }

    @Inject ProductListPresenter productListPresenter;

    @ProxyCodeSplit
    @NameToken(NameTokens.first)
    public interface MyProxy extends ProxyPlace<FirstPresenter> {
    }

    @Inject
    public FirstPresenter(final EventBus eventBus, final MyView view,
            final MyProxy proxy, Provider<ProductListPresenter> productListFactory) {
        super(eventBus, view, proxy);

        this.productListFactory = new StandardProvider<ProductListPresenter>(productListFactory);
    }

    @Override
    protected void revealInParent() {
    }

    @Override
    protected void onBind() {
        super.onBind();
    }

    @Inject
    PlaceManager placeManager;

    @Override
    protected void onReset() {
        super.onReset();
        setInSlot(SLOT_PRODUCT, null);
        for (int i = 0; i < 2; i++) { //TODO: change hardcoded value 

            productListFactory.get(new AsyncCallback<ProductListPresenter>() {

                @Override
                public void onSuccess(ProductListPresenter result) {
                        addToSlot(SLOT_PRODUCT, result);
                }

                @Override
                public void onFailure(Throwable caught) {

                }
            });

        }
    }

}

The ProductListPresenter:

public class ProductListPresenter extends
        PresenterWidget<ProductListPresenter.MyView> {

    @Inject ProductListPiritiJsonReader reader;

    public interface MyView extends View {
        public Label getNameLabel();
        public Label getCompanyLabel();
        public Label getSerialLabel();
        public Label getPricesLabel();
    }

    @Inject
    public ProductListPresenter(final EventBus eventBus, final MyView view) {
        super(eventBus, view);
    }

    @Override
    protected void onBind() {
        super.onBind();
    }

    @Override
    protected void onReset() {
        super.onReset();

        try {
            RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, "/jsongwtproject/products.json");
            rb.setCallback(new RequestCallback() {
                @Override
                public void onResponseReceived(Request request, Response response) {
                    ProductList productList = reader.read(response.getText());
                    for (Product product : productList.getProductList()) {
                        fetchDataFromServer();
                    }
                }
                @Override
                public void onError(Request request, Throwable exception) {
                    Window.alert("Error occurred" + exception.getMessage());
                }
            });
            rb.send();
        } 
        catch (RequestException e) {
            Window.alert("Error occurred" + e.getMessage());
        }
    }
    //Takes the JSON string and uses showProductListData(String jsonString)  method
    public void fetchDataFromServer() {
        try {
            RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, "/jsongwtpproject/products.json");
            rb.setCallback(new RequestCallback() {
                @Override
                public void onResponseReceived(Request request, Response response) {
                    showProductListData(response.getText());                    
                }
                @Override
                public void onError(Request request, Throwable exception) {
                    Window.alert("Error occurred" + exception.getMessage());
                }
            });
            rb.send();
        } 
        catch (RequestException e) {
            Window.alert("Error occurred" + e.getMessage());
        }
    }
    //Uses Piriti mappers to take JSON values
    private void showProductListData(String jsonString) {
        ProductList productList = reader.read(jsonString);
        for (Product product : productList.getProductList()) {
            StringBuffer priceSb = new StringBuffer();
            for (Double price : product.getPrices()) {
                priceSb.append(price + ", ");
            }

            getView().getNameLabel().setText(product.getName());
            getView().getCompanyLabel().setText(product.getCompany());
            getView().getSerialLabel().setText(product.getSerialNumber());
            getView().getPricesLabel().setText(priceSb.toString());
            //break;

        }
    }   

}

And the ProductListView.ui.xml:

<g:HTMLPanel>
<table border="1">
    <tr>
        <td><g:Label ui:field="nameLabel" /> </td>
        <td><g:Label ui:field="companyLabel" /> </td> 
        <td><g:Label ui:field="serialLabel" /> </td>
        <td><g:Label ui:field="pricesLabel" /> </td> 
    </tr>
    </table>
</g:HTMLPanel> 

Currrently there are two products in the JSON.

Here is what happens with this code: the first row with Product1 appears, then it changes to the first row that contains Product2‘s values, then again it contains Product1‘s values, then again Product2‘s, after that the second row with Product1 appears, then it changes to the second row that contains Product2‘s values, then again it contains Product1‘s values, then again Product2‘s.

So, there are two products and two rows, and in this code the values are changed twice, but in the end the table contains only Product2‘s values. If the break; is uncommented, Product1‘s values output twice in the first row, then in the second row, then the table contain only these Product1‘s values.

I do understand why that happens. But I haven’t yet figured out how to make the correct output. It’d be great if someone could tell me how to do the correct output, or, well, provide an example (or would tell me which part, e.g. the widget usage, is terribly wrong).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:53:32+00:00Added an answer on June 3, 2026 at 8:53 pm

    The problem with your code is that you really don’t have a real table in your ProductListView.ui.xml.

    Of course if there were two records retrieved from the server, this part of the code is called twice:

    getView().getNameLabel().setText(product.getName());
    getView().getCompanyLabel().setText(product.getCompany());
    getView().getSerialLabel().setText(product.getSerialNumber());
    getView().getPricesLabel().setText(priceSb.toString());
    

    the second call overwriting the value from the first call.

    Points to improve your code:

    1. You may want to read about CellTable for creating a real table view.
    2. Do not use the PresenterWidget itself as data holder, instead create
      a DTO that will be pass to the database and use this to retrieve the
      data.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.