vaadin UI call from callback - java

i am trying to build a 2-step process using vaadin. I created a view that holds my 2 main components (extends Div) which are displayed alternately.
to change from one of the main components to the other i have a ComboBox that i use for searching and therefore implemented a CallbackDataProvider, like seen below.
ComboBox<ResponsePartSearchResult> cmbPartSearch = new ComboBox<>();
CallbackDataProvider<ResponsePartSearchResult, String> provider = new CallbackDataProvider<ResponsePartSearchResult, String>(
query -> {
// fetch callback
}, query -> {
// retrieve count
});
The user is supposed to search for parts, get a list, and should be able to click on one of the results. this result is then displayed in the ComboBox. In another text field he has to add more info and click on a Button, in order to proceed. The Button's ClickListener retrieves the value from the ComboBox and the second TextField and sends it to a private method:
ResponsePartSearchResult value = cmbPartSearch.getValue();
value.q = txtPartSerial.getValue();
proceedToStepTwo(value)
BUT! If the user pastes a valid ID, the result coming back from the backend contains a certain flag, showing that this part was retrieved by its ID and with all required additional info. In this case the user is supposed to be directly "redirected" to the second main component, whithout the need to click the Button.
In this case I call the method proceedToStepTwo within the "fetch callback".
For the first case everything is running smoothly so far. For the second case, however, the 2nd main component and all it's UI elements are shown, but in order to click on something, whether it is a button or a checkbox, i need a double click.
It's a very strange behaviour without any error message. When I click on a Button (I added a sysout to a ClickListener) on that 2nd main component my RequestLoggingFilter shows a few of the following lines:
After request [uri=/?v-r=uidl&v-uiId=0;client=0:0:0:0:0:0:0:1;session= ...]
but not the content of the sysout. It only shows the content (and a few of the Logging lines above) when i doubleclick.
This shows that the Button reacts, but not entirely.
When I just let the fetch callback fill the ComboBox and TextFields and click the Button manually, it works again. But I want to get rid of the separate manual step.
I assume when I'm inside of that callback method, I need to call proceedToStepTwo differently, but how? Any ideas or experiences? Any help would be appreciated.
Thanks!
EDIT
When i debug and set a breakpoint into the method proceedToStepTwo() the UI will behave expectedly. However when i remove the breakpoint again and put a Thread.sleep(1000) in there, nothing changes and i cannot properly click the UI elements.

Related

how to synchronize 2 tabs JTabbedPane Swing

I work with swing to build GUI. Hello everyone
I have 2 tabs (JTabbedPane) that I want to synchronize.
For example, on the image below, I would like that if I click on the Rent button, the line can be automatically added to the My leasing tab so that if I go to the My Leasing tab, I find the line that has just been added.
Currently, to see the line that has just been added to the My leasing tab, I must log out and log back in.
I tell myself that there may be a listener to put in place but I do not know which one.
You need to respond to the click of the "Rent" button.
Check out the Table Button Column. This class allows you to add an ActionListener which is invoked whenever the button is clicked (or activated by using the space bar).
The example code shows how to delete a row from the model. In your case you would want to copy the data from one model to the other.

How to solve the delay in loading the radio button selection in the application?

In my application, i have a radio button field selected. When i am opening the page, the selected field has some delay. Example: I am opening the page, that radio button is in unselected state, after some time (say like hovering on the screen/scrolling) the radio button turns to selected state. Is there is any other way to solve this delay?
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
#Override
public void execute() {
statementGroupSelectionModel.setSelected(item, profile.getSelected());
}
});
Here in the above code, "item" is widget field name and depending upon my "getselected" value, the radio icon will get selected. Here my "getSelected" value is true.
Any code inside scheduleDeferred will have its execution postponed until the browser finishes rendering the page and the flow control returns to the Javascript event loop, as explained in GWT's documentation:
Deferring some logic into the immediate future: the Scheduler class
Sometimes you want to break up your logic loop so that the JavaScript event loop gets a chance to run between two pieces of code. The Scheduler class will allow you to do that. The logic that you pass to Scheduler will run at some point in the future, after control has been returned to the JavaScript event loop. This little delay may give the interface a chance to process some user events or initialize other code. To use the Scheduler class in its simplest form, you create a subclass of the Command class, overriding the execute() method and pass it to Scheduler.scheduleDeferred
If what you want is for the radio button to be selected immediately, just remove the Scheduler wrapping, i.e. move statementGroupSelectionModel.setSelected(item, profile.getSelected()); out of scheduleDeferred.
// Put this here
statementGroupSelectionModel.setSelected(item, profile.getSelected());
// Remove the following code
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
...
});
If what you want is not that (sorry, your explanation is rather unclear), but just to be able to set the delay time yourself instead of having to wait for the browser, you can use the Timer class which is explained in the documentation linked above.

Callbacks in GWT - save data to the list after click submit button

I have a interesting problem with callbacks in GWT. My application have a form, where I have few fields, OK button which add something to the list and a main send button.
When I fill all fields, click OK button first and click send button, on the next page, I see the results - everything I wrote to the form is correctly displaying on the confirm site.
But, I have a problem with fields which add something to the list - I have fields, where I put the name and surname, click the button OK next to this field which add this data to the list. It works good, I can add as many data I want. This button has his own onClick() method, which do something - this is not important here what. As I said, when I click OK button, data is added to the list.
But, I have also my main send button. I want to add data to the list with this button, but without clicking on the button OK.
Example:
I have put some data to the fields name and surname, I haven't click button OK and I click send button. The problem is, data was not add to the list and on my confirm page I cannot see the correct result. Of course, under the send button I called click() method from the OK button.
Maybe I don't know well how callbacks work, but this is very difficult thing for me to solve this problem.
If I manually click on the OK button, everything is good. When I do this same thing by programming side, it does not work. I debugged it for a long time, but in any cases everything run identically. Differents are in the final result.
My question is - how to add data to the list only by clicking send button?
EDIT - some pseudo code how it looks right now:
View class has method (form is a place where I have name and surname fields with button OK:
public void add(){
form.addButton().click();
}
Presenter for this view, where I have sendButton:
sendButton.addHandler(new ClickHandler(){
#Override
public void onClick(ClickEvent event) {
view.add();
}
}

How to control print and cancel buttons on browser's print page?

I work on a Java web application on Eclipse.It has a screen, which some invoices are listed in a table.I can approve, edit,send via email,print or cancel the invoices via selecting them from the table.
When I click on print button, a MessageDialog gets opened and asks whether the user is sure to print the invoice, and I say yes.Then the browser's print page gets opened:
I want to be able to control the "Print" and "Cancel" buttons on these page.If I click on "Print", the status of invoice is going to be "PRINTED".If I click on "CANCEL" the status of invoice is not going to change, it should remain same.
When I execute the following method on the class,it opens browser's print page.
private void printPressed() {
browserContent.execute("printMe();");
}
And I am stuck at these stage.I want to modify this method for the purpose of controlling "Print" and "Cancel" buttons.How can I change it?
You can't as this will be security hole (Imagine that you make loop to print 1000000 pages of stg nasty). Every user must decide on his own.

GWT. How to handle two similar actions with one event?

I've encountered next problem. I've got list of products and each product has button to open its QuickLook PopUp. I've created special event for this button, registered it in EventBus and trigger them. Everything seems good, but when I click one button, popup is shown not just for this item, but for all items, that are in list (I mean numbers of that "show"). This happens cause I have one Event-class for all these buttons, but can I somehow separate them one from another?
I just want to set some ID or something like that to every button and check this condition while triggering or (this would be even better) trigger only event, that I really need.
You don't need an EventBus for this. You can create a simple ClickHandler and attach it to your buttons. When you create a ClickHandler, you pass a product ID (or whatever you use to differentiate your products) to a method that shows your popup.
You can add productId to your Custom Event as a property. Event handler will check it and show only required product info.

Categories

Resources