dynamic update data

63 views
Skip to first unread message

Aldin Habibović

unread,
Dec 24, 2012, 5:48:00 AM12/24/12
to google-web-toolkit
Hi guys,

I am developing pizza ordering application. I have two forms:

1) For inserting new pizza
2) and for ordering.

Here you can see:




When I insert a new pizza and go to check on combo box (picture ordering) I can't see my new pizza in combo box. The new pizza is inserted in my databases. The pizzas in combo box are from my database.

I have one idea.  But I don't think it is good. To use

    Timer t = new Timer() {
      public void run() {
        //display all pizza from my database every 2 se to combobox
      }
    };
t.schedule(2000);

Any idea for better approach???
Thanks

Jeffrey Chimene

unread,
Dec 24, 2012, 10:43:09 AM12/24/12
to google-we...@googlegroups.com
That's certainly one approach. There's nothing inherently wrong with polling. The interval will depend on your specific requirements.
If this is a classroom exercise, then it would be good to explore other models, some of which are available in the GWT universe.
A search of the list archives on publish/subscribe and push models will be rewarding.

Aldin Habibović

unread,
Dec 24, 2012, 10:54:44 AM12/24/12
to google-web-toolkit
Thank you for replying. Yes, this is for my final school project. What did you mean by "GWT universe". Is it tutorial ? :) When I click on my TabPanel ("Racun" or "Ordering pizza" tab) , I can also add this line of code: Window.Location.reload() to refresh the page to see new pizza which is added in my database.

Sebastián Gurin

unread,
Dec 24, 2012, 12:14:30 PM12/24/12
to google-we...@googlegroups.com
If the pizza objects that your client posses are not a very big number, then, instead updating against the server, you can mantain a local collection of pizzas in the client. I mean, write a class like PizzaHome or something like that that contains a collection or a map of pizzas. When you add a new pizza or remove a pizza, make a call to the server for adding/updating and then modify the local pizza home PizzaHome.getInstance().addNew(pizza1). The Pizza home can be an Observable that notify other interested part of your client when the local pizza collection changes. Also from time to time you can synchronize this PizzaHome with your server.

Aldin Habibović

unread,
Jan 1, 2013, 11:29:57 AM1/1/13
to google-web-toolkit
Happy New Year!

Your idea is not bad. But I don't know how to achieve your logic. I trying to implement your idea without success.
I can add my new pizza object to ArrayList of pizza objects but how to update the ListBox???


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/1VMHjsTx0o4J.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Sebastián Gurin

unread,
Jan 1, 2013, 5:30:19 PM1/1/13
to google-we...@googlegroups.com
define some class with a name like ClientContext or something like that. Let that class be the "home" of the client entities you want to manage (like your pizzas). This class is responsble of mantaining this "client entities" both by let you add/remove the entities and also let observers to subscribe to "entity changes". So when you add / remove entities you notify the observers. Then register a Entity change listener and when notified for an entity change, just update all the GUI components that need to be updated when you add/remove pizzas. Something like this:

public class ClientContext {
private List<Pizza> pizzas;
public void add(Pizza p) {
pizzas.add(p);
notifyAllListeners();
}
public void addPizzaListener(PizzaListener l){...}
public void notifyAllListeners(){for(PizzaListener l : listeners){l.notifyPizzasChange(); }}
}

..then on your GUI code...:
ClientContext.getInstance().addPizzaListener(new PizzaListener(){
public void notifyPizzasChange(){update the list box using ClientContext.getInstance().getPizzas()}
})

Hope this can clarify something... Happy new year to you too!

P/D: in these cases, I often find much more useful to have a Map<String, Pizza> for storing the pizzas by id. Also you can use a cheap map using Js Objects directly instead of java.util.Map implementations, like this: http://code.google.com/p/yuigwt/source/browse/trunk/yuigwt/src/org/sgx/yuigwt/yui/util/LWMap.java 
To unsubscribe from this group, send email to google-web-toolkit+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages