Wt: Wt::Form::Dbo::FormModel< C > Class Template Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | List of all members
Wt::Form::Dbo::FormModel< C > Class Template Reference
Dbo Forms (Wt::Form)

A model class to represent database objects. More...

`#include <Wt/Form/Dbo/FormModel.h>`

Inheritance diagram for Wt::Form::Dbo::FormModel< C >:
[legend]

## 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.
const Wt::Dbo::ptr< C > & | item () const
| Returns the database object used by this class.
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.
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.
Static Public Member Functions inherited from Wt::WObject
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.
Protected Attributes inherited from Wt::Form::Dbo::FormModelBase

## Detailed Description

template<class C>
class Wt::Form::Dbo::FormModel< C >

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.

See also
  FormView

## Constructor & Destructor Documentation

## ◆ FormModel()

template<class C >

Wt::Form::Dbo::FormModel< C >::FormModel | ( | Wt::Dbo::Session & | session,
|  | Wt::Dbo::ptr< C > | ptr = nullptr )
| explicit

Constructor.

Creates a new form model

## Member Function Documentation

## ◆ addAllDboColumnsAsFields()

template<class C >

void Wt::Form::Dbo::FormModel< C >::addAllDboColumnsAsFields | ( | Wt::WFlags< FieldOptions > | options = Wt::WFlags<FieldOptions>() | ) |

Adds all Dbo columns to the model.

Exceptions

  WException | when the method is called after initDboValues

## ◆ addDboField()

template<class C >

void Wt::Form::Dbo::FormModel< C >::addDboField | ( | Wt::WFormModel< C >::Field | field | ) |

Adds a Dbo column as a field.

Exceptions

  WException | when the method is called after initDboValues

## ◆ addDboFields()

template<class C >

void Wt::Form::Dbo::FormModel< C >::addDboFields | ( | std::vector< Wt::WFormModel< C >::Field > | fields | ) |

Adds a list of Dbo columns to the model.

Exceptions

  WException | when the method is called after initDboValues