|
Wt
4.13.3
|
A model class to represent database objects. More...
#include <Wt/Form/Dbo/FormModel.h>
Public Member Functions | |
| FormModel (Wt::Dbo::Session &session, Wt::Dbo::ptr< C > ptr=nullptr) | |
| Constructor. | |
| void | addDboField (Wt::WFormModel::Field field) |
| Adds a Dbo column as a field. | |
| void | addDboFields (std::vector< Wt::WFormModel::Field > fields) |
| Adds a list of Dbo columns to the model. | |
| void | addAllDboColumnsAsFields (Wt::WFlags< FieldOptions > options=Wt::WFlags< FieldOptions >()) |
| Adds all Dbo columns to the model. | |
| void | initDboValues () |
| Initializes the model with values from the database. | |
| void | saveDboValues () |
| Saves the changes made in the model to the database. | |
| bool | validateField (Wt::WFormModel::Field field) override |
| Validates a field. | |
| Wt::Dbo::Session & | session () const |
| Returns the Session object used by this class. | |
| void | setItem (Wt::Dbo::ptr< C > ptr) |
| Sets the item of the model. | |
| const Wt::Dbo::ptr< C > & | item () const |
| Returns the database object used by this class. | |
| Signal & | itemChanged () |
| Signal emited when the item is changed. | |
Public Member Functions inherited from Wt::Form::Dbo::FormModelBase | |
| FormModelBase () | |
| Constructor. | |
| const std::vector< std::string > & | dboFields () const |
| Returns the Dbo columns used in this model. | |
Public Member Functions inherited from Wt::WFormModel | |
| WFormModel () | |
| Constructor. | |
| void | addField (Field field, const WString &info=WString::Empty) |
| Adds a field. | |
| void | removeField (Field field) |
| Removes a field. | |
| std::vector< Field > | fields () const |
| Returns the fields. | |
| virtual void | reset () |
| Resets the model. | |
| virtual bool | validate () |
| Validates the current input. | |
| bool | valid () const |
| Returns the current overall validation state. | |
| void | setVisible (Field field, bool visible) |
| Sets whether a field is visible. | |
| virtual bool | isVisible (Field field) const |
| Returns whether a field is visible. | |
| void | setReadOnly (Field field, bool readOnly) |
| Sets whether a field is read-only. | |
| virtual bool | isReadOnly (Field field) const |
| Returns whether a field is read only. | |
| virtual WString | label (Field field) const |
| Returns a field label. | |
| virtual void | setValue (Field field, const cpp17::any &value) |
| Sets the field value. | |
| virtual const cpp17::any & | value (Field field) const |
| Returns the field value. | |
| virtual WString | valueText (Field field) const |
| Returns the field value text. | |
| virtual void | setValidator (Field field, const std::shared_ptr< WValidator > &validator) |
| Sets a validator. | |
| virtual std::shared_ptr< WValidator > | validator (Field field) const |
| Returns a validator. | |
| virtual void | setValidated (Field field, bool validated) |
| Sets whether a field has been validated. | |
| virtual bool | isValidated (Field field) const |
| Returns whether the field has been validated yet. | |
| const WValidator::Result & | validation (Field field) const |
| Returns the result of a validation. | |
| virtual void | setValidation (Field field, const WValidator::Result &result) |
| Sets the validation result for a field. | |
Public Member Functions inherited from Wt::WObject | |
| void | addChild (std::unique_ptr< WObject > child) |
| Add a child WObject whose lifetime is determined by this WObject. | |
| template<typename Child > | |
| Child * | addChild (std::unique_ptr< Child > child) |
| Add a child WObject, returning a raw pointer. | |
| std::unique_ptr< WObject > | removeChild (WObject *child) |
| Remove a child WObject, so its lifetime is no longer determined by this WObject. | |
| template<typename Child > | |
| std::unique_ptr< Child > | removeChild (Child *child) |
| Remove a child WObject, so its lifetime is no longer determined by this WObject. | |
| virtual const std::string | id () const |
| Returns the (unique) identifier for this object. | |
| virtual void | setObjectName (const std::string &name) |
| Sets an object name. | |
| virtual std::string | objectName () const |
| Returns the object name. | |
| void | resetLearnedSlots () |
| Resets learned stateless slot implementations. | |
| template<class T > | |
| void | resetLearnedSlot (void(T::*method)()) |
| Resets a learned stateless slot implementation. | |
| template<class T > | |
| WStatelessSlot * | implementStateless (void(T::*method)()) |
| Declares a slot to be stateless and learn client-side behaviour on first invocation. | |
| template<class T > | |
| WStatelessSlot * | implementStateless (void(T::*method)(), void(T::*undoMethod)()) |
| Declares a slot to be stateless and learn client-side behaviour in advance. | |
| void | isNotStateless () |
| Marks the current function as not stateless. | |
| template<class T > | |
| WStatelessSlot * | implementJavaScript (void(T::*method)(), const std::string &jsCode) |
| Provides a JavaScript implementation for a method. | |
| virtual bool | resendFormData () |
| Returns whether the form data should be resent. | |
Public Member Functions inherited from Wt::Core::observable | |
| observable () noexcept | |
| Default constructor. | |
| virtual | ~observable () |
| Destructor. | |
| template<typename... Args, typename C > | |
| auto | bindSafe (void(C::*method)(Args...)) noexcept |
| Protects a method call against object destruction. | |
| template<typename... Args, typename C > | |
| auto | bindSafe (void(C::*method)(Args...) const) const noexcept |
| Protects a const method call against object destruction. | |
| template<typename Function > | |
| auto | bindSafe (const Function &function) noexcept |
| Protects a function against object destruction. | |
Additional Inherited Members | |
Public Types inherited from Wt::WFormModel | |
| typedef const char * | Field |
| A type to identify a field. | |
Public Types inherited from Wt::WObject | |
| typedef void(WObject::* | Method) () |
| Typedef for a WObject method without arguments. | |
Protected Member Functions inherited from Wt::Form::Dbo::FormModelBase | |
| void | insertDboField (Wt::WFormModel::Field field) |
| Adds a Dbo column as a field. | |
Protected Member Functions inherited from Wt::WObject | |
| virtual WStatelessSlot * | getStateless (Method method) |
| On-demand stateless slot implementation. | |
A model class to represent database objects.
This implements field data and validation handling for database form-based views.
The user needs to add all database columns to the model that they want to display in the view before initializing the model. During initialization the model will read the information from the database.
Initialization is performed by calling either initDboValues(), or setItem().
The model is a wrapper around the Dbo object, allowing it to be accessed, and edited. Destructing this model will "close" the connection to the database, no data will be removed.
|
explicit |
Constructor.
Creates a new form model
| void Wt::Form::Dbo::FormModel< C >::addAllDboColumnsAsFields | ( | Wt::WFlags< FieldOptions > | options = Wt::WFlags<FieldOptions>() | ) |
Adds all Dbo columns to the model.
Automatically adds all of the Dbo columns of the table as fields. Each field will have the same name as the Dbo column it holds the value for.
The options argument can be used to exclude foreign keys from being added as fields.
| WException | when the method is called after initDboValues() |
| void Wt::Form::Dbo::FormModel< C >::addDboField | ( | Wt::WFormModel< C >::Field | field | ) |
Adds a Dbo column as a field.
Adds the given field to the model. This field will hold the value of the Dbo column that has the same name.
| WException | when the method is called after initDboValues() |
| void Wt::Form::Dbo::FormModel< C >::addDboFields | ( | std::vector< Wt::WFormModel< C >::Field > | fields | ) |
Adds a list of Dbo columns to the model.
Adds the fields in the given list to the form. Each field will hold the value of the Dbo column that has the same name.
| WException | when the method is called after initDboValues() |
| void Wt::Form::Dbo::FormModel< C >::initDboValues | ( | ) |
Initializes the model with values from the database.
If an item is set, that item will be loaded into the model. This means that each field in the model will be populated with the corresponding value from the item. If no item is set, a new item with default values will be created and loaded into the model instead.
This method will not modify or lead to any modifications of the database. To save any modifications made to the item, or to save the newly created item, the saveDboValues() method must be called.
| const Wt::Dbo::ptr< C > & Wt::Form::Dbo::FormModel< C >::item | ( | ) | const |
Returns the database object used by this class.
| Signal & Wt::Form::Dbo::FormModel< C >::itemChanged | ( | ) |
| void Wt::Form::Dbo::FormModel< C >::saveDboValues | ( | ) |
Saves the changes made in the model to the database.
This method will save the changes made on the object in the database, creating a new entry if the object is new.
| void Wt::Form::Dbo::FormModel< C >::setItem | ( | Wt::Dbo::ptr< C > | ptr | ) |
Sets the item of the model.
Changes the item of the model. This will emit the itemChanged() signal, making the FormView update.
Setting the item to nullptr will result in a new item being constructed. This will load the default values of the item. The item remains transient (ptr::isTransient()), until it is saved, using saveDboValues() or FormView::save().