Hi Sokab,

I’m not an expert regarding EJB injection, but my first guess is that your


@EJB

NewSessionBeanLocal beanLocal


is null inside your form. Can you check this please?


If that is the case, it’s probably related to the way you have set up
injection. Can you share how you have configured the dependency injection?

Met vriendelijke groet,
Kind regards,

Bas Gooren

Op 28 maart 2017 bij 18:59:33, Sokab ([email protected]) schreef:

Hi Everyone. When I try save entity inside simple WebPage like this
everything is ok:

import com.example.entities.Person;
import javax.ejb.EJB;

public class Register extends WebPage{
@EJB
NewSessionBeanLocal beanLocal;
br/> public Register(){{
br/> NavomaticBorder navomaticBorder = new
NavomaticBorder("navigationBorder"); br/> ReggisterForm form = new
RegisterForm("form"); br/> naavomaticBorder.add(form);
add(navomaticBorder);
br/> // save entity to database for test <
Person person = new Person();
person.setSurname("ABC");
person.setUsername("DEF");

beanLocal.addPerson(person); // IT IS OK
}
}

//************************************************************************************************************************


Html Form:

<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
</head>
<body>
br/> <form wicket:id="form">
Username <input type="text" wicket:id="username"/>
Suername <input type="text" wicket:id="surname"/>
<input value="Save" name="save" type="submit" />
</form> br/> br/> </body> <
</html>

//************************************************************************************************************************


but when i try do this inside Form, becouse I want save entity after click
on Subimt button (register Person):

import com.example.Repository.NewSessionBeanLocal;
import com.example.entities.Person;
import javax.ejb.EJB;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.CompoundPropertyModel;

public class RegisterForm extends Form{ br/> @@EJB
NewSessionBeanLocal beanLocal;
br/> Person person = new Person();
br/> public RegisterFForm(String id) {
super(id); br/> CompoundPropertyModel mmodel = new
CompoundPropertyModel(person);
this.setModel(model);
br/> this.add(new TextFField("username"));
this.add(new TextField("surname"));
}
br/> @@Override
public void onSubmit() {
Person p = (Person)this.getModelObject();
System.out.println("TO: : : "+ p.getUsername()+ " "+
p.getSurname()); // shows right data
br/> //Person p = new Person();
//p.setSurname("ABC");
//p.setUsername("DEF");

beanLocal.addPerson(p); // <-- PROBLEM IS HERE
} br/> br/>}}


I have error:
Unexpected RuntimeException:

Last cause: null
WicketMessage: Method onFormSubmitted of interface
org.apache.wicket.markup.html.form.IFormSubmitListener targeted at
[RegisterForm [Component id = form]] on component [RegisterForm [Component
id = form]] threw an exception

Root cause:
java.lang.NullPointerException
at
com.example.navigationBefore.RegisterForm.onSubmit(RegisterForm.java:34)
(...)

Something I'm doing wrong? I Should not save entity inside onSubmit() Form
method? Thank you for any advice.

-- 
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/How-save-entity-after-clicking-on-submit-button-inside-Form-Wicket-class-tp4677474.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to