Thread: [Cppcms-users] Custom form rendering and dynamic widgets
Brought to you by:
artyom-beilis
From: Julian P. <ju...@wh...> - 2010-08-30 01:58:30
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hallo, I've a question concerning the custom form rendering. My situation is, that I have a form which gets filled with widgets at runtime (by a JSON configuration), so that I don't know which widgets it will contain when it has to be rendered. So how can I iterate over the form's widgets in my template to do custom rendering? <% form input my_input %> won't work here as I don't know how many widgets there are. May I use a construct like <% foreach widget in form %> here? Thanks, Julian -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQIcBAEBAgAGBQJMexA6AAoJENidYKvYQHlQTbcP/2GHE41322Iow1xxjTk7MEbN oeproZQGjEwptgDQVkbTRKjUHiwrJuMjC45RFdeZP2h6G1FtXEmXs2mF4WJcliSg bsuKoQ/q4dRv758+BOLB34C1Hd9sfmq7PomjQYh45MFx6eUQqKG0CuVt6bjTGkaK Z0/RN7aCYfqwtOO5vJo8jjF+INqsldwkmE+EUHGcGdicfT+ZkgxP5JelgCSfPEG0 P7dMWejLxlGhWoW+9hvxzMVv3ZTD0xdiV3Q9LGJHp/BIBTAopwEf8rX7eQEY8mPv tT0Op380sx2PAlFij7OBrp8cUKFLsezhBNhfkX+leEcPY7AhkW9THawFFwwVKbMb 4Ka0wBr/G/gh05/7c0B8e+1vFnoKVUFypZ/qASV8fUqF6IrJlcWHHRzzrMWBhz0m i8GGg7FJ1Ri+FsYKuZmXmyZgJVVtWS+RYQDdvFzxGo95lZuRSEueWZ3BedOb8SaM DglBLw9xhpKuLIBLXcNQZmg1eBQRkObFaZNBko4tadCe/xI70/Fl9qiU0Nk2KSHi OM6zpTogcnHALN2WEH5+AKf8AqdS4t/GKaCE8Y5f+b6hVw+UENDcyoCsWCnXxLLc PTpFEO3yahSHTxegrA8T3xCgRuVx46eZ1y6V0CANMgyt7/qcNusrDQsQhnxFLrfH bg06GLl7rP9U9j+OLHZt =YAH1 -----END PGP SIGNATURE----- |
From: Artyom <art...@ya...> - 2010-08-30 04:15:25
|
> May I use a construct like > <% foreach widget in form %> here? Yes, you can. See: http://art-blog.no-ip.info/cppcms_ref_v0_99/classcppcms_1_1form.html it has forward iterator in it and thus you can iterate over the form. There is an example from src/hello_world_view1.tmpl <% foreach w as cppcms::form::iterator in form %> <% separator %><br/><% item %> <% if w.has_message() %><% w.message() %>:<% end %> <% form input w %> <% if not w.valid() %>:<% w.error_message() %><% end %> <% end %> <% end %> Artyom |
From: Julian P. <ju...@wh...> - 2010-08-30 23:52:32
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 30.08.2010 06:15, schrieb Artyom: >> May I use a construct like >> <% foreach widget in form %> here? > > Yes, you can. > > See: http://art-blog.no-ip.info/cppcms_ref_v0_99/classcppcms_1_1form.html > > it has forward iterator in it and thus you can iterate over the > form. > > There is an example from src/hello_world_view1.tmpl > > > <% foreach w as cppcms::form::iterator in form %> > <% separator %><br/><% item %> > <% if w.has_message() %><% w.message() %>:<% end %> > <% form input w %> > <% if not w.valid() %>:<% w.error_message() %><% end %> > <% end %> > <% end %> > > Artyom > > Ok, thanks for this example. But I still have a problem: Because even the forms on this page are dynamically allocated, they are stored in a vector, and because they are not copyable, I store a booster::shared_ptr to them instead. I loop with <% foreach form in forms %> But the problem is, that now the following construct <% foreach w as cppcms::form::iterator in form %> does not work, because the template generator expects form to be the object itself (and therefore generates form.begin() and form.end() instead of form->begin() and form->end() which would have to be used here). Is there a way around this apart of editing the generated template afterwards? Thanks, Julian -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQIcBAEBAgAGBQJMfEQ0AAoJENidYKvYQHlQOc8QAMrII619eMkDxv5mMdr341d9 mlqHIMpmJUPB5NwT1sqcoftHW3+6LkBVKSvx9VciOK8PnOaxZEEBW7K479RM943Q 9Pt1m2fBckJi7SQ0UGIaHqr/7rcpkkDNf6x8z/X8KYLWfYI0Jr7OYKKv1pSKTqYT cMepd64wvxxbpdZ1xN1Cw0frB82bTIsO9xek3ZkgDdIfMQ8/NzmLK/bz2/KdJf8c wSYT+3kZS7e4X7/84MgTsVwaLRnOpVyU5m2xzaZfWMeib/FbZWY1RsxMqEzTfaqW cplWPoEJV6zzfRIB7IVTfNd83fQTHu0X3gmnOSq6BnZufK7n5XLc2io2UMGlPWds oFlaJDqwKZL4Hvqd5zCp0e1RcK6m3rRd6+U/vyBZ+Z+Ye480Ubd5VlmdKAmOts8d APdwOJ21xHqj8sfzLAv84hbKDwwbXR54uF7DoqI5rKxwQkRry231wMORjjC1DsII tXQ/zrpT5iMZB8hFxlVIBq4rdQLg2Syfr+LM/6QZN5H9cvhSULlwP6/PMtyMljqe XglId5HmL6uQkjI5D4hagVz4ddqr6uiQAzy+0RGt/0WuE2sx0WR8zkee6hbsLAAx i6fgzuJ9AgDXJOHrfgCJKe1ulRoZjFjpKoRNQBt0aUH2L/LCmrUDdAQkDS+mOUOa vN71su/IIWaudH0/ISsB =hR8o -----END PGP SIGNATURE----- |
From: Artyom <art...@ya...> - 2010-08-31 04:27:52
|
> > Ok, thanks for this example. But I still have a problem: Because even > the forms on this page are dynamically allocated, they are stored in a > vector, and because they are not copyable, I store a booster::shared_ptr > to them instead. > I loop with > <% foreach form in forms %> > But the problem is, that now the following construct > <% foreach w as cppcms::form::iterator in form %> > does not work, because the template generator expects form to be the > object itself (and therefore generates form.begin() and form.end() > instead of form->begin() and form->end() which would have to be used > here). You can use: <% foreach w as cppcms::form::iterator in *form %> BTW `as foo` is required only for MSVC as gcc and intel have a construct typeof, so you can just use <% foreach w in *form %> Generally in every place where you use variable you can use "->", ".", "*" and single "()" operator. See: <http://art-blog.no-ip.info/wikipp/en/page/cppcms_1x_templates_gen#Syntax+Description+Rules> Artyom |
From: <ju...@ne...> - 2010-08-31 10:16:46
|
> You can use: > > <% foreach w as cppcms::form::iterator in *form %> > > BTW `as foo` is required only for MSVC as gcc and intel have > a construct typeof, so you can just use > > <% foreach w in *form %> > I tried that already, but gcc exits with the following errors (not different of the errors I get when I specify form instead of *form): stdconfig.tmpl: In member function virtual void stdconfig::stdconfig::get_content(): stdconfig.tmpl:11: error: class booster::shared_ptr<iweb2::content::StdConfigForm> has no member named begin stdconfig.tmpl:12: error: invalid type in declaration before = token stdconfig.tmpl:12: error: class booster::shared_ptr<iweb2::content::StdConfigForm> has no member named begin stdconfig.tmpl:12: error: class booster::shared_ptr<iweb2::content::StdConfigForm> has no member named end stdconfig.tmpl:11: error: invalid type argument of unary * stdconfig.tmpl:11: error: invalid type in declaration before = token stdconfig.tmpl:11: error: invalid type argument of unary * Any solution to this? Up to now, the only solution that worked was, to manually change any appearance of form.begin() and form.end() to form->begin() and form->end(). Thanks, Julian |
From: augustin <aug...@ov...> - 2010-08-31 04:27:54
|
Hello, On the topic of widget rendering, I think the rendering of each type of widget should be template-based. Currently, the default form rendering is hard-coded. I currently use the hack from src/hello_world_view1.tmpl that Artyom kindly indicated twice in recent weeks. I don't know what it would take to make it so that the default rendering for each form item is based on a template that can be overridden at the skin level, as well as at the form level. Maybe it's already possible. I haven't tested much yet. Augustin. -- Friends: http://www.reuniting.info/ http://activistsolutions.org/ My projects: http://astralcity.org/ http://3enjeux.overshoot.tv/ http://linux.overshoot.tv/ http://overshoot.tv/ http://charityware.info/ http://masquilier.org/ http://openteacher.info/ http://minguo.info/ http://www.wechange.org/ http://searching911.info/ . |
From: Artyom <art...@ya...> - 2010-08-31 06:23:13
|
> Hello, > > On the topic of widget rendering, I think the rendering of each type of widget > > should be template-based. > Currently, the default form rendering is hard-coded. > The hard coded options are only for some basic cases, for custom template rendering you can create your own template easily <% template my_form_render(cppcms::form &f) %> <% foreach w in f %> ... Do anything you like ... <% end %> <% end %> and then, instead of calling <% form as_p my_form %> you call <% include my_form_render(my_form) %> Artyom |
From: Julian P. <ju...@wh...> - 2010-08-31 09:59:36
|
> You can use: > > <% foreach w as cppcms::form::iterator in *form %> > > BTW `as foo` is required only for MSVC as gcc and intel have > a construct typeof, so you can just use > > <% foreach w in *form %> > I tried that already, but gcc exits with the following errors (not different of the errors I get when I specify form instead of *form): stdconfig.tmpl: In member function virtual void stdconfig::stdconfig::get_content(): stdconfig.tmpl:11: error: class booster::shared_ptr<iweb2::content::StdConfigForm> has no member named begin stdconfig.tmpl:12: error: invalid type in declaration before = token stdconfig.tmpl:12: error: class booster::shared_ptr<iweb2::content::StdConfigForm> has no member named begin stdconfig.tmpl:12: error: class booster::shared_ptr<iweb2::content::StdConfigForm> has no member named end stdconfig.tmpl:11: error: invalid type argument of unary * stdconfig.tmpl:11: error: invalid type in declaration before = token stdconfig.tmpl:11: error: invalid type argument of unary * Any solution to this? Up to now, the only solution that worked was, to manually change any appearance of form.begin() and form.end() to form->begin() and form->end(). Thanks, Julian |
From: Artyom <art...@ya...> - 2010-08-31 10:54:35
|
Hi, Ok, I see, you are right, this does not work as cppcms_tmpl_cc generates: *foo.bar.begin() When it should (*foo.bar).begin() Fixed in svn 1385, take latest revision. Artyom P.S.: Next time generated code sample that fails would be helpful ----- Original Message ---- > From: Julian Pietron <ju...@wh...> > To: cpp...@li... > Sent: Tue, August 31, 2010 1:01:25 PM > Subject: Re: [Cppcms-users] Custom form rendering and dynamic widgets > > > > You can use: > > > > <% foreach w as cppcms::form::iterator in *form %> > > > > BTW `as foo` is required only for MSVC as gcc and intel have > > a construct typeof, so you can just use > > > > <% foreach w in *form %> > > > > I tried that already, but gcc exits with the following errors (not > different of the errors I get when I specify form instead of *form): > > stdconfig.tmpl: In member function virtual void > stdconfig::stdconfig::get_content(): > stdconfig.tmpl:11: error: class > booster::shared_ptr<iweb2::content::StdConfigForm> has no member named > begin > stdconfig.tmpl:12: error: invalid type in declaration before = token > stdconfig.tmpl:12: error: class > booster::shared_ptr<iweb2::content::StdConfigForm> has no member named > begin > stdconfig.tmpl:12: error: class > booster::shared_ptr<iweb2::content::StdConfigForm> has no member named > end > stdconfig.tmpl:11: error: invalid type argument of unary * > stdconfig.tmpl:11: error: invalid type in declaration before = token > stdconfig.tmpl:11: error: invalid type argument of unary * > > Any solution to this? Up to now, the only solution that worked was, to > manually change any appearance of form.begin() and form.end() to > form->begin() and form->end(). > > Thanks, > Julian > > ------------------------------------------------------------------------------ > This SF.net Dev2Dev email is sponsored by: > > Show off your parallel programming skills. > Enter the Intel(R) Threading Challenge 2010. > http://p.sf.net/sfu/intel-thread-sfd > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |