I’m very new to JSF and Hibernate, I found some tutorials and I understood almost everything but there is something very simple I didn’t understand yet and I can`t realize by myself how to do it;
1.This is my html page
<h:panelGrid columns="2">
<h:outputLabel value="Title:"/>
<h:inputText value='#{Activity.title}' />
</h:panelGrid>
2.This is my save method at activityController
public void saveActivity(String title){
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = null;
try {
transaction = session.beginTransaction();
Activity activity = new Activity(title);
session.save(activity);
transaction.commit();
} catch (HibernateException e) {
transaction.rollback();
}finally{
session.close();
}
}
My doubt is: How do I get what my user types at the OutputText in the HTML page and send it to my saveActivity method?
You need a Form and an Submit Button:
Then, either make your Controller a Managed Bean with Annotation @SessionScoped
@ManagedBean(name = “activityBean”) or use a Class for it and give it a reference to your Controller.
Good Luck 🙂