I was following example tutorials how to integrate JSF, Spring, Hibernate in my web application:
http://www.journaldev.com/7122/jsf-spring-hibernate-integration-example-tutorial
http://www.journaldev.com/3531/spring-mvc-hibernate-mysql-integration-crud-example-tutorial
Everything til now works fine for me (insert and delete). Now, I would like to have that single form not only for inserting data into database, but use is also for editing, only without need for entering id field manually in html text field as it is shown in examples. Also, I would like to do this without seo path like edit/id (I want it like edit?id=1)
I see in the second link I posted here in my question, that there is controller class defined for that for that - PersonController.java (that example uses Spring MVC, I am using JSF like the first link tutorial is showing, but I think I need that controller)
In there it is defined:
@RequestMapping("/edit/{id}")
public String editPerson(@PathVariable("id") int id, Model model){
model.addAttribute("person", this.personService.getPersonById(id));
model.addAttribute("listPersons", this.personService.listPersons());
return "person";
}
But I do not nowhere see in the .java files or in .jsf/.xhtml files where that method editPerson was called? I know I should wrote it probably whit request mapping like this:
@RequestMapping(value = "/index.xhtml", method = RequestMethod.GET, params = { "id" })
I wrote that same method with that RequestMapping, but what to do now? Where must I call that method to populate my insert form with data when GET param called "id" is present in url? I want to make functionallity when GET param called id is present, then filled form with data (for that id in the database) will show; and after saving that filled form, update will occur in database, not insert. Insert should be occured when no id param is in the url (GET method). I hope I was clear enough.
Can someone show me on source code how to do it?