You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Gytis <li...@mail.ru> on 2012/03/05 14:02:38 UTC

wicket wizard init

hello, I have such a problem
I develop wizard in which user enters some values in first step fields, then
I need to use those values in a second step in a text. looks like this:

userModel = new CompoundPropertyModel<WizardPage>(this);
setDefaultModel(userModel);
WizardModel model = new WizardModel();

model.add(new Step1());
model.add(new Step2());

init();

Step1(){
super("summary","title");

TextField name = new TextField("user.name");
TextField surname = new TextField("user.surname");

Form f1 = new Form("f1");
f1.add(name);
f1.add(surname);
}

Step2(){
super("summary2", "title2");

agreementText = getAgreementText();
Label textArea = new Label("text", agreementText);
textArea.setEscapeModelStrings(false);

Form f2= new Form("f2");
f2.add(textArea);
}

 private String getAgreementText() {
getTextFromDataBase();
replace(#clientName, userModel.bind("user.name");
replace(#clientSurname, userModel.bind("user.surname");
}

So, as you can see, I cannot get text anywhere else, but DB, and have to
insert those values from first step to this text, but I get NullPointer
Exception, because wizard sets all values before rendering first step.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicket-wizard-init-tp4446076p4446076.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: wicket wizard init

Posted by Gytis <li...@mail.ru>.
So I created a method like:

private Component text(String pId){
Label text = new Label(pId){
@Override
protected void onConfigure() {
        			// TODO Auto-generated method stub
        			super.onConfigure();
        			
        			setDefaultModelObject(getAgreementText);
        		}
}

then in Step2 I made
add(text("user.text"));

and it Worked!
Thank you Andrea Del Bene-2 so much!!!



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicket-wizard-init-tp4446076p4456290.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: wicket wizard init

Posted by Andrea Del Bene <ad...@ciseonweb.it>.
I think exception is thrown because you call your getTextFromDataBase 
inside step's constructor, when 'user.name' and 'user.surname' are still 
empty. You could try moving getAgreementText() from constructor to 
another method like Component.onConfigure.

>
> Andrea Del Bene-3 wrote
>> Hi,
>>
>> which line of your code throws  NullPointerException? can you elaborate
>> a little more on the purpose of function getAgreementText() ?
>>
>   private String getTextFromDataBase() {
> agreementText = "AGREEMENT "
> 				+ ""
> 				+ "someText #clientName# #clientSurname#, someText"
> 				+ "someMoreAgreementText"
> 				+ "andMore"
> 				+ "End of Agreement"
> return agreementText;
>
> private String replace(String replace, String value){
>            agreementText= agreementText.replace(replace, value);
> return agreementText;
>
> NullPointerException occurs in the line, where program tries to replace
> #clientName# with userModel.bind("user.name").
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicket-wizard-init-tp4446076p4448935.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: wicket wizard init

Posted by Gytis <li...@mail.ru>.

Andrea Del Bene-3 wrote
> 
> Hi,
> 
> which line of your code throws  NullPointerException? can you elaborate 
> a little more on the purpose of function getAgreementText() ?
> 

 private String getTextFromDataBase() {
agreementText = "AGREEMENT "
				+ ""
				+ "someText #clientName# #clientSurname#, someText"
				+ "someMoreAgreementText"
				+ "andMore"
				+ "End of Agreement"
return agreementText;

private String replace(String replace, String value){
          agreementText= agreementText.replace(replace, value);
return agreementText;

NullPointerException occurs in the line, where program tries to replace
#clientName# with userModel.bind("user.name").

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicket-wizard-init-tp4446076p4448935.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: wicket wizard init

Posted by Andrea Del Bene <an...@gmail.com>.
Hi,

which line of your code throws  NullPointerException? can you elaborate 
a little more on the purpose of function getAgreementText() ?
> hello, I have such a problem
> I develop wizard in which user enters some values in first step fields, then
> I need to use those values in a second step in a text. looks like this:
>
> userModel = new CompoundPropertyModel<WizardPage>(this);
> setDefaultModel(userModel);
> WizardModel model = new WizardModel();
>
> model.add(new Step1());
> model.add(new Step2());
>
> init();
>
> Step1(){
> super("summary","title");
>
> TextField name = new TextField("user.name");
> TextField surname = new TextField("user.surname");
>
> Form f1 = new Form("f1");
> f1.add(name);
> f1.add(surname);
> }
>
> Step2(){
> super("summary2", "title2");
>
> agreementText = getAgreementText();
> Label textArea = new Label("text", agreementText);
> textArea.setEscapeModelStrings(false);
>
> Form f2= new Form("f2");
> f2.add(textArea);
> }
>
>   private String getAgreementText() {
> getTextFromDataBase();
> replace(#clientName, userModel.bind("user.name");
> replace(#clientSurname, userModel.bind("user.surname");
> }
>
> So, as you can see, I cannot get text anywhere else, but DB, and have to
> insert those values from first step to this text, but I get NullPointer
> Exception, because wizard sets all values before rendering first step.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicket-wizard-init-tp4446076p4446076.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