You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Raul <ra...@netwie.com> on 2012/12/03 22:34:34 UTC

Model is null after submit, using FormComponentPanel

Hello, I want to create a reusable component for use as part of a form, for
this class use FormComponentPanel,
As the following article.

https://cwiki.apache.org/WICKET/creating-custom-formcomponentpanels-to-build-valid-objects-using-wickets-form-validation-logic.html

My problem is that when I submit the internal components (TextFields),
updated its model to null, instead of updating the model with the entered
string, the method mytextfield.getConvertedInput () returns null during the
call to UpdateModel (). Does anyone know what might be happening?.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Model-is-null-after-submit-using-FormComponentPanel-tp4654441.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Model is null after submit, using FormComponentPanel

Posted by Raul <ra...@netwie.com>.
Thanks, your suggestion solved my problem. Greetings from Spain.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Model-is-null-after-submit-using-FormComponentPanel-tp4654441p4654594.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Model is null after submit, using FormComponentPanel

Posted by Sven Meier <sv...@meiers.net>.
Hi Raul,

there are a few things to improve here:
- in your case you don't need to extend FormComponentPanel
- if you really want to control the textField's inputName, you have to 
let the component know about it
- usage of models could be improved.

See here for some ideas:

http://www.fileconvoy.com/dfl.php?id=gdb276da925b2a095999178849bf06c4474e3bdd23

Sven

On 12/07/2012 10:06 AM, Raul wrote:
> Here is the example to prove it's package it and deploy it in an application
> server.
>
> http://ul.to/ymfabds0
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Model-is-null-after-submit-using-FormComponentPanel-tp4654441p4654586.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Model is null after submit, using FormComponentPanel

Posted by Raul <ra...@netwie.com>.
Here is the example to prove it's package it and deploy it in an application
server.

http://ul.to/ymfabds0



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Model-is-null-after-submit-using-FormComponentPanel-tp4654441p4654586.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Model is null after submit, using FormComponentPanel

Posted by Paul Bors <pa...@bors.ws>.
Clean it, zip it and just publish it somewhere where you can post the URL in
a reply to this thread :)

~ Thank you,
  Paul Bors

-----Original Message-----
From: Raul [mailto:ralvarez@netwie.com] 
Sent: Thursday, December 06, 2012 3:32 PM
To: users@wicket.apache.org
Subject: RE: Model is null after submit, using FormComponentPanel

I created a quickstart, Where I can upload it for what you may see?



--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/Model-is-null-after-submit-using-
FormComponentPanel-tp4654441p4654566.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Model is null after submit, using FormComponentPanel

Posted by Raul <ra...@netwie.com>.
I created a quickstart, Where I can upload it for what you may see?



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Model-is-null-after-submit-using-FormComponentPanel-tp4654441p4654566.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Model is null after submit, using FormComponentPanel

Posted by Joachim Schrod <js...@acm.org>.
Paul Bors wrote:
> Assuming that you don't set a model for the FormComponet won't Wicket fail
> back to the CompountPropertyModel of the form?

Yes, for sure. But you explicitly recommended:

>> If you're using CompoundPropertyModel and set the model on your
>> FormComponentPanel then your TextField ID and type should be all
you
>> need for wicket to know which getter/setter to call.

I.e., you told Raul that he should set the FormComponentPanel's
model. And then he risks getting null values set in his model at
the panel level.

Please note, that I don't argue for or against storing
CompountPropertyModels in FormComponetPanels. I have many places in
my applications where storing models is sensible and where the
form's CompountPropertyModel is not the right thing, design-wise.
And the other way round, too.

As a common use case, consider when a FormComponentPanel is
actually a reusable model that may be used in several situations. A
recent example of mine is a component that handles address input
and validation for a person. The base model, available as a
CompountPropertyModel at form level, has several persons. So the
FormComponentPanel gets passed the right person model (actually,
the address model from that person model -- a person might have
several addresses!) and uses it.

And in such cases, one has to take care that the FormComponent
processing lifecycle is properly adapted to such situation.

> Who will perform the conversion then?

As I've written, quite often it's not the conversion that's the
problem, but the updateModel() call that stores
FormComponent.convertedInput into the model object. To repeat: On
the panel level, no input is available, and convertInput() stores
that as null in FormComponent.convertedInput. You need to prevent
usage of that stored field in updateModel(), otherwise your model
object will end up to be null. Overriding convertInput() is of no
use here, if there *is no input* that can be converted.

Thus quite clearly, overriding FormComponentPanel#convertInput() is
only sensible if you do something with the input values of
sub-components, beyond storing them, and if you can compute
something that you can place into convertedInput. If it's just
about storing and you use a CompountPropertyModel, overriding
FormComponentPanel#updateModel() is adequate and sufficient.

I hope this makes my arguments clearer. It probably won't help
Raul, though. :-(

	Joachim

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Joachim Schrod, Roedermark, Germany
Email: jschrod@acm.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Model is null after submit, using FormComponentPanel

Posted by Paul Bors <pa...@bors.ws>.
Assuming that you don't set a model for the FormComponet won't Wicket fail
back to the CompountPropertyModel of the form?

Who will perform the conversion then?

I only override FormComponentPanel#convertInput() when I force my clients to
provide the model for my FormComponentPanel and even then I delegate the
call to another form component :)

e.g.

/**
 * {@link FormComponentPanel} that hosts the label and form component with a
shared model.<br>
 * The label can be aligned around the form field given the {@link LABEL}
value constants.
 * 
 * @param <F, M>
 *      F = The form field type (e.g. TextField, CheckBox etc.)
 *      M = The model object type of the form field
 */
public class LabeledFormField<F extends LabeledWebMarkupContainer, M>
extends FormComponentPanel<M> {
...
    public LabeledFormField(String id, IModel<M> model, ...) {
        ...
    }
...
    /**
     * Propagate changes into the real valid model via the
FormComponentPanel.convertInput() method.
     * {@inheritDoc}
     */
    @Override
    @SuppressWarnings("unchecked")
    protected void convertInput() {
        FormComponent<?> formComponent = ...
        if(formComponent != null) {
            setConvertedInput((M)formComponent.getConvertedInput());
        }
    }
...
}

Above class warps around all the form field I use to ensure that
accessibility is supported.

I did so per the recommendation of Wicket:
http://ci.apache.org/projects/wicket/apidocs/6.0.x/org/apache/wicket/markup/
html/form/FormComponentPanel.html

It is recommended that you override FormComponent.convertInput() and let it
set the value that represents the compound value of the nested components.
Often, this goes hand-in-hand with overriding Component.onBeforeRender(),
where you would analyze the model value, break it up and distribute the
appropriate values over the child components.

But if you have a CompoundPropertyModel, do you really need to do all this
conversion?
Wouldn't the form component wrapped inside the panel handle it itself?

I had to delegate the call because I don't always use a
CompoundProeprtyModel.

~ Thank you,
  Paul Bors

-----Original Message-----
From: Joachim Schrod [mailto:jschrod@acm.org] 
Sent: Thursday, December 06, 2012 2:05 PM
To: users@wicket.apache.org
Subject: Re: Model is null after submit, using FormComponentPanel

Paul Bors wrote:
> I would suggest overriding FormComponentPanel#convertInput() only if 
> your domain object can't be easily converted by Wicket given the model you
have.
> 
> If you're using CompoundPropertyModel and set the model on your 
> FormComponentPanel then your TextField ID and type should be all you 
> need for wicket to know which getter/setter to call.

Really? That's not possible in an 1.4-based application, IMHO.

FormComponentPanel is a FormComponent, i.e., it participates in conversion,
validation, and update Model. When that FormComponentPanel has an associated
model, e.g., a CompoundPropertyModel, its getInputAsArray() will return
null, null will be stored as convertedInput, and updateModel() will set the
CompoundPropertyModel's object to that null value.

When sub-widgets of a FormComponentPanel do all the work necessary, and the
FormComponentPanel has a model of its own, I often override
updateModel() to be an empty method, to prevent the behavior named above
from happening.

Best,
	Joachim

--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Joachim Schrod, Roedermark, Germany
Email: jschrod@acm.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Model is null after submit, using FormComponentPanel

Posted by Joachim Schrod <js...@acm.org>.
Paul Bors wrote:
> I would suggest overriding FormComponentPanel#convertInput() only if your
> domain object can't be easily converted by Wicket given the model you have.
> 
> If you're using CompoundPropertyModel and set the model on your
> FormComponentPanel then your TextField ID and type should be all you need
> for wicket to know which getter/setter to call.

Really? That's not possible in an 1.4-based application, IMHO.

FormComponentPanel is a FormComponent, i.e., it participates in
conversion, validation, and update Model. When that
FormComponentPanel has an associated model, e.g., a
CompoundPropertyModel, its getInputAsArray() will return null, null
will be stored as convertedInput, and updateModel() will set the
CompoundPropertyModel's object to that null value.

When sub-widgets of a FormComponentPanel do all the work necessary,
and the FormComponentPanel has a model of its own, I often override
updateModel() to be an empty method, to prevent the behavior named
above from happening.

Best,
	Joachim

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Joachim Schrod, Roedermark, Germany
Email: jschrod@acm.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Model is null after submit, using FormComponentPanel

Posted by Paul Bors <pa...@bors.ws>.
I would suggest overriding FormComponentPanel#convertInput() only if your
domain object can't be easily converted by Wicket given the model you have.

If you're using CompoundPropertyModel and set the model on your
FormComponentPanel then your TextField ID and type should be all you need
for wicket to know which getter/setter to call.

Since you mentioned that you can see the values rendered okay but you can't
change them via your form submit I would ask to see the full picture.

Can you create a quick start and show it to us?
http://wicket.apache.org/start/quickstart.html

Also take a look at FormComponentPanel's direct known subclasses:
DateTimeField, MultiFileUploadField, Multiply

~ Thank you,
  Paul Bors

-----Original Message-----
From: Raul [mailto:ralvarez@netwie.com] 
Sent: Thursday, December 06, 2012 10:35 AM
To: users@wicket.apache.org
Subject: Re: Model is null after submit, using FormComponentPanel

I've tried to override FormComponentPanel#convertInput (),  but in the
execution of this, both the method TextField#getConvertedInput () and
TextField#getModelObject () return null. By the way I'm using Wicket 6.3



--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/Model-is-null-after-submit-using-
FormComponentPanel-tp4654441p4654557.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Model is null after submit, using FormComponentPanel

Posted by Raul <ra...@netwie.com>.
I've tried to override FormComponentPanel#convertInput (),  but in the
execution of this, both the method TextField#getConvertedInput () and
TextField#getModelObject () return null. By the way I'm using Wicket 6.3



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Model-is-null-after-submit-using-FormComponentPanel-tp4654441p4654557.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Model is null after submit, using FormComponentPanel

Posted by Tobias Gierke <to...@voipfuture.com>.
Hi,

I think you need to override FormComponentPanel#convertInput().

Cheers,
Tobias
> Thanks for the reply, I tried to use the component on the form with the
> object
> CompoundPropertyModel. As follows,
>
> ccc = new CustomerAccountCode("ccc",
> new CompoundPropertyModel<Account>(new Account(config.getCcc())));
> form.add(ccc);
> 		
> But this does the same as before, ie load correctly displayed data, but when
> you throw the "onSubmit" form, the model
> the "ccc.getModelObject()" still returns null.
>
> //New implementation	
> public class CustomerAccountCode extends
> 		FormComponentPanel<Account> {
>
> 	private FormComponent<String> entity;
> 	private FormComponent<String> office;
> 	private FormComponent<String> dc;
> 	private FormComponent<String> number;
>
> 	public CustomerAccountCode(String id, CompoundPropertyModel<Account> model)
> {
> 		super(id, model);
> 				
> 		entity = new TextField<String>("entity");
> 		office = new TextField<String>("office");
> 		dc = new TextField<String>("dc");
> 		number = new TextField<String>("number");
> 		
> 		AttributeModifier attEntity = new AttributeModifier("name", "entity");
> 		AttributeModifier attOffice = new AttributeModifier("name", "office");
> 		AttributeModifier attDc = new AttributeModifier("name", "dc");
> 		AttributeModifier attNumber = new AttributeModifier("name", "number");
> 		add(entity.add(attEntity));
> 		add(office.add(attOffice));
> 		add(dc.add(attDc));
> 		add(number.add(attNumber));
> //		add(CustomerAccountCodeValidator.getInstance());
>
> 	}
>
> 	@Override
> 	public Component add(final Behavior... behaviors) {
> 		entity.add(behaviors);
> 		office.add(behaviors);
> 		dc.add(behaviors);
> 		number.add(behaviors);
> 		return this;
> 	}
> }
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Model-is-null-after-submit-using-FormComponentPanel-tp4654441p4654545.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


-- 
Tobias Gierke
Development

VOIPFUTURE GmbH   Wendenstraße 4   20097 Hamburg,  Germany
Phone +49 40 688 900 111 Mobile +49 172 323 06 11 Fax +49 40 688 900 199
Email jan.bastian@voipfuture.com   Web http://www.voipfuture.com
  
CEO Jan Bastian
	
Commercial Court AG Hamburg   HRB 109896, VAT ID DE263738086



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Model is null after submit, using FormComponentPanel

Posted by Raul <ra...@netwie.com>.
Thanks for the reply, I tried to use the component on the form with the
object
CompoundPropertyModel. As follows,

ccc = new CustomerAccountCode("ccc", 
new CompoundPropertyModel<Account>(new Account(config.getCcc())));
form.add(ccc);
		
But this does the same as before, ie load correctly displayed data, but when
you throw the "onSubmit" form, the model
the "ccc.getModelObject()" still returns null. 

//New implementation	
public class CustomerAccountCode extends
		FormComponentPanel<Account> {

	private FormComponent<String> entity;
	private FormComponent<String> office;
	private FormComponent<String> dc;
	private FormComponent<String> number;

	public CustomerAccountCode(String id, CompoundPropertyModel<Account> model)
{
		super(id, model);
				
		entity = new TextField<String>("entity");
		office = new TextField<String>("office");
		dc = new TextField<String>("dc");
		number = new TextField<String>("number");
		
		AttributeModifier attEntity = new AttributeModifier("name", "entity");
		AttributeModifier attOffice = new AttributeModifier("name", "office");
		AttributeModifier attDc = new AttributeModifier("name", "dc");
		AttributeModifier attNumber = new AttributeModifier("name", "number");
		add(entity.add(attEntity));
		add(office.add(attOffice));
		add(dc.add(attDc));
		add(number.add(attNumber));
//		add(CustomerAccountCodeValidator.getInstance());

	}

	@Override
	public Component add(final Behavior... behaviors) {
		entity.add(behaviors);
		office.add(behaviors);
		dc.add(behaviors);
		number.add(behaviors);
		return this;
	}
}



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Model-is-null-after-submit-using-FormComponentPanel-tp4654441p4654545.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Model is null after submit, using FormComponentPanel

Posted by Paul Borș <pa...@bors.ws>.
Take a look at https://cwiki.apache.org/WICKET/working-with-wicket-models.html

Okay so Account is the type of the model object and your FormComponentPanel seem to work off a CustomerAccountCodeModel:
>> CustomerAccountCodeModel ccc = getModelObject();


If I'm understanding this right, what does your CustomerAccountCodeModel's getObject() and setObject() do?

I would switch to a CompundPropertyModel and I would leave the models null for the form fields. This way you won't need any your own implementation of onModelChange().

~ Thank you,
    Paul Bors

On Dec 4, 2012, at 1:48 PM, Joachim Schrod <js...@acm.org> wrote:

> Raul wrote:
>> Thank Col, But I have no validation, my component code is the code of the
>> component is
>> 
>> public class CustomerAccountCode extends
>>        FormComponentPanel<Account> {
>> 
>>    private FormComponent<String> entity;
>>    private FormComponent<String> office;
>>    private FormComponent<String> dc;
>>    private FormComponent<String> number;
>> 
>> 
>>    public CustomerAccountCode(String id, Model<Account> model) {
>>        super(id, model);
>>        
>>        entity = new TextField<String>("entity", new Model<String>());
>>        office = new TextField<String>("office", new Model<String>());
>>        dc = new TextField<String>("dc", new Model<String>());
>>        number = new TextField<String>("number", new Model<String>());
>> 
>>        onModelChanged();
>>        add(entity);
>>        add(office);
>>        add(dc);
>>        add(number);
>> //        add(CustomerAccountCodeValidator.getInstance());
>> 
>>    }
>> 
>>    protected void onModelChanged() {
>>        super.onModelChanged();
>>        CustomerAccountCodeModel ccc = getModelObject();
>>        if (ccc != null) {
>>            entity.setModelObject(ccc.getEntity());
>>            office.setModelObject(ccc.getOffice());
>>            dc.setModelObject(ccc.getDc());
>>            number.setModelObject(ccc.getAccount());
>>        } else {
>>            entity.setModelObject(null);
>>            office.setModelObject(null);
>>            dc.setModelObject(null);
>>            number.setModelObject(null);
>>        }
>>    }
> 
> Did you try to use PropertyModels of your account object, maybe a
> CompoundPropertyModel instead of setting the TextField's model
> objects in the constructor that way?
> 
>    Joachim
> 
> -- 
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> Joachim Schrod, Roedermark, Germany
> Email: jschrod@acm.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 

Re: Model is null after submit, using FormComponentPanel

Posted by Raul <ra...@netwie.com>.
I tried to use CompoundPropertyModel <Account> in CustomerAccountCode object
constructor, and similarly



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Model-is-null-after-submit-using-FormComponentPanel-tp4654441p4654490.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Model is null after submit, using FormComponentPanel

Posted by Joachim Schrod <js...@acm.org>.
Raul wrote:
> Thank Col, But I have no validation, my component code is the code of the
> component is
> 
> public class CustomerAccountCode extends
> 		FormComponentPanel<Account> {
> 
> 	private FormComponent<String> entity;
> 	private FormComponent<String> office;
> 	private FormComponent<String> dc;
> 	private FormComponent<String> number;
> 
> 
> 	public CustomerAccountCode(String id, Model<Account> model) {
> 		super(id, model);
> 		
> 		entity = new TextField<String>("entity", new Model<String>());
> 		office = new TextField<String>("office", new Model<String>());
> 		dc = new TextField<String>("dc", new Model<String>());
> 		number = new TextField<String>("number", new Model<String>());
> 
> 		onModelChanged();
> 		add(entity);
> 		add(office);
> 		add(dc);
> 		add(number);
> //		add(CustomerAccountCodeValidator.getInstance());
> 
> 	}
> 
> 	protected void onModelChanged() {
> 		super.onModelChanged();
> 		CustomerAccountCodeModel ccc = getModelObject();
> 		if (ccc != null) {
> 			entity.setModelObject(ccc.getEntity());
> 			office.setModelObject(ccc.getOffice());
> 			dc.setModelObject(ccc.getDc());
> 			number.setModelObject(ccc.getAccount());
> 		} else {
> 			entity.setModelObject(null);
> 			office.setModelObject(null);
> 			dc.setModelObject(null);
> 			number.setModelObject(null);
> 		}
> 	}

Did you try to use PropertyModels of your account object, maybe a
CompoundPropertyModel instead of setting the TextField's model
objects in the constructor that way?

	Joachim

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Joachim Schrod, Roedermark, Germany
Email: jschrod@acm.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Model is null after submit, using FormComponentPanel

Posted by Raul <ra...@netwie.com>.
Thank Col, But I have no validation, my component code is the code of the
component is

public class CustomerAccountCode extends
		FormComponentPanel<Account> {

	private FormComponent<String> entity;
	private FormComponent<String> office;
	private FormComponent<String> dc;
	private FormComponent<String> number;


	public CustomerAccountCode(String id, Model<Account> model) {
		super(id, model);
		
		entity = new TextField<String>("entity", new Model<String>());
		office = new TextField<String>("office", new Model<String>());
		dc = new TextField<String>("dc", new Model<String>());
		number = new TextField<String>("number", new Model<String>());

		onModelChanged();
		add(entity);
		add(office);
		add(dc);
		add(number);
//		add(CustomerAccountCodeValidator.getInstance());

	}

	protected void onModelChanged() {
		super.onModelChanged();
		CustomerAccountCodeModel ccc = getModelObject();
		if (ccc != null) {
			entity.setModelObject(ccc.getEntity());
			office.setModelObject(ccc.getOffice());
			dc.setModelObject(ccc.getDc());
			number.setModelObject(ccc.getAccount());
		} else {
			entity.setModelObject(null);
			office.setModelObject(null);
			dc.setModelObject(null);
			number.setModelObject(null);
		}
	}

	@Override
	protected void convertInput() {
		Account account = new Account(
				entity.getConvertedInput(), office.getConvertedInput(),
				dc.getConvertedInput(), number.getConvertedInput());
	
		if (Strings.isEmpty(account.getEntity()) &&
Strings.isEmpty(account.getDc())
  		&& Strings.isEmpty(account.getOffice()) &&
Strings.isEmpty(account.getNumber())) {
			account = null;
		}
		setConvertedInput(account);
	}
	
	@Override 
	public void updateModel(){
		System.err.println("UPDATE MODEL" +entity.getConvertedInput());	
	}

	@Override
	public Component add(final Behavior... behaviors) {
		entity.add(behaviors);
		office.add(behaviors);
		dc.add(behaviors);
		number.add(behaviors);
		return this;
	}
}

The model takes it perfectly when constrye the object, but loses to do
submit, I use the component on the form as follows

HTML FORM
<form id="form" name="form" wicket:id="form">
				

					

							CCC:
							<wicket:container wicket:id="ccc"/>
							 Editar <javascript:enableFieldccc()>  
					
					

					...
JAVA FORM
    ....
    ccc = new CustomerAccountCode("ccc",
				new Model<Account>(
						new Account(config.getCcc())));
   add(ccc);
   ....



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Model-is-null-after-submit-using-FormComponentPanel-tp4654441p4654462.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: Model is null after submit, using FormComponentPanel

Posted by Colin Rogers <Co...@objectconsulting.com.au>.
Raul,

There are better qualified people to answer this, but...

Are the components actually passing validation? Pre-validation the model would be null - if the validation fails the model would be null. If the component validates then the model would be updated with the valid value.

Col.

-----Original Message-----
From: Raul [mailto:ralvarez@netwie.com]
Sent: Tuesday, 4 December 2012 8:35 AM
To: users@wicket.apache.org
Subject: Model is null after submit, using FormComponentPanel

Hello, I want to create a reusable component for use as part of a form, for this class use FormComponentPanel, As the following article.

https://cwiki.apache.org/WICKET/creating-custom-formcomponentpanels-to-build-valid-objects-using-wickets-form-validation-logic.html

My problem is that when I submit the internal components (TextFields), updated its model to null, instead of updating the model with the entered string, the method mytextfield.getConvertedInput () returns null during the call to UpdateModel (). Does anyone know what might be happening?.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Model-is-null-after-submit-using-FormComponentPanel-tp4654441.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org

EMAIL DISCLAIMER This email message and its attachments are confidential and may also contain copyright or privileged material. If you are not the intended recipient, you may not forward the email or disclose or use the information contained in it. If you have received this email message in error, please advise the sender immediately by replying to this email and delete the message and any associated attachments. Any views, opinions, conclusions, advice or statements expressed in this email message are those of the individual sender and should not be relied upon as the considered view, opinion, conclusions, advice or statement of this company except where the sender expressly, and with authority, states them to be the considered view, opinion, conclusions, advice or statement of this company. Every care is taken but we recommend that you scan any attachments for viruses.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org