Bug #2852
closedWFormModel issue / Wrong wording in widget gallery example
0%
Description
There is an issue related to your wording in the integration example (Wt Widget Gallery->Forms).
Using a FormModel and a View:
class MyModel : public Wt::WFormModel
{
public:
static constexpr Field Title_Field = "article-title";
//static const Field Title_Field;
};
Your example (http://www.webtoolkit.eu/widgets/forms/integration-example) says, it's totaly valid to use the c++11 approach. Well, I don't think so.
Try to set a model value from inside MyModel using "setValue(Title_Field,X)" and additionaly from the view via "model->setValue(MyModel::Title_Field,X)" and you end up with having 2 fields.
They are both named "article-title", but they are distinct, since you are using a "const char*" as Field-Type, which is itsel the key in your field map (https://github.com/kdeforche/wt/blob/master/src/Wt/WFormModel). Because "static constexpr Field" does not guarantee the pointers to be equal, this leads to nasty bugs.
I would prefer defining the Field as std::string, but at least you might want to correct (or place an explicit hint) on your integration example, that the C++11-approach does not work.
Updated by Koen Deforche over 10 years ago
- Status changed from New to InProgress
- Target version set to 3.3.3
Updated by Koen Deforche over 10 years ago
- Status changed from InProgress to Resolved
Hey,
It's unfortunate that the C++11 short-cut cannot be taken (since constexpr will not generate the unique storage needed for our purposes). I'm removing this comment.
But I would prefer to stick to the 'const char *' based Fields, simply because it avoids a lot of string comparisons while trying to look-up a particular field. Using a std::string just seems like a large price to pay for minimal developer comfort improvements. But I realize it's debatable. I'm also updating the documentation of WFormModel to point out this caveat.
Regards,
koen
Updated by Koen Deforche over 10 years ago
- Status changed from Resolved to Closed