TextField setSecret doesn't work in a FormLayout?

I have the following two classes, that just contain a TextField. One is just in an AbsoluteLayout (class Test2), the other is in a FormLayout which is on an AbsoluteLayout (class Test). setSecret works fine in the first one but doesn’t work at all in the second. How can I get it to work in the FormLayout?

import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.TextField;

public class Test extends CustomComponent {

	@AutoGenerated
	private AbsoluteLayout mainLayout;
	@AutoGenerated
	private FormLayout testFormLayout;
	@AutoGenerated
	private TextField passwordTextField;
	/**
	 * The constructor should first build the main layout, set the
	 * composition root and then do any custom initialization.
	 *
	 * The constructor will not be automatically regenerated by the
	 * visual editor.
	 */
	public Test() {
		buildMainLayout();
		setCompositionRoot(mainLayout);

		// TODO add user code here
		passwordTextField.setSecret(true);
		passwordTextField.setValue("1234567");
	}

	@AutoGenerated
	private AbsoluteLayout buildMainLayout() {
		// common part: create layout
		mainLayout = new AbsoluteLayout();
		
		// top-level component properties
		setWidth("100.0%");
		setHeight("100.0%");
		
		// testFormLayout
		testFormLayout = buildTestFormLayout();
		mainLayout.addComponent(testFormLayout,
				"top:20.0px;bottom:331.0px;left:0.0px;");
		
		return mainLayout;
	}

	@AutoGenerated
	private FormLayout buildTestFormLayout() {
		// common part: create layout
		testFormLayout = new FormLayout();
		testFormLayout.setWidth("300px");
		testFormLayout.setHeight("100.0%");
		testFormLayout.setCaption("Test Password Textfield on a Form");
		testFormLayout.setImmediate(true);
		testFormLayout.setMargin(false);
		testFormLayout.setSpacing(true);
		
		// passwordTextField
		passwordTextField = new TextField();
		passwordTextField.setWidth("150px");
		passwordTextField.setHeight("30px");
		passwordTextField.setCaption("Password");
		passwordTextField.setImmediate(true);
		testFormLayout.addComponent(passwordTextField);
		
		return testFormLayout;
	}
}

import com.vaadin.annotations.AutoGenerated;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.TextField;

public class Test2 extends CustomComponent {

	@AutoGenerated
	private AbsoluteLayout mainLayout;
	@AutoGenerated
	private TextField passwordTextField;
	/**
	 * The constructor should first build the main layout, set the
	 * composition root and then do any custom initialization.
	 *
	 * The constructor will not be automatically regenerated by the
	 * visual editor.
	 */
	public Test2() {
		buildMainLayout();
		setCompositionRoot(mainLayout);

		// TODO add user code here
		passwordTextField.setSecret(true);
		passwordTextField.setValue("1234567");		
	}

	@AutoGenerated
	private AbsoluteLayout buildMainLayout() {
		// common part: create layout
		mainLayout = new AbsoluteLayout();
		
		// top-level component properties
		setWidth("100.0%");
		setHeight("100.0%");
		
		// passwordTextField
		passwordTextField = new TextField();
		passwordTextField.setWidth("-1px");
		passwordTextField.setHeight("-1px");
		passwordTextField.setCaption("Password");
		mainLayout.addComponent(passwordTextField, "top:34.0px;left:23.0px;");
		
		return mainLayout;
	}

}

The application just does:

import com.vaadin.Application;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.Window;

public class TestApp extends Application {

	private AbsoluteLayout mainLayout;
	
	@Override
	public void init() {
		Window main = new Window("Test");
		setMainWindow(main);

		mainLayout = new AbsoluteLayout();
		mainLayout.setWidth("100%");
		mainLayout.setHeight("100%");
		mainLayout.setImmediate(false);
		mainLayout.setMargin(false);	
		main.setContent(mainLayout);
		
		Test t = new Test();
		Test2 t2 = new Test2();
		t.setWidth("100%");
		mainLayout.addComponent(t,"left:10px;top:13px");
		mainLayout.addComponent(t2,"left:300px;top:8px");
} }

I think I’ve answered my own question. setSecret() works when the height is set to “-1px”. This doesn’t seem to be documented anywhere.

A related issue is the following. In my application, I use the PasswordField add-on. It works great in a Dialog which extends Window and which is added to the main window (this is also used in the test application for the WindowsTheme add-on).

Instead of a TextField with setSecret set to True, I first used a PasswordField instead of a TextField in the AbsoluteLayout or the FormLayout in the AbsoluteLayout (as per Test and Test2 above). No matter what I tried, I got the following:

I have gone through all the mentions of this problem in the forums and elsewhere to no avail. I have recompiled the widgetset dozens of times. I have played around with the various xml files etc.

And PasswordField works fine in a separate part of the application.

Any idea what is going on here? I’m using Eclipse Helios SR1, Vaadin 6.4.8, the 1.3.0.201011300200 version of vaadin eclipse integration, version 2.0.3 of gwt SDK, and 1.4.0 of App Engine (I upgraded from 1.3.8 to see if that made any difference and it did not).

The setSecret issue sounds odd. You seem to have used the experimental Visual Editor. For some reason, it sets a fixed size for the password TextField, which is not necessary. But it shouldn’t make the component disappear.

The missing implementation error means that the widget set is not compiled properly. For some reason, the PasswordField widget set is not included in the application’s widget set.

Please check:

[list=1]

[]
that the widget set compilation mentions that it has found the PasswordFieldWidgetset (it should be generated in the combining widget set file as an element),
[
]
that the PasswordField is listed in the compilation output among widgets to be included in the widget set,
[*]
that the application actually uses the compiled widget set (the application must have correct widgetset parameter in web.xml).

[/list]Did I forget something? See the
Using Add-ons: Troubleshooting
section in the Book.

Where are you seeing the error - in the Visual Editor or in your running application?

Visual Editor does not really support add-ons yet, and uses its own built-in widgetset with some customizations. Some server-side subclasses of standard components might work, but widgets that require a custom client side implementation probably don’t.

You could try to use a TextField in Visual Editor and then replace it with a PasswordField run-time in the constructor of your visually composed class or in the attach() method.

Note also that Visual Editor 0.6 was released yesterday - not sure if you were already using that branch.

Thanks, this helped me figure it out. It was item 3. The web.xml did have the correct widgetset parameter but only for one of the two GAEApplicationServlets. I thought it was a global setting but only just now noticed it was within a particular servlet and was missing for the other one.

The TextField doesn’t disappear, the text just shows up as text instead of as hidden.

Thanks,

Jonathan

Henri,

The error only showed up when running the application. The solution is described above in response to Marko’s post. I was using the latest Visual Editor but it wasn’t a Visual Editor issue.

There likely remains an issue with setSecret when it has a fixed height. The code I included should easily help verify that.

Thanks,

Jonathan

When you change the height of a TextField, it can become effectively a (multi-line) VTextArea on the client side. It does not support the “secret” mode.

In Vaadin 6.5, there will be a separate PasswordField core component that is effectively just a TextField with the “secret” setting turned on, and that should not exhibit this behavior.