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?
Related
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?
I have the following code snippet -
Button testButton = new Button("Test");
testButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
final DialogBox box = new DialogBox();
box.setText("Test");
box.add(new DateField());
box.setGlassEnabled(true);
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
#Override
public void execute() {
box.show();
}
});
}
});
RootPanel.get().add(testButton);
RootPanel.get().add(new DateField());
The GXT DateField inside the modal DialogBox doesn't seem to work and none of the dates are selectable. On the other hand, the one added directly to RootPanel seems to works fine.
Any ideas on how to work around this?
When using the GWT dialog and the date picker expand, the GWT dialog is preventing the click events from propagating to it. So in this case the GWT dialog modal can be set to false to get it to work. Although I would suggest using the GXT DialogBox. Another option might be to override the event handling a bit more in DialogBox in the case the GXT Date picker is displayed.
This will allow the field to work in GWT:
final DialogBox box = new DialogBox(false, false);
Small test case to show both:
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.RootPanel;
import com.sencha.gxt.widget.core.client.Dialog;
import com.sencha.gxt.widget.core.client.form.DateField;
public class DialogWithDateField {
public DialogWithDateField() {
RootPanel.get().add(new DateField());
testGwtDialog();
testGxtDialog();
}
private void testGwtDialog() {
Button testButton = new Button("Test Gwt Dialog");
testButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
final DateField field = new DateField();
final DialogBox box = new DialogBox(false, false);
box.setText("Test");
box.add(field);
box.setGlassEnabled(true);
box.show();
}
});
RootPanel.get().add(testButton);
}
private void testGxtDialog() {
Button testButton = new Button("Test Gxt Dialog");
testButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
DateField field = new DateField();
final Dialog box = new Dialog();
box.setHeadingText("Test");
box.add(field);
box.setModal(true);
box.show();
}
});
RootPanel.get().add(testButton);
}
}
The issue might be due to mixing GWT Dialog with GXT widget.
Try this sample code that works with Sencha Dialog
Dialog d = new Dialog();
d.setHeadingText("Enter Date");
d.setWidget(new DateField());
d.setPixelSize(300, 100);
d.setHideOnButtonClick(true);
d.setPredefinedButtons(PredefinedButton.YES, PredefinedButton.NO,
PredefinedButton.CANCEL);
d.show();
Works fine with EXTJS Dialog as well.
Dialog d = new Dialog();
d.setTitle("Enter Date");
d.add(new DateField());
d.setPixelSize(300, 100);
d.setHideOnButtonClick(true);
d.setButtons(Dialog.YESNOCANCEL);
d.show();
How to create a click event search button in Eclipse?? Can someone help me. This is the code im working with.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
listContent1 = (ListView)findViewById(R.id.lFoodlist1);
mySQLiteAdapter = new SQLiteAdapter(this);
mySQLiteAdapter.openToRead();
Cursor cursor = mySQLiteAdapter.queueAll();
startManagingCursor(cursor);
String[] from = new String[]{SQLiteAdapter.KEY_FOODNAME,SQLiteAdapter.KEY_CALORIES};
int[] to = new int[]{R.id.tv1, R.id.tv2};
SimpleCursorAdapter cursorAdapter =
new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);
listContent1.setAdapter(cursorAdapter);
//listContent.setOnItemClickListener(listContentOnItemClickListener);*/
}
This code was taken from Here and was modified/commented to help the poseter with his scenario.
You can implement swing to help with the GUI aspect of your application. Others may prefer AWT
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class myTest {
public static void main(String[] args) {
//This will create the JFrame/JPanel/JButton
final JFrame frame = new JFrame();
JPanel panel = new JPanel();
JButton button1 = new JButton();
//Add your panel and button and make them visable
frame.add(panel);
panel.add(button1);
frame.setVisible(true);
//This adds the actionListener to the Button
button1.addActionListener(new ActionListener() {
//When the button is clicked this action will be performed
public void actionPerformed(ActionEvent arg0) {
//Add your code here.
}
});
}
}
I have a CellTable showing data that is plotted in a GFlot SimplePlot.
An export of the plot is possible with GFlots integrated function:
exportImage = plot.getImage();
Now I would like to export the CellTable too, to show the corresponding data to the plot.
Is this possible in some way with GWT on the client-side? It needn't to be the CellTable itself, just the data it shows would suffice.
I think You can use flash4j library:
package com.emitrom.flash4j.demo.client;
import com.emitrom.flash4j.clientio.client.ClientIO;
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.RootPanel;
public class ClientIOExample implements EntryPoint {
#Override
public void onModuleLoad() {
// initialize the ClientIO module
ClientIO.init();
Button b = new Button("Click Me");
b.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
// create a PDF File
PDF pdf = new PDF();
pdf.addPage();
pdf.setTextStyle(new RGBColor(0x000000));
pdf.setFont(new CoreFont(), 10);
pdf.addText("");
ClientIO.saveFile(pdf.save(), "file.pdf");
}
});
RootPanel.get().add(b);
}
}
You can see more detailed information a link
How to implement something kinda internal frame in JavaFx 2.0 specifically?
My attempt is as so..
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main extends Application {
ConnectDb connection;
public static void main(String[] args) {
Application.launch(args);
}
#Override
public void start(Stage stage) throws Exception {
final Stage stage1 = new Stage();
StackPane pane = new StackPane();
Button btn = new Button("Click Me");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
connection = new ConnectDb();
try {
connection.start(stage1);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Fire some thing..");
}
});
pane.getChildren().add(btn);
stage.setScene(new Scene(pane ,200, 300));
stage.show();
}
}
ConnectDb.java
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class ConnectDb extends Application {
#Override
public void start(Stage stage) throws Exception {
StackPane pane = new StackPane();
Button btn = new Button("Click On Button which is me");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("Something here..");
}
});
pane.getChildren().add(btn);
stage.setScene(new Scene(pane ,200, 300));
stage.show();
}
}
First of all, for your approach, you don't really need to (and therefore should not) extend ConnectDb from Application as you just use the start method to create new stages. You just need one Application class (in your case Main). You could just as well create the new stage/scene in your first event handler.
Secondly, there is no real MDI support in JavaFX 2.1. Right now, you can just have multiple Stages (which is the equivalent to having multiple windows/frames). But you cannot have something like an internal frame in a desktop pane.
I guess you could take the following actions:
Just use multiple Stages (windows) with the drawback that they will float quite uninspiredly on your desktop
Use Swing as a container (with JDesktopPane and JInternalFrame) and integrate JavaFX (here's a nice How-To)
Implement your own framework that emulates MDI behavior
Find a framework that provides MDI behavior
Wait for a future release of JavaFX that hopefully provides MDI support (as far as I know, there's a change request pending...)
Create parent AncorPane.
Add several children AnchorPanes to it. They will serve as internal frames. Add different content to these.
Set children AnchorPanes invisible.
Add buttons to hide, resize or close children AnchorPanes. When needed, call function to set all children AnchorPanes invisible, except for one.