Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    trouble with XMLTools

    smartgwt from svn, FF browser

    I've isolated this problem and inserted the relevant lines into the GWT sample program:

    Code:
    package com.introspect.test.client;
    
    import java.util.HashMap;
    
    import com.introspect.test.shared.FieldVerifier;
    import com.smartgwt.client.data.XMLTools;
    import com.smartgwt.client.util.StringUtil;
    import com.google.gwt.core.client.EntryPoint;
    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.event.dom.client.KeyCodes;
    import com.google.gwt.event.dom.client.KeyUpEvent;
    import com.google.gwt.event.dom.client.KeyUpHandler;
    import com.google.gwt.user.client.rpc.AsyncCallback;
    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.Label;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.google.gwt.user.client.ui.TextBox;
    import com.google.gwt.user.client.ui.VerticalPanel;
    import com.google.gwt.xml.client.Document;
    import com.google.gwt.xml.client.Element;
    import com.google.gwt.xml.client.Node;
    import com.google.gwt.xml.client.XMLParser;
    
    /**
     * Entry point classes define <code>onModuleLoad()</code>.
     */
    public class Test1 implements EntryPoint {
    	/**
    	 * The message displayed to the user when the server cannot be reached or
    	 * returns an error.
    	 */
    	private static final String SERVER_ERROR = "An error occurred while "
    			+ "attempting to contact the server. Please check your network "
    			+ "connection and try again.";
    
    	/**
    	 * Create a remote service proxy to talk to the server-side Greeting service.
    	 */
    	private final GreetingServiceAsync greetingService = GWT
    			.create(GreetingService.class);
    
    	/**
    	 * This is the entry point method.
    	 */
    	public void onModuleLoad() {
    		final Button sendButton = new Button("Send");
    		final TextBox nameField = new TextBox();
    		nameField.setText("GWT User");
    		final Label errorLabel = new Label();
    
    		// We can add style names to widgets
    		sendButton.addStyleName("sendButton");
    
    		// Add the nameField and sendButton to the RootPanel
    		// Use RootPanel.get() to get the entire body element
    		RootPanel.get("nameFieldContainer").add(nameField);
    		RootPanel.get("sendButtonContainer").add(sendButton);
    		RootPanel.get("errorLabelContainer").add(errorLabel);
    
    		// Focus the cursor on the name field when the app loads
    		nameField.setFocus(true);
    		nameField.selectAll();
    
    		// Create the popup dialog box
    		final DialogBox dialogBox = new DialogBox();
    		dialogBox.setText("Remote Procedure Call");
    		dialogBox.setAnimationEnabled(true);
    		final Button closeButton = new Button("Close");
    		// We can set the id of a widget by accessing its Element
    		closeButton.getElement().setId("closeButton");
    		final Label textToServerLabel = new Label();
    		final HTML serverResponseLabel = new HTML();
    		VerticalPanel dialogVPanel = new VerticalPanel();
    		dialogVPanel.addStyleName("dialogVPanel");
    		dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
    		dialogVPanel.add(textToServerLabel);
    		dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
    		dialogVPanel.add(serverResponseLabel);
    		dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
    		dialogVPanel.add(closeButton);
    		dialogBox.setWidget(dialogVPanel);
    
    		// Add a handler to close the DialogBox
    		closeButton.addClickHandler(new ClickHandler() {
    			public void onClick(ClickEvent event) {
    				dialogBox.hide();
    				sendButton.setEnabled(true);
    				sendButton.setFocus(true);
    			}
    		});
    
    		// Create a handler for the sendButton and nameField
    		class MyHandler implements ClickHandler, KeyUpHandler {
    			/**
    			 * Fired when the user clicks on the sendButton.
    			 */
    			public void onClick(ClickEvent event) {
    				sendNameToServer();
    			}
    
    			/**
    			 * Fired when the user types in the nameField.
    			 */
    			public void onKeyUp(KeyUpEvent event) {
    				if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
    					sendNameToServer();
    				}
    			}
    
    			/**
    			 * Send the name from the nameField to the server and wait for a response.
    			 */
    			private void sendNameToServer() {
    				// First, we validate the input.
    				errorLabel.setText("");
    				String textToServer = nameField.getText();
    				if (!FieldVerifier.isValidName(textToServer)) {
    					errorLabel.setText("Please enter at least four characters");
    					return;
    				}
    
    				// Then, we send the input to the server.
    				sendButton.setEnabled(false);
    				textToServerLabel.setText(textToServer);
    				serverResponseLabel.setText("");
    				greetingService.greetServer(textToServer,
    						new AsyncCallback<String>() {
    							public void onFailure(Throwable caught) {
    								// Show the RPC error message to the user
    								dialogBox
    										.setText("Remote Procedure Call - Failure");
    								serverResponseLabel
    										.addStyleName("serverResponseLabelError");
    								serverResponseLabel.setHTML(SERVER_ERROR);
    								dialogBox.center();
    								closeButton.setFocus(true);
    							}
    
    							public void onSuccess(String result) {
    								dialogBox.setText("Remote Procedure Call");
    								serverResponseLabel.removeStyleName("serverResponseLabelError");
    								serverResponseLabel.setHTML(result);
    								dialogBox.center();
    								closeButton.setFocus(true);
    /** INSERTED CODE HERE **/
    								String s0 = "<?xml version='1.0' encoding='UTF-8'?><s0><s1>test</s1></s0>";
    								Document doc = XMLParser.parse( s0 );
    								Element top = doc.getDocumentElement();
    								Node obj1 = top.getFirstChild();
    								String s1 = XMLTools.selectString( top,"s1" );
    								Object nodes = XMLTools.selectObjects( top,"s0" );
    /** END **/
    							}
    						});
    			}
    		}
    
    		// Add a handler to send the name to the server
    		MyHandler handler = new MyHandler();
    		sendButton.addClickHandler(handler);
    		nameField.addKeyUpHandler(handler);
    	}
    }
    After calling 'selectString' (or 'selectObjects'), the system loops for a few seconds and then thorws the following exception:

    Code:
    10:34:26.679 [ERROR] [test1] Uncaught exception escaped
    com.google.gwt.core.client.JavaScriptException: (null): null
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:195)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
        at com.smartgwt.client.data.XMLTools.selectString(XMLTools.java)
        at com.introspect.test.client.Test1$1MyHandler$1.onSuccess(Test1.java:154)
        at com.introspect.test.client.Test1$1MyHandler$1.onSuccess(Test1.java:1)
        at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:216)
        at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
        at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:393)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
        at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
        at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
        at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:188)
        at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
        at com.google.gwt.dev.shell.BrowserChannel.reactToMessages(BrowserChannel.java:1668)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
        at java.lang.Thread.run(Thread.java:637)
    Can anyone advise on this?
    Thank you.
Working...
X