On click is not refreshing the tabledata - gwt

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.

Related

How to access the currently selected item within Wicket Palette

I am trying to override certain features of the Wicket Palette. I have attached a picture of what i am trying to accomplish with Palette. Basically in addition to the select-item-clickbutton-moveToRight functionality of Palette, I also want to know which item has been selected before it is moved. When I select an item in either of the panels and click on a View button, I should be able to display an html page related to the currently selected item from the Palette.
Right now, the button is placed out of the Palette code and as long as I can get the ID of the selected element, I will be able to accomplish my objective.
I am stuck at the point where I need to know which item has been selected within the palette.
Here's what I have tried so far:
1. Adding an onclick listener to the choicesComponent using the AjaxFormComponentUpdatingBehavior
final Palette classFormMapping = new Palette("formsPalette", new ListModel(selectedFormsList),
formsList, new CustomObjectChoiceRenderer(), 8 , false ){
#Override
protected void onBeforeRender() {
super.onBeforeRender();
getChoicesComponent().add(new AjaxFormComponentUpdatingBehavior("onclick"){
#Override
protected void onUpdate(AjaxRequestTarget target) {
System.out.println("REACHED HERE"+ getFormComponent());
/*
* The code reaches here for each click but I am unable to know which item was selected */
}
});
}
};
Adding a Recorder component to the Palette with an "onclick" listener.
This listener does not get called at all.
final Palette classFormMapping = new Palette("formsPalette", new ListModel(selectedFormsList),
formsList, new CustomObjectChoiceRenderer(), 8 , false ){
protected Recorder newRecorderComponent() {
Recorder recorder = super.newRecorderComponent();
recorder.add(new AjaxFormComponentUpdatingBehavior("onclick") {
private static final long serialVersionUID = 1L;
#Override
protected void onUpdate(AjaxRequestTarget target) {
System.out.println("reached record on click ");
}
});
return recorder;
}
};
Trying to create this palette with a custom button
Please help. Thanks in advance.
Palette.java javadoc explains how to "Ajax-ify" it: https://github.com/apache/wicket/blob/529db58c413861677f7ff6736f9363edf42ae85a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/Palette.java#L52-L71
But this won't help you because the selection is done at the client side first and then Wicket is notified:
https://github.com/apache/wicket/blob/529db58c413861677f7ff6736f9363edf42ae85a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/palette.js#L118-L127
You need either to register your own JS event listener for 'change' event before the Wicket one or monkey-patch palette.js to override Wicket.Palette.updateRecorder() function.

How to don't validate form with Ajax buttons

I have a problem with validation on form actually sub-form.
In my website I have some kind of table and "Add row" button (BlockingAjaxSubmitLink).
When I try add let say 2 rows, I get validation error (because row in this table has Required=True parameter) and I can't add another row. I tried use simple AjaxLink but it doesn't have reference to form in onClick method and when I complete some rows and click "Add row" this data get lost.
I want to enable validation only after "save" button click.
Any idea how to deal with this problem?
I do something like you want using an AjaxLink.
My AjaxLink:
private AjaxLink addNewRow = new AjaxLink("addNewRow") {
#Override
public void onClick(AjaxRequestTarget target) {
MyEntityObject newTableRowObject = new MyEntityObject(irrelevantParameter);
entityObjectTableService.createNewRowInDB(newTableRowObject );
target.add(listViewContainer);
}
};
In this code the listViewContainer is a WebMarkupContainer which contains a ListView holding the table rows.
When i click this AjaxLink a new object representing a row in my table is added to the database and then the container containing the ListView is being refreshed refreshing the ListView and the new empty object is being fetched from the DB and shown as a new row in my table at the end.
Depending on your structure maybe you are looking after disabling validation using setDefaultFormProcessing(true); - http://ci.apache.org/projects/wicket/apidocs/6.x/org/apache/wicket/markup/html/form/AbstractSubmitLink.html#setDefaultFormProcessing%28boolean%29
For now I write some kind of hack
First I set
addKnowledgeLink.setDefaultFormProcessing(false);
and next
BlockingAjaxSubmitLink<Object> addKnowledgeLink = new BlockingAjaxSubmitLink<Object>(
"link_knowledge_add") {
#Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
ChangeDataForm.this.process(this);
/* some code */
target.add(form.get(MY_CONTAINER_ID));
}
(...)
and my hack...
//HACK
public void process(IFormSubmitter object){
if (!isEnabledInHierarchy() || !isVisibleInHierarchy())
{
return;
}
// run validation
validate();
/*if (hasError())
{
// mark all children as invalid
markFormComponentsInvalid();
// let subclass handle error
callOnError(object);
}
else
{*/
// mark all children as valid
markFormComponentsValid();
// before updating, call the interception method for clients
beforeUpdateFormComponentModels();
// Update model using form data
updateFormComponentModels();
// validate model objects after input values have been bound
onValidateModelObjects();
if (hasError())
{
callOnError(object);
return;
}
// Form has no error
delegateSubmit(object);
//}
}
and I ovveride one method
#Override
protected void onError(){
super.onError();
this.updateFormComponentModels();
}
I know it is ugly solution but I couldn't figure out anything better..
And I couldn't shutdown feedback messages

mgwt attach CellSelectedHandler to GroupingCellList inside HeaderList

I'm having trouble attaching an SelectionHandler to the contents of the mgwt HeaderList.
How can I attach a CellSelectedHandler to a HeaderList just like in the Showcase?
http://mobilegwt.appspot.com/showcase/#GroupedCellListPlace:
I already tryed to attach the Handler to the GrouingCellList with wich the HeaderList is built, but this Handler is never fired.
Anyone done this already?
I managed to get the SelectEvents using the SelectionHandler instead of the CellSelectedHandler on the GroupingCellList
addHandlerRegistration(view.getList().addSelectionHandler(new SelectionHandler<Content>(){
#Override
public void onSelection(SelectionEvent<Content> event) {
Window.alert("event"+event.getSelectedItem().getName());
}
}));

GWT - Code Splitting - How can GWT know which data load first time?

Im curios about this. I have for example this code :
button_article.addClickListener(new ClickListener(){
public void onClick(Widget w) {
GWT.runAsync(new RunAsyncCallback() {
public void onFailure(Throwable reason) {
// somethings
}
public void onSuccess() {
content.clear();
content.designArticles();
}
});
}
});
public final void designArticles() {
this.add(new ProfileArticles(this.rpcService, this));
}
I see that until i click on button_article, the elements on ProfileArticles() (that is a FlowPanel) arent loaded when i start the application. So, how can GWT know that element on that class shouldnt loaded when the application start? It check each methods under GWT.runAsync() and their correspondents Class?
I also see that when i leave that "context" they arent released (in fact, if i change context and i return there, when i click again on that method it doesnt call the server. So it use the previous loaded code). Is it right? :)
Cheers
The GWT compiler analyzes the flow of your program to figure out what chunks it can load later. If you want to visually understand what it's done, check out http://code.google.com/webtoolkit/doc/latest/DevGuideCompileReport.html .
Once code is loaded, most of it can be cached, so even if the user navigates off the page and then back to yours, the code will not need to be reloaded.

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