GWT Bootstrap Modal buttons won't work with ClickHandler's onClick - gwt

I'm trying to create a dialog box using GWT-Bootstrap modal widget.
I can get it to display but have not been able to get the buttons to recognize events.
The cancel button onClick never fires.
Had some other code to try to get the addClass button to do do something but stripped it out. If I can get the cancel button to do something (anything!) I should be in good shape.
I've also tried the java using addDomHandler and that didn't work either.
Here's the XML:
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:a="urn:import:cgs.common.client.gwt.bootstrap"
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<b:Modal title="Add Class?" ui:field="addClassModal" backdrop="STATIC" keyboard="true" animation="true">
<a:BootstrapField label="Classname:">
<a:BootstrapTextInput
ui:field="classname"
placeholder="Classname" />
</a:BootstrapField>
<b:Button ui:field="addClass">Add Class</b:Button>
<b:Button ui:field="cancel">Cancel</b:Button>
</b:Modal>
</ui:UiBinder>
And here's the java:
package cgs.teacher.portal.client.view.impl.bootstrap;
import cgs.common.client.gwt.bootstrap.BootstrapTextInput;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Modal;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
public class AddClassDialogViewImpl
extends Composite
{
interface AddClassDialogViewImplUiBinder extends UiBinder<Widget, AddClassDialogViewImpl>
{
}
private static AddClassDialogViewImplUiBinder uiBinder = GWT
.create(AddClassDialogViewImplUiBinder.class);
#UiField
Modal addClassModal;
#UiField
BootstrapTextInput classname;
#UiField
Button addClass;
#UiField
Button cancel;
public AddClassDialogViewImpl()
{
initWidget(uiBinder.createAndBindUi(this));
cancel.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
addClassModal.hide();
}
});
addClassModal.toggle(); //PS. Show gave error. Had to use toggle to show!
}
}
Thanks!

Another workaround which I have found is adding the Modal component to the RootPanel :
public AddClassDialogViewImpl() {
initWidget(uiBinder.createAndBindUi(this));
cancel.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
//hide the widget
addClassModal.hide();
// unless you want to keep this modal as a singleton, you need to remove it from the DOM
RootPanel.get().remove(AddClassDialogViewImpl.this);
}
});
//add the widget to the DOM
RootPanel.get().add(this);
// show the widget
addClassModal.show();
}

Related

Custom Button in MessageDialog

I want to add my custom button with AjaxEventBehavior to MessageDialog , i can add simple custom button without AjaxEventBehavior by extending DialogButton class, but this will be useless button with out listener, anyone no how to do it?
here is my code:
import com.googlecode.wicket.jquery.ui.widget.dialog.MessageDialog;
import org.apache.wicket.ajax.AjaxRequestTarget;
import
org.apache.wicket.core.request.handler.IPartialPageRequestHandler;
import org.apache.wicket.model.Model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
public class TipOfTheDayDialog extends MessageDialog {
private static final Logger log =
LoggerFactory.getLogger(TipOfTheDayDialog.class);
Model<String> model = null;
List<DialogButton> dialogButtons =null;
public TipOfTheDayDialog(String id, Model<String> model,List<DialogButton> dialogButtons) {
super(id, Model.of("Совет дня"), model, dialogButtons);
this.model = model;
}
#Override
public void onClose(IPartialPageRequestHandler handler, DialogButton button) {}
#Override
public void onClick(AjaxRequestTarget target, DialogButton button)
{
if(!button.getName().equals("next")){
super.close(target,button);
this.close(target, button);
}else {
model.setObject("another message");
target.add(this);
}
}
}
I have decided to override method onclick instead of adding button with its own listener, but now i have another problem, i can't change message of dialog without it's closing , when i change message by this line of the code: model.setObject("another message"); and then add it to the target by this code : target.add(this); dialog window closes, how to fix it?

How to make gmail search box similar ui in gwt

We are making an application using GWT that require a search box widget like gmail has.
I dont know how and where to start to make such widget.
Basically what widget/component should i use to make a text box with a dropdown icon,where if i click the dropdown icon it opens a panel with advanced search using gwt.Please help
with UiBinder tool, you can design fastly what you wish :
`
<g:HTMLPanel>
<g:VerticalPanel>
<g:HorizontalPanel>
<g:TextBox/>
<g:PushButton text="V" ui:field="pushButton"/>
<g:PushButton text="Search"/>
</g:HorizontalPanel>
<g:VerticalPanel ui:field="optionsPanel">
<g:HorizontalPanel>
<g:Label text="Foo"/>
<g:TextBox/>
</g:HorizontalPanel>
<g:HorizontalPanel>
<g:Label text="Bar"/>
<g:TextBox/>
</g:HorizontalPanel>
</g:VerticalPanel>
</g:VerticalPanel>
</g:HTMLPanel>
`
and
`
package yde.dev.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.event.dom.client.ClickEvent;
public class SearchLikeGmail extends Composite {
private static SearchLikeGmailUiBinder uiBinder = GWT
.create(SearchLikeGmailUiBinder.class);
#UiField VerticalPanel optionsPanel;
#UiField PushButton moreOptionsBttn;
interface SearchLikeGmailUiBinder extends UiBinder<Widget, SearchLikeGmail> {
}
public SearchLikeGmail() {
initWidget(uiBinder.createAndBindUi(this));
optionsPanel.setVisible( false );
}
#UiHandler("moreOptionsBttn")
void onMoreOptionsBttnClick(ClickEvent event) {
optionsPanel.setVisible( true );
}
}
`

Styleclass not being applied when the previous style class is added in FXML

I assign styleclass of ToggleButton in FXML file as follows:
<ToggleButton fx:id="Button" styleClass="defaultStyle">
Later, in my code I change the style classes as follows:
#FXML private ToggleButton Button;
Button.getStyleClass().remove("defaultStyle");
Button.getStyleClass().add("newStyle");
The CSS file is defined as:
.defaultStyle { -fx-background-color: black;}
.newStyle { -fx-background-color: red;}
EDITED:
The new style is applied when done in the Controller, but the new style is not being applied when done somewhere else. When I debug, I see the correct style-class being added & removed to the button.
Anyone got a workaround for this problem? I appreciate your help in advance.
Style class removing and adding are working as expected. I guess your problem is the ToggleButton has not been injected correctly, it should be:
#FXML private ToggleButton Button;
...
Button.getStyleClass().remove("defaultStyle");
Button.getStyleClass().add("newStyle");
in the controller class. Note the capital b of "Button" since you have defined fx:id="Button" in FXML file. Also note that you don't need to instantiate the ToggleButton Button (like new ToggleButton()) yourself.
EDIT:
Here is code example for changing the styleclass. As I said it is working as expected. Compare it with yours.
Sample.fxml:
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml" fx:controller="somepackage.SampleController">
<stylesheets>
<String fx:value="somepackage/style.css" />
</stylesheets>
<children>
<ToggleButton layoutX="126" layoutY="90" text="Click Me!" onAction="#handleButtonAction" fx:id="mybutton" styleClass="defaultStyle" />
</children>
</AnchorPane>
SampleController.java:
package somepackage;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ToggleButton;
public class SampleController implements Initializable {
#FXML
private ToggleButton mybutton;
#FXML
private void handleButtonAction(ActionEvent event) {
System.out.println("before :" + mybutton.getStyleClass());
mybutton.getStyleClass().remove("defaultStyle");
mybutton.getStyleClass().add("newStyle");
System.out.println("after :" + mybutton.getStyleClass());
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
MainDemo.java:
package somepackage;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MainDemo extends Application {
#Override
public void start(Stage stage) throws Exception {
System.out.println("version: " + com.sun.javafx.runtime.VersionInfo.getRuntimeVersion());
Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
The css file includes selectors of yours.
Since you said it is only done when the controller does it.
Use the FXMLLoader to load your controller. then you change the StyleClass to the newStyle.

GWT/JAVA - Getting an AJAX call into a dialog box

I'm new to GWT, and having an issue getting the result of an AJAX call to show up in my Dialog box.
I set up my dialog box, Vpanel, and response label here:
VerticalPanel eventDetailWindow = new VerticalPanel();
final DialogBox dialogBox2 = new DialogBox();
dialogBox2.setText("Event Detail");
dialogBox2.setAnimationEnabled(true);
final HTML serverResponse3 = new HTML("<b> ok, this is working</b>");
serverResponse3.addStyleName("detailView");
eventDetailWindow.add(serverResponse3);
eventDetailWindow.addStyleName("detailWindow");
dialogBox2.setWidget(eventDetailWindow);
RootPanel.get("detailWindow").add(eventDetailWindow);
Then, in the onSuccess method I have this:
dialogBox2.setText("Remote Procedure Call");
serverResponse3.setHTML(result);
dialogBox2.center();
closeButton.setFocus(true);
However, when it fires, the response shows up on the page, not in the dialog box and the dialog box is empty. It looks like it's set up the same as the starter project - which works fine..
Can someone help me out...?
Dont use that RootPanel.get("detailWindow").add(eventDetailWindow);
if you want to only add into dialogBox2
use like that:
dialogBox2.setWidget(eventDetailWindow);
and You dont have to add dialogBox2.show(); because dialogBox2.center(); that code will show the dialogBox2 initially.
package com.ex.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
public class Example implements EntryPoint {
public void onModuleLoad() {
VerticalPanel eventDetailWindow = new VerticalPanel();
final DialogBox dialogBox2 = new DialogBox();
dialogBox2.setText("Event Detail");
dialogBox2.setAnimationEnabled(true);
final HTML serverResponse3 = new HTML("<b> ok, this is working</b>");
serverResponse3.addStyleName("detailView");
eventDetailWindow.add(serverResponse3);
eventDetailWindow.addStyleName("detailWindow");
dialogBox2.setWidget(eventDetailWindow);
Button b= new Button("click");
b.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
dialogBox2.setText("Remote Procedure Call");
serverResponse3.setHTML("result");
dialogBox2.center();
}
});
RootPanel.get().add(b);
}
}
You are adding the eventDetailWindow to something on the page and I don't see a call to .show() on the DialogBox. Can you post your full code?

GWT Button EventListener not fired

I have a <div id="test"><input type="button" value="OK" /></div> html tag.
I used:
((HasClickHandlers)RootPanel.get("test").getWidget(0)).addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
Window.alert('sss');
}
}
I executed but no action.
Update:
package com.example.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.*;
import com.google.gwt.user.client.*;
import com.google.gwt.user.client.ui.RootPanel;
public class ExampleWebApp implements EntryPoint {
public void onModuleLoad() {
((HasClickHandlers) RootPanel.get("test").getWidget(0)).addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
Window.alert("i got it");
}
});
}
}
HTML:
<table>
<tr>
<div id="test">
<input type=button onClick="" value='click here'>
</div>
</tr>
</table>
The GWT Button widget is a button tag and not a input tag. Which means you can't use the GWT Button widget in this case. To make it work you need to create your own widget, which can be based on the widget ButtonBase, but needs to be initialized with an InputElement object instead of a ButtonElement.
The next step to get tag from html is to add something similar to the static wrap method present in most widgets. Here is how it would be used in your example when the input would have been a button tag:
Button.wrap(RootPanel.get("test").getWidget(0).getElement()).addClickHandler(
new ClickHandler() {
#Override public void onClick(ClickEvent event) {
Window.alert('sss');
}
});
In you case you could add a wrap method to your custom input widget. See the Button widget implementation of te wrap method, it's the same, expect of course for the creation of the widget itself.
You can't just take an html button and try to add click handlers to it. You need to create the button using gwt code. Try:
<div id="test"></div>
And then:
Button button = new Button("OK");
RootPanel.get("test").add(button);
button.addClickHandler(new ClickHandler() {...});