Automatically fill Text Boxes

My form contains two text boxes, when I type 2 in my first text box, then next text box automatically fill with 4. How can I do it. without pressing button

You should look into using a community provided component called “SuperImmediateTextField”, which will do the thing you need.

You’ll find more about it on this forum thread:
SuperImmediateTextField

Please Help me still I unable to run superimmediatetextfield application, I refer this link
code
. I used that code without changing any line but i was fail.

First I created Vaadin application and set class name as
SuperimmediatetextfieldApplication.java
and below show that code


package com.vaadin.incubator.superimmediatetextfield;

import com.vaadin.Application;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Window;

@SuppressWarnings("serial")
public class SuperimmediatetextfieldApplication extends Application {

    @Override
    public void init() {
        final Window mainWindow = new Window(
                "Superimmediatetextfield Application");
        setMainWindow(mainWindow);
        final Panel panel = new Panel("SuperImmediateTextField examples");

        final HorizontalLayout semiSuperImmediate = new HorizontalLayout();
        final SuperImmediateTextField semiSuperImmediateTextField = new SuperImmediateTextField();
        final Label semiSuperImmediateLabel = new Label(
                "I'm a Label, mirroring the field with a second's delay.");

        semiSuperImmediate.addComponent(semiSuperImmediateTextField);
        semiSuperImmediate.addComponent(semiSuperImmediateLabel);

        semiSuperImmediateTextField.setDelay(1000);
        semiSuperImmediateTextField.setInputPrompt("type something");
        semiSuperImmediateTextField
                .addListener(new SuperImmediateTextField.KeyPressListener() {
                    private static final long serialVersionUID = -3549051979588281670L;

                    public void keyPressed(
                            SuperImmediateTextField.KeyPressEvent event) {
                        semiSuperImmediateLabel
                                .setValue(semiSuperImmediateTextField
                                        .getValue());
                    }
                });

        final HorizontalLayout verySuperImmediate = new HorizontalLayout();
        final SuperImmediateTextField verySuperImmediateTextField = new SuperImmediateTextField();
        final Label verySuperImmediateLabel = new Label(
                "I'm a Label, mirroring the field immediately.");

        verySuperImmediate.addComponent(verySuperImmediateTextField);
        verySuperImmediate.addComponent(verySuperImmediateLabel);

        verySuperImmediateTextField.setDelay(0);
        verySuperImmediateTextField.setInputPrompt("type something");
        verySuperImmediateTextField
                .addListener(new SuperImmediateTextField.KeyPressListener() {
                    private static final long serialVersionUID = 3729899805732151471L;

                    public void keyPressed(
                            SuperImmediateTextField.KeyPressEvent event) {
                        verySuperImmediateLabel
                                .setValue(verySuperImmediateTextField
                                        .getValue());
                    }
                });

        panel.addComponent(semiSuperImmediate);
        panel.addComponent(verySuperImmediate);

        mainWindow.setContent(panel);
    }
}

After that I created vaadin widgetset and put name as
SuperimmediatetextfieldApplicationWidgetset.java
and I used IDE generated code because sample didin’t contain this sort of file below show my default generated code


package com.vaadin.incubator.superimmediatetextfield.client;

import com.vaadin.incubator.superimmediatetextfield.client.ui.VSuperImmediateTextField;
import com.vaadin.terminal.gwt.client.DefaultWidgetSet;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.UIDL;

public class SuperimmediatetextfieldApplicationWidgetset extends
		DefaultWidgetSet {

	/** Creates a widget according to its class name. */
	public Paintable createWidget(UIDL uidl) {
		final Class<?> classType = resolveWidgetType(uidl);

		Paintable p = createWidgetByClass(classType);
		if (p == null) {
			// Let the DefaultWidgetSet handle creation of default widgets
			p = super.createWidget(uidl);
		}

		return p;
	}

	/** Resolves UIDL tag name to class . */
	protected Class<?> resolveWidgetType(UIDL uidl) {
		final String tag = uidl.getTag();

		Class<?> c = resolveWidgetByTag(tag);

		if (c == null) {
			c = super.resolveWidgetType(uidl);
		}

		// Let the DefaultWidgetSet handle resolution of default widgets
		return c;
	}

	// This method gets AUTOGENERATED by Vaadin plugin
	private Paintable createWidgetByClass(Class<?> classType) {
		if (classType == VSuperImmediateTextField.class) {
			return new VSuperImmediateTextField();
		} else {
			return null;
		}
	}

	// This method gets AUTOGENERATED by Vaadin plugin
	private Class<?> resolveWidgetByTag(final String tag) {
		if (VSuperImmediateTextField.TAGNAME.equals(tag)) {
			return VSuperImmediateTextField.class;
		} else {
			return null;
		}
	}

}

After that i create widgetset and set name as
SuperImmediateTextField.java
below show that code


package com.vaadin.incubator.superimmediatetextfield;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

import com.vaadin.data.Property;
import com.vaadin.incubator.superimmediatetextfield.client.ui.VSuperImmediateTextField;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.ui.ClientWidget;
import com.vaadin.ui.TextField;

/**
 * A text input widget that recognizes each keypress and informs the server side
 * about the event.
 * 
 * @author Henrik Paul
 * @see TextField
 */
@ClientWidget(VSuperImmediateTextField.class)
public class SuperImmediateTextField extends TextField {

    /**
     * A class that is informed whenever a {@link SuperImmediateTextField} is
     * typed upon.
     * 
     * @author Henrik Paul
     * @see SuperImmediateTextField#addListener(KeyPressListener)
     * @see SuperImmediateTextField#removeListener(KeyPressListener)
     */
    public interface KeyPressListener extends Serializable {
        /**
         * Inform that a key has been pressed in an
         * {@link SuperImmediateTextField}.
         * 
         * @param event
         */
        public void keyPressed(KeyPressEvent event);
    }

    /**
     * An event that is sent whenever a key is pressed in a
     * {@link SuperImmediateTextField}.
     * 
     * @author Henrik Paul
     */
    public interface KeyPressEvent extends Serializable {
        /**
         * Get the source of the {@link KeyPressEvent}.
         * 
         * @return The {@link SuperImmediateTextField} that was typed upon.
         */
        public SuperImmediateTextField getSource();
    }

    private static final long serialVersionUID = -8423510242229989097L;

    private final KeyPressEvent keypressEvent = new KeyPressEvent() {
        private static final long serialVersionUID = 1L;

        public SuperImmediateTextField getSource() {
            return SuperImmediateTextField.this;
        }
    };

    private final Collection<KeyPressListener> listeners = new ArrayList<KeyPressListener>();

    private int delayMillis = VSuperImmediateTextField.DEFAULT_DELAY;

    /**
     * @see TextField#TextField()
     */
    public SuperImmediateTextField() {
        super();
    }

    /**
     * @see TextField#TextField(Property)
     */
    public SuperImmediateTextField(Property dataSource) {
        super(dataSource);
    }

    /**
     * @see TextField#TextField(String, Property)
     */
    public SuperImmediateTextField(String caption, Property dataSource) {
        super(caption, dataSource);
    }

    /**
     * @see TextField#TextField(String, String)
     */
    public SuperImmediateTextField(String caption, String value) {
        super(caption, value);
    }

    /**
     * @see TextField#TextField(String)
     */
    public SuperImmediateTextField(String caption) {
        super(caption);
    }

    @Override
    @SuppressWarnings("unchecked")
    public void changeVariables(Object source, Map variables) {
        super.changeVariables(source, variables);

        if (variables.containsKey(VSuperImmediateTextField.PROPERTY_KEYPRESSED)) {
            fireKeyPressEvent();
        }
    }

    protected void fireKeyPressEvent() {
        for (KeyPressListener listener : listeners) {
            listener.keyPressed(keypressEvent);
        }
    }

    public void addListener(KeyPressListener listener) {
        if (listener != null) {
            listeners.add(listener);
        }
    }

    public void removeListener(KeyPressListener listener) {
        listeners.remove(listener);
    }

    /**
     * Set the delay to wait until the super immediate event is sent from when
     * the user starts typing.
     * 
     * @param delayInMillis
     *            How many milliseconds to wait. If negative, no event will be
     *            sent.
     */
    public void setDelay(final int delayInMillis) {
        delayMillis = delayInMillis;
        requestRepaint();
    }

    /**
     * Get the time waited between the user's start of typing and when the super
     * immediate event.
     * 
     * @return The delayed time in milliseconds. A negative result indicates
     *         that no events will be sent.
     */
    public int getDelay() {
        return delayMillis;
    }

    @Override
    public void paintContent(PaintTarget target) throws PaintException {
        super.paintContent(target);

        target.addAttribute(VSuperImmediateTextField.ATTRIBUTE_DELAY,
                delayMillis);
    }
}

While generating widgetset another file created
VSuperImmediateTextField.java


package com.vaadin.incubator.superimmediatetextfield.client.ui;

import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Timer;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.ui.VTextField;

public class VSuperImmediateTextField extends VTextField implements
        KeyUpHandler {

    /** Set the tagname used to statically resolve widget from UIDL. */
    public static final String TAGNAME = "superimmediatetextfield";

    /** Set the CSS class name to allow styling. */
    public static final String CLASSNAME = "v-" + TAGNAME;

    public static final String PROPERTY_KEYPRESSED = "keypressed";
    public static final String ATTRIBUTE_DELAY = "delay";
    public static final int DEFAULT_DELAY = 300;

    private int delayMillis = DEFAULT_DELAY;
    private Timer timer = null;

    public VSuperImmediateTextField() {
        this(DOM.createInputText());
    }

    protected VSuperImmediateTextField(Element node) {
        super(node);

        setStyleName(CLASSNAME);
        addKeyUpHandler(this);
    }

    public void onKeyUp(KeyUpEvent event) {
        if (delayMillis == 0) {
            sendSuperImmediateEvent();
        }

        else if (delayMillis > 0) {
            if (timer == null) {
                timer = newTimer();
            } else {
                timer.cancel();
            }

            timer.schedule(delayMillis);
        }
    }

    @Override
    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
        super.updateFromUIDL(uidl, client);

        if (client.updateComponent(this, uidl, true)) {
            return;
        }

        if (uidl.hasAttribute(ATTRIBUTE_DELAY)) {
            delayMillis = uidl.getIntAttribute(ATTRIBUTE_DELAY);
        }
    }

    private Timer newTimer() {
        return new Timer() {
            public void run() {
                sendSuperImmediateEvent();
                timer = null;
            }
        };
    }

    public void sendSuperImmediateEvent() {
        client.updateVariable(client.getPid(this), PROPERTY_KEYPRESSED, true,
                false);
        client.updateVariable(client.getPid(this), "text", getText(), false);
        client.sendPendingVariableChanges();
    }

    @Override
    protected void onDetach() {
        super.onDetach();

        if (timer != null) {
            timer.cancel();
        }
    }
}

hear is my
widgetset.gwt.xml-file


<module>
	<!-- Inherit super widgetset -->
	<inherits name="com.vaadin.terminal.gwt.DefaultWidgetSet" /> 
	
	<!-- Entry point -->
	<entry-point class="com.vaadin.incubator.superimmediatetextfield.client.SuperimmediatetextfieldApplicationWidgetset"/>
	
</module>

After running this project interfaces are loaded but function are not work. Please help to configure and run this application correctly. what sort of thing show i write SuperimmediatetextfieldApplicationWidgetset.java file

To me all seems okay. Just to make sure, you did actually compile the widgetset before trying to run it, right? See the chapter
“Compiling GWT Widget Sets”
from the Book.

Another thing I noticed, that you do not need, is the @ClientWidget annotation in VSuperImmediateTextField.java. That’s only needed if you’re using Vaadin 6.2 nightlies and the new compilation process (which I assume you’re not using).

If these were not the issue, I’ll try and compile it myself like you did to see where the problem lies.

Edit: one more thing: what does your src-package structure look like? The .gwt.xml module descriptor and the VSuperImm…java files must reside correctly for the GWT compiler to work.

E.g. if the .gwt.xml file is in package com.vaadin.incubator.superimmediatetextfield, then the VSuperImm…java file must be inside com.vaadin.incubator.superimmediatetextfield.client package. And if I’m seeing correctly, your .gwt.xml file is actually inside the client package as well, and it won’t work then. Try moving the module descriptor one level up in the package hierarchy.

I changed SuperImmediateTextField.java class. I removed

import com.vaadin.ui.ClientWidget;
@ClientWidget(VSuperImmediateTextField.class)

and vaadin 6.2 nightly builds

and put


@Override
    public String getTag() {
        return "superimmediatetextfield";
    }

I used vaadin-6.1.5 . please give comments if I wrong.