Hi all, I have been reading up on this forum for a while, but now have a question I cannot find the answer for here. I might be searching wrong, so if someone has a thread recommendation, please post it.
I am new to java really. I have a simple timesheet application that uses a derby db, struts and hibernate and adds fields userCn, userName, firstName,lastName... etc... I am trying to use a JSP page to populate the data with a new user. I have a method called lookup:
...that takes data from a jsp input form and loads a new page with the persons CN. I have been trying to create a page that adds a new user with a method called create() that looks like this:
I feel like I should be using set instead of get in there... but set won't work without errors. I am confused on how this works. How come I can get data from my form no problem with the lookup, but cannot add it?
First principles: if you are coupling your form to the model code, your coupling is too close. Your data layer should have no knowledge of the front end -- and that includes the whole concept of a form. Rather, in the controller layer you should be populating an entity class with the information from the form and passing that to the model layer.
In any case, it sounds like you are passing a form to your model layer. Is this the case? If so, it's a violation of the principles of Separation of Concerns that govern the MVC pattern. The model should be completely agnostic of the controller and presentation layers.
If you haven't read then yet, I always suggest JSP writers read these articles:
I didn't say anything about removing create(), just that I'm not a fan of the the style where you have to set the user before calling create(), rather than just passing the user to the create() method directly.
In any case, this really isn't about JSP, so I've moved it to the ORM forum.
I'm not sure what book and patterns you are following but this isn't similar to anything I've actually seen in use.