|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.click.control.AbstractControl
net.sf.click.control.AbstractContainer
net.sf.click.control.Form
net.sf.click.extras.hibernate.HibernateForm
Provides Hibernate data aware Form control: <form method='POST'>.
|
The HibernatteForm uses the thread local Session obtained via SessionContext.getSession() for all object for persistence operations. To use an alternative Session source override set the forms getSession() method.
The example below provides a User data object creation
and editing page. To edit an existing user object, the object is passed
to the page as a request parameter. Otherwise a new user object will
be created when saveChanges()
is called.
public class UserEdit extends Page { private HibernateForm form = new HibernateForm("form", User.class); public UserEdit() { form.add(new TextField("firstName"); form.add(new TextField("middleNames"); form.add(new TextField("FamilyName"); form.add(new Submit("ok", " OK ", this, "onOkClicked"); form.add(new Submit("cancel", this, "onCancelClicked"); form.setButtonAlign("right"); form.setLabelRequiredPrefix("<b>"); form.setLabelRequiredSuffix("</b>"); addControl(form); } public void setUser(User user) { form.setValueObject(user); } public boolean onOkClicked() { if (form.isValid()) { if (form.saveChanges()) { setRedirect("user-list.htm"); } } return true; } public boolean onCancelClicked() { setRedirect("user-list.htm"); return false; } }
SessionContext
,
SessionFilter
,
Serialized FormField Summary | |
protected HiddenField |
classField
The value object class name hidden field. |
protected static String |
FO_CLASS
The form value object classname parameter name. |
protected static String |
FO_ID
The form value object id parameter name. |
protected boolean |
metaDataApplied
The flag specifying that object validation meta data has been applied to the form fields. |
protected HiddenField |
oidField
The value object identifier hidden field. |
protected org.hibernate.Session |
session
The Hibernate session. |
protected org.hibernate.SessionFactory |
sessionFactory
The Hibernate session factory. |
Fields inherited from class net.sf.click.control.Form |
actionURL, ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, buttonAlign, buttonList, buttonStyle, columns, defaultFieldSize, disabled, enctype, error, errorsAlign, errorsPosition, errorsStyle, fieldList, fieldStyle, fieldWidths, FOCUS_JAVASCRIPT, FORM_NAME, HTML_IMPORTS, javaScriptValidation, labelAlign, labelsPosition, labelStyle, method, MULTIPART_FORM_DATA, POSITION_BOTTOM, POSITION_LEFT, POSITION_MIDDLE, POSITION_TOP, readonly, SUBMIT_CHECK, validate |
Fields inherited from class net.sf.click.control.AbstractContainer |
controlMap, controls |
Fields inherited from class net.sf.click.control.AbstractControl |
actionListener, attributes, listener, listenerMethod, messages, name, parent, styles |
Fields inherited from interface net.sf.click.Control |
CONTROL_MESSAGES |
Constructor Summary | |
HibernateForm(String name,
Class valueClass)
Create a new HibernateForm with the given form name and value object class. |
Method Summary | |
protected void |
applyMetaData()
Applies the ClassMetadata validation database meta data to the form fields. |
protected String |
getClassname(Class aClass)
Return the original classname for the given class removing any CGLib proxy information. |
org.hibernate.Session |
getSession()
Return the form Hibernate Session. |
org.hibernate.SessionFactory |
getSessionFactory()
Return the application Hibernate SessionFactory. |
Object |
getValueObject()
Return a Hibernate value object from the form with the form field values copied into the object's properties. |
boolean |
onProcess()
This method applies the object meta data to the form fields and then invokes the super.onProcess() method. |
void |
render(HtmlStringBuffer buffer)
Render the HTML representation of the HibernateForm. |
boolean |
saveChanges()
Save or update the object to the database and return true. |
void |
setSession(org.hibernate.Session session)
Set the user's Hibernate Session. |
void |
setSessionFactory(org.hibernate.SessionFactory sessionFactory)
Set the form Hibernate SessionFactory. |
void |
setValueObject(Object valueObject)
Set the given Hibernate value object in the form, copying the object's properties into the form field values. |
Methods inherited from class net.sf.click.control.AbstractContainer |
contains, getControl, getControlMap, getControls, hasControls, onInit, onRender, renderChildren, renderContent, renderTagEnd, toString |
Methods inherited from class net.sf.click.control.AbstractControl |
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getId, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasStyles, onDeploy, registerActionEvent, removeStyleClass, renderTagBegin, setActionListener, setAttribute, setId, setParent, setStyle |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface net.sf.click.Control |
getContext, getId, getMessages, getName, getParent, onDeploy, setParent |
Field Detail |
protected static final String FO_CLASS
protected static final String FO_ID
protected HiddenField classField
protected HiddenField oidField
protected org.hibernate.Session session
protected org.hibernate.SessionFactory sessionFactory
protected boolean metaDataApplied
Constructor Detail |
public HibernateForm(String name, Class valueClass)
name
- the form namevalueClass
- the value object classMethod Detail |
public org.hibernate.Session getSession()
SessionContext
.
Applications using alternative Hibernate Session sources should
set the form's session using the setSession(Session)
method.
public void setSession(org.hibernate.Session session)
session
- the user's Hibernate sessionpublic org.hibernate.SessionFactory getSessionFactory()
SessionContext
.
Applications using an alternative Hibernate SessionFactory
sources should set the form's session factory using the
setSessionFactory(SessionFactory)
method.
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
sessionFactory
- the Hibernate SessionFactorypublic Object getValueObject()
public void setValueObject(Object valueObject)
valueObject
- the Hibernate value object to setpublic boolean saveChanges() throws org.hibernate.HibernateException
If no object is added to the form using setValueObject() then this method will:
If an existing persistent object is added to the form using setValueObject() then this method will:
org.hibernate.HibernateException
- if a persistence error occuredpublic boolean onProcess()
Form.onProcess()
public void render(HtmlStringBuffer buffer)
This method applies the object meta data to the form fields and then invokes the super.toString() method.
buffer
- the specified buffer to render the control's output toAbstractContainer.toString()
protected void applyMetaData()
The field validation attributes include:
protected String getClassname(Class aClass)
aClass
- the class to obtain the original name from
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |