What is need History.fireCurrentHistoryState() in GWT History? - gwt

Hello I am working on a GWT sample history management application.
Here is my onModuleLoad Code.
public void onModuleLoad() {
ContentPanel panel = ContentPanel.getInstance();
if(History.getToken()!=null && History.getToken().length()==0)
{
History.newItem("first_page");
}
History.addValueChangeHandler(new HistoryHandler());
RootPanel.get().add(panel);
History.fireCurrentHistoryState();
}
In this I fired History.fireCurrentHistoryState(); to fire current state of history.
Now In my firstPanel class ther is button named Second Panel on which history token second_page is fired.
public FirstPanel() {
VerticalPanel panel = new VerticalPanel();
Button button2 = new Button("Second Panel");
button2.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
History.newItem("second_page");
}
});
panel.add(button2);
initWidget(panel);
}
But here no need to fire History.fireCurrentHistoryState() ; again.
simply histtory.newItem works fine.
Now I want to know that what the need of History.fireCurrentHistoryState() at module load time only?
Also why it is not required second time in the application.?

History.fireCurrentHistoryState() invokes your history handlers without actually inserting new history item in browser history stack, while History.newItem(token) does insert new history token into history stack.
Note: if your current token is the same as new token (i.e. same page is reloaded), then browsers do not insert this into history stack. In this case (current token == new token) History.fireCurrentHistoryState() has the same effect as History.newItem(currentToken).

Related

Hide Dialog from inside in LWUIT

I have created a Dialog with two buttons Yes, No, and then I have add action listener to them, my problem is that I want no button to hide the Dialog that I have created
the code is looks like:
dialog = new Dialog(title);
dialog.setDialogType(Dialog.TYPE_CONFIRMATION);
ta = new TextArea(text);
ta.getStyle().setBorder(Border.createEmpty());
ta.setEditable(false);
yesCommand = new Button("YES");
noCommand = new Button("NO");
yesCommand.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
LGBMainMidlet.getLGBMidlet().notifyDestroyed();
}
});
noCommand.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
Logger.Log("Bye Bye");
dialog = null;
System.gc();
}
});
dialog.addComponent(ta);
dialog.addComponent(yesCommand);
dialog.addComponent(noCommand);
dialog.show();
the code is not working for me, can anyone told me what is the problem?
B.N. I have used dialog.dispose(), but it exit the whole application
It is better to use
dialog.setTimeout(1000); the number show the time limit the dialog box wait in milliseconds. So by doing this you can exit the dialog form automatically.
Dialog.dispose() does not exit the whole application, it just closes the dialog.
If you have nothing in your application you might see nothing if you dispose the dialog.

On click is not refreshing the tabledata

Hi I have been trying to reinitiate the data in a table by using an onClick handler
But when I click the data the older data persists and along with that the new data is coming up
Kindly let me know how can I resolve this issue
Thanks in advance
private void showErrorButton() {
//super.initWidget(widget);
_displayAlerts.addClickHandler(new ClickHandler() {
/**
* Click event for hiding dialog box.
*/
public void onClick(final ClickEvent arg0) {
getCustomDialog().getDialogBox().center();
getCustomDialog().getDialogBox().show();
showDialogBox(_errorList,_warnList);
}
});
}
It seems like you are not clearing the old data from your table before populating it with new data.
If you're using a Panel (GWT Javadoc) (or any subclass of Panel such as HTMLTable, FlexTable, etc.) you should call the method clear() before adding the new data.
void onClick(...) {
yourTable.clear();
yourTable.addNewData();
}
I'll change my answer as I learn more about your specific problem if this doesn't help.

Block gwt DisclosurePanel on open state

How may I block a gwt DisclosurePanel on the open state ?
I mean, how can I prevent this DisclosurePanel to close if the user click the header more than once ?
(My header is a textBox, I want the user to enter a text, and the panel should remain open if the user unfocus the textBox and focus newly by clicking it. The DisclosurePanel content has a "cancel" button that closes the panel)
Thank you very much.
I edit my question after 2 first answers: I would like to avoid to reopen the DisclosurePanel once closed to avoid flashing effect. I actually want to prevent the DisclosurePanel to close. Maybe sinkEvents can help me... if so, how? Thanks.
A NativePreviewHandler receives all events before they are fired to their handlers. By registering a nativePreviewHandler the first time your disclosurePanel is opened, you can cancel the click event. You can later decide to remove this handler by preventClose.removeHandler();
HandlerRegistration preventClose = null;
....
panel.addOpenHandler(new OpenHandler<DisclosurePanel>() {
#Override
public void onOpen(OpenEvent<DisclosurePanel> event) {
if (preventClose == null){
preventClose = Event.addNativePreviewHandler(new NativePreviewHandler() {
#Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
if (event.getTypeInt()==Event.ONCLICK && event.getNativeEvent().getEventTarget() == panel.getHeader().getElement().cast())
event.cancel();
}
});
}
}
});
The obvious answer is review the javadoc here: https://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/DisclosurePanel.html
There is a setOpen() method that: Changes the visible state of this DisclosurePanel.
Set it to false from a click event to capture the user action.
The JavaDoc is right here: https://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/ui/DisclosurePanel.html
jamesDrinkard pointed the old 1.5 javadoc.
You can use the addCloseHandler(CloseHandler<DisclosurePanel> handler) method to add a handler so when the user tries to close it you can reopen it again with setOpen().
Maybe not the best way, but it worked for me (maybe just one of both will work too):
dPanel.setOpen(true);
dPanel.addOpenHandler(new OpenHandler<DisclosurePanel>() {
#Override
public void onOpen(OpenEvent<DisclosurePanel> event) {
dPanel.setOpen(true);
}
});
dPanel.addCloseHandler(new CloseHandler<DisclosurePanel>() {
#Override
public void onClose(CloseEvent<DisclosurePanel> event) {
dPanel.setOpen(true);
}
});

Postback parent page when using an ASP.NET ModalPopup control

I have a custom UserControl that displays a modal popup (from the Ajax Toolkit). The control allows the user to add a note to a customer record which the parent page displays in a GridView.
I'm unable to force the parent page to reload the grid after the user clicks the "Add Note" button on the modal popup and closes it. The note is added to the database correctly, but I have to manually refresh the page to get it to display instead of it automatically refreshing when I save+close the popup.
You can use a delegate to fire an event in parent page after note is added to the database.
// Declared in Custom Control.
// CustomerCreatedEventArgs is custom event args.
public delegate void EventHandler(object sender, CustomerCreatedEventArgs e);
public event EventHandler CustomerCreated;
After note is added, fire parent page event.
// Raises an event to the parent page and passing recently created object.
if (CustomerCreated != null)
{
CustomerCreatedEventArgs args = new CustomerCreatedEventArgs(objCustomerMaster.CustomerCode, objCustomerMaster.CustomerAddress1, objCustomerMaster.CustomerAddress2);
CustomerCreated(this, args);
}
In parent page, implement required event to re-fill grdiview.
protected void CustomerCreated(object sender, CustomerCreatedEventArgs e)
{
try
{
BindGridView();
}
catch (Exception ex)
{
throw ex;
}
}
In your case, you can not use any custom event args, and use EventArgs class itself.

How do you rebuild the GWT History stack?

I have a larger application that I'm working with but the GWT History documentation has a simple example that demonstrates the problem. The example is copied for convenience:
public class HistoryTest implements EntryPoint, ValueChangeHandler
{
private Label lbl = new Label();
public void onModuleLoad()
{
Hyperlink link0 = new Hyperlink("link to foo", "foo");
Hyperlink link1 = new Hyperlink("link to bar", "bar");
Hyperlink link2 = new Hyperlink("link to baz", "baz");
String initToken = History.getToken();
if (initToken.length() == 0)
{
History.newItem("baz");
}
// Add widgets to the root panel.
VerticalPanel panel = new VerticalPanel();
panel.add(lbl);
panel.add(link0);
panel.add(link1);
panel.add(link2);
RootPanel.get().add(panel);
History.addValueChangeHandler(this); // Add history listener
History.fireCurrentHistoryState();
}
#Override
public void onValueChange(ValueChangeEvent event)
{
lbl.setText("The current history token is: " + event.getValue());
}
}
The problem is that if you refresh the application, the history stack gets blown away. How do you preserve the history so that if the user refreshes the page, the back button is still useful?
I have just tested it with Firefox and Chrome for my application and page refresh does not clear the history. Which browser do you use? Do you have the
<iframe src="javascript:''" id='__gwt_historyFrame' style='position:absolute;width:0;height:0;border:0'></iframe>
in your HTML?
GWT has catered for this problem by providing the History object. By making a call to it's static method History.newItem("your token"), you will be able to pass a token into your query string.
However you need to be aware that any time there is a history change in a gwt application, the onValueChange(ValueChangeEvent event){} event is fired, and in the method you can call the appropriate pages. Below is a list of steps which i use to solve this problem.
Add a click listener to the object that needs too call a new page. In handling the event add a token to the history.(History.newItem("new_token").
Implement the ValueChangeHandler in the class that implements your EntryPoint.
Add onValueChangeHandler(this) listener to the class that implements the EntryPoint. Ensure that the line is add in the onModuleLoad() method (it is important it is added in this method) of the class that implements the EntryPoint(pretty obvious ha!)
Finally implement onValueChange(ValueChangeEvent event){ //call a new page } method.
That's it