I'm using GWT 2.6.0 and I'm following the StockWatcher tutorial.
Simplified, this is my code:
private Button sendButton = new Button("send");
private VerticalPanel mainPanel = new VerticalPanel();
public void onModuleLoad(){
// this works
mainPanel.add(sendButton);
RootPanel.get("stockList").add(mainPanel);
// until I add a Click Handler:
sendButton.addClickHandler(event -> addStock());
}
private void addStock(){
//TODO: implement
}
The button is not rendered. However, if I remove the click handler, the button becomes visible.
I'm completely new to GWT and I'm wondering what I'm doing wrong here?
I'm using ant devmode to run in development mode and I'm using Firefox 26.0.
I not sure, that gwt 2.6 supports java8 and lambdas.
To be convinced of this, try to compile you project to javascript.
Java 7 is supported and is now the default. (This can be overridden
using
-sourceLevel 6)
http://www.gwtproject.org/release-notes.html#Release_Notes_2_6_0
It looks like that lamdas a java8 feature are not supported yet by GWT:
sendButton.addClickHandler(event -> addStock());
Here's how to add a click handler
Button b = new Button("Click Me");
b.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// handle the click event
}
});
Related
We are using 1.4.9 for our current webapp. But we want to upgrade to higher 1.4.x version preferably 1.4.22(latest 1.4). The problem is that the page won't submit if AjaxButton is clicked. This is working in 1.4.9. I put breakpoint on the onSubmit of that button but it is not going there. Any insights on this? Thanks!
Here is the code:
For the button:
public abstract class SXIButton extends AjaxButton {
public SXIButton(String id, Form form) {
super(id, form);
initialize();
add(new SimpleAttributeModifier("validating", "false"));
}
}
In the java:
searchForm.add(new SXIButton("searchButton", searchForm) {
private static final long serialVersionUID = -4366670520053224476L;
#Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
LOG.info("Searching Users");
target.addComponent(userContainer);
userSearchModel.setUserCurrentUserFilter(getSessionBOUser().getCd());
UserDataProvider udp = new UserDataProvider(userSearchModel,isForSearch);
udp.setSort("cd", true);
userContainer.addOrReplace(getResultPanel(udp));
}
});
add(portlet);
portlet.add(searchForm);
in html
<input type = "submit" wicket:id = "searchButton" wicket:message="value:button.search" />
Without any code it's hard to help you out. I would first check the changelog to see if anything was changed in a later version that might causes you trouble (e.g. this ticket). If you cannot find anything obvious you might want to update first to another version which is not the latest one, to narrow down in which version your code breaks for the first time.
But those are just shots in the dark.
I'm trying to do the following:
I want to add a specific handler for some links, denoted by a class.
$("a.link_list").live("click", new ListLinkHandler());
I need .live() instead of .bind() because new such links will be generated. (I know jQuery's .live() is deprecated in favor of .on(), but gwt-query doesn't have a .on() yet.)
I defined the handler like this (just as the gwtquery example does):
public class ListLinkHandler extends Function {
#Override
public boolean f(Event e) { [...] }
}
However, the handler method is never called when I click the links.
I can see the event listener in Chrome Dev Tools: http://screencloud.net/v/bV5V. I think it's on the body because it's a .live().
I tried using .bind() and it worked fine. The body event listener changed in a a.link_list and the handler does what it's supposed to do, but (as documented, I didn't test) not for newly created links.
I filed a bug for the .live() method, but maybe I'm doing something wrong.
Also, I have no idea how to do it without gwtquery, GWT doesn't seem to have a method for selecting elements by class, neither to continually add the listener to new elements.
It seems you are doing something wrong, but I need more code to be sure. Could you send the complete onModuleLoad code which demonstrates this wrong behavior?
I have written a quick example using live, and it works either when adding new gwt widgets or dom elements with gquery, in both Chrome and FF
public void onModuleLoad() {
$("a.link_list").live("click", new ListLinkHandler());
// Add a new link via gquery
$("<a class='link_list' href=javascript:alert('href') onClick=alert('onClick')>Click </a>").appendTo(document);
// Add a new link via gwt widgets
Anchor a = new Anchor("click");
a.setStyleName("link_list");
a.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
Window.alert("clickHandler");
}
});
RootPanel.get().add(a);
}
public class ListLinkHandler extends Function {
#Override
public boolean f(Event e) {
Window.alert("live");
return true;
}
}
Here is my Entry point class
public class TestUI implements EntryPoint
{
Panel1 panel1 = new Panel1();
public void onModuleLoad()
{
final RootPanel rootPanel = RootPanel.get();
Button btnButtonOnRoot = new Button("Go to next view");
btnButtonOnRoot.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
rootPanel.clear();
rootPanel.add( panel1 );
}
});
rootPanel.add(btnButtonOnRoot, 72, 40);
}
}
Works ok but I want to use something other than a Panel as the view to load when I click the button.
In Eclipse when I click on my client package I get the option to add a Panel, A Composite among other things. Problem is when I go to edit these with my UI designer I can only put a single widget on each one. What I would like to do is have the ability to clear the rootpanel and add an EntryPoint type class to it as I can edit EntryPoint classes with my UI designer. What other type of Classes can I add to a panel that would be editable in a UI designer?
Dont use that WYSIWYG-editors. They are nice to get you started, but building UIs in GWT really is no magic. You have a panel A and add components aa, ab and ac. Then you have another panel and so on.
And one more advice: Try not to use the rootpanel. It behaves a little different than other panels as it actually is no panel. Try to add a ContentPanel to the RootPanel and add elements to that ContentPanel. The ContentPanel then is added to the RootPanel.
I'm using GEF. I have a graphical editor with some "boxes" implemented. Now, I want to add a double-click listener to each box (Rectangle).
I tried to add a listener to the GraphicalViewer but it did not work.
In the GraphicalEditPart of the "box" for which you want to add the listener, you have to override the performRequest(Request req) method. When the framework identifies a double-click on the part's figure, it calls this method with a request that has req.getType()==RequestConstants.REQ_OPEN. You can take over from here.
Complete code to test that his works:
#Override
public void performRequest(Request req) {
if(req.getType() == RequestConstants.REQ_OPEN) {
System.out.println("requested double-click.");
}
}
Hope this does the trick.
I am not familiar with GEF myself, however I found this in documentation:
GraphicalEditor abstraction sets the EditDomain - handler for editing events
EditDomain interface with methods for handling events - e.g. double click
Tutorial on how to implement editing of models through GUI in GEF (using EditDomain)
viewer.getControl().addListener(SWT.MouseDoubleClick, new Listener() {
#Override
public void handleEvent(Event event) {
//write the double click action
});
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