The NullPointerException is for role as: Root cause: wicket.util.convert.ConversionException: Can't convert value: Administrator to class: class
np.com.test.Role.......... (where Administrator is the role selected from drop down list).And my code snippet is as below. Model attached to ddc and textfields is CompoundPropertyModel public class UserAdd extends WebPage{ .... private Role r = new Role(); private List rList = null; private List roleList = new ArrayList(); private Role newRole = new Role(); ....... public userAdd() { CompoundPropertyModel userAddModel = new CompoundPropertyModel(user); Form form = new userAddForm("user",userAddModel); add(new FeedbackPanel("feedback")); add(form); TextField userNameComp = new TextField("username"); ......... .......... try{ rList = r.list(); Iterator it = rList.iterator(); while(it.hasNext()){ newRole = (Role)it.next(); roleList.add(newRole.getName()); } }catch(SQLException e){ ......... } DropDownChoice ddc = new DropDownChoice("role",roleList); form.add(userNameComp); form.add(ddc); class AdminAddForm extends Form { public AdminAddForm(String id,IModel model) { super(id,model); } @Override public void onSubmit() { Admin ad = (Admin)getModelObject(); try{ ad.add(); }catch(SQLException e){ String errMsg = e.getMessage(); error(errMsg); } info(getModelObjectAsString()); } } } Martijn Dashorst wrote: > > where does the TextField and the DDC store their values? I don't see > models > attached to them. > Read all about models here: Working with Wicket > models<http://cwiki.apache.org/WICKET/working-with-wicket-models.html> > > Martijn > > On Nov 21, 2007 6:37 AM, tsuresh <[EMAIL PROTECTED]> wrote: > >> >> I have two classes User and Role.User class has Role as one of its >> attributes >> and getRole() and setRole() methods. Role class >> >> has two attributes name and description. >> >> I have a form to add user with drop down choice which has list of role >> names. When I submit the form, I need to add this form >> >> value role name to user database. But at present it is showing null >> pointer >> exception. How do I convert this String value >> >> (role name ) to Role object. My code is as below. >> >> ........ >> ........ >> TextField userNameComp = new TextField("username"); >> ............ >> ........... >> .......... >> >> DropDownChoice ddc = new DropDownChoice("role",roleList); >> form.add(userNameComp); >> ........... >> ......... >> .......... >> form.add(ddc); >> } >> >> class userAddForm extends Form { >> public userAddForm(String id,IModel model) { >> super(id,model); >> } >> @Override >> public void onSubmit() { >> User ad = (User)getModelObject(); >> .......... >> ad.add(); // class User has add() method which adds the >> values of the UserAddForm to database >> ......... >> ......... >> } >> } >> } >> >> >> Please help. >> thanks >> -- >> View this message in context: >> http://www.nabble.com/Convert-String-to-desired-class-object-tf4848185.html#a13871390 >> Sent from the Wicket - User mailing list archive at Nabble.com. >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> > > > -- > Buy Wicket in Action: http://manning.com/dashorst > Apache Wicket 1.3.0-rc1 is released > Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-rc1/ > > -- View this message in context: http://www.nabble.com/Convert-String-to-desired-class-object-tf4848185.html#a13872885 Sent from the Wicket - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]