SQLContainer Form set Default value

I’m trying to set a default value to a field in a form.

setFormFieldFactory(new DefaultFieldFactory() {
			public Field createField(Item item,Object propertyId,Component uiContext) {
				Field field;
				 if (propertyId.equals("id_Sim_Card_Type")) {
				}else if (propertyId.equals("id_Client")) {
					field=super.createField(item, propertyId, uiContext);
				else {
					field=super.createField(item, propertyId, uiContext);
				return field;

But the result is always the same the value stays to null.

You probably bind it to and item after that? (or does SQLContainer do some magic that I’m not aware of?) When you call setItemDataSource(Item), the form will look for the property id_Client in the item, and call setValue on the field with getItemProperty(“id_Client”).getValue(). This means that what ever you do to the value in the fieldfactory, it will be overridden when some data is bound to it. This is one of the core features of forms.

What you can do is either manipulate the item (getItemProperty(…).setValue(…)) itself before you bind it to the form, or modfiy the field value after that the data has been bound with something like form.getField(“id_Client”) (didn’t check the API). I think that the latter might be better because then form.isModified() will return true as well.