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;
    
    public Register(){
      
        NavomaticBorder navomaticBorder = new
NavomaticBorder("navigationBorder");      
        RegisterForm form = new RegisterForm("form");  
        navomaticBorder.add(form);
        add(navomaticBorder);
        
      // 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>
        
            <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>      
        
    </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{    
    @EJB
    NewSessionBeanLocal beanLocal;
    
    Person person = new Person();
    
    public RegisterForm(String id) {
        super(id);        
        CompoundPropertyModel model = new CompoundPropertyModel(person);
        this.setModel(model);
        
        this.add(new TextField("username"));
        this.add(new TextField("surname"));
    }
    
    @Override
    public void onSubmit() {
        Person p = (Person)this.getModelObject();
        System.out.println("TO: : : "+ p.getUsername()+ " "+
p.getSurname());  // shows right data
        
      //Person p = new Person();
      //p.setSurname("ABC");
     //p.setUsername("DEF");

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


 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