You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Muhammad Gelbana <m....@gmail.com> on 2013/02/11 22:51:50 UTC

[t5.3.6] Constructing Forms from Maps

I'm trying to construct tapestry form fields using the database. I'll
basically have a field label, key and other values in the database and I
need to use that to construct forms in tapestry.
I tried looking into the BeanEditor component but it looks like I'll be
making many workarounds since it's originally designed to deal with bean
types, not maps. Needless to say there are many methods I cannot figure out
if I need to implement them in a special way or not.

I was thinking of looping over my database records and like use a markup
writer to write the fields I need ? Is that easily possible ?

Thank you.

Re: [t5.3.6] Constructing Forms from Maps

Posted by Lance Java <la...@googlemail.com>.
Yeah, I changed mapprop: to map:

The demo (and source code) can be seen live here:
http://tapestry-stitch.uklance.cloudbees.net/mapbindingdemo



--
View this message in context: http://tapestry.1045711.n5.nabble.com/t5-3-6-Constructing-Forms-from-Maps-tp5719952p5720234.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [t5.3.6] Constructing Forms from Maps

Posted by Muhammad Gelbana <m....@gmail.com>.
The last 2 links aren't working. Here is a valid link for the last one
(MapPropBindingDemo.java)

https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/java/org/lazan/t5/stitch/demo/pages/MapBindingDemo.java

Thanks a lot for your help :)


On Sun, Feb 24, 2013 at 7:14 PM, Lance Java <la...@googlemail.com>wrote:

> FYI I've updated the tapestry-stitch-demo to validate the generic field.
>
> Some interesting files:
>
> https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/field/FieldSnapshot.java
>
> https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/resources/org/lazan/t5/stitch/demo/pages/MapPropBindingDemo.tml
>
> https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/java/org/lazan/t5/stitch/demo/pages/MapPropBindingDemo.java
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/t5-3-6-Constructing-Forms-from-Maps-tp5719952p5720190.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: [t5.3.6] Constructing Forms from Maps

Posted by Lance Java <la...@googlemail.com>.
FYI I've updated the tapestry-stitch-demo to validate the generic field.

Some interesting files:
https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/field/FieldSnapshot.java
https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/resources/org/lazan/t5/stitch/demo/pages/MapPropBindingDemo.tml
https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/java/org/lazan/t5/stitch/demo/pages/MapPropBindingDemo.java



--
View this message in context: http://tapestry.1045711.n5.nabble.com/t5-3-6-Constructing-Forms-from-Maps-tp5719952p5720190.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [t5.3.6] Constructing Forms from Maps

Posted by Lance Java <la...@googlemail.com>.
I'm on holiday at the moment so can't update the example, I'll update it when
I'm back. In the meantime this should help
tapestry.1045711.n5.nabble.com/how-to-recordError-against-a-form-field-in-a-loop-td5719832.html 



--
View this message in context: http://tapestry.1045711.n5.nabble.com/t5-3-6-Constructing-Forms-from-Maps-tp5719952p5720114.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [t5.3.6] Constructing Forms from Maps

Posted by Muhammad Gelbana <m....@gmail.com>.
So now I'm trying to apply this. First problem I'm facing now is validation
and ID assignment. I can get a component by It's ID from the
ComponentResources (i.e. I'm writing a component for this) service but how
can I identify the field to which a certain value is assigned ? Is it
possible for example to obtain the latest generated component ID ?

On Thu, Feb 14, 2013 at 8:00 PM, Muhammad Gelbana <m....@gmail.com>wrote:

> You've been so generous with your knowledgeable replies, thank you :)
>
>
> On Thu, Feb 14, 2013 at 7:41 PM, Lance Java <la...@googlemail.com>wrote:
>
>> I've just added a mapprop: binding prefix to tapestry-stitch. The binding
>> is
>> a two-way binding which can get() and put() to a map. I've created a demo
>> which generates dynamic textfields and updates a serverside map.
>> Expressions
>> are of the form "mapprop:mapexpression[keyexpression]" where mapexpression
>> and keyexpression are normal tapestry property expressions
>>
>> Demo:
>>
>> https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/resources/org/lazan/t5/stitch/demo/pages/MapPropBindingDemo.tml
>>
>> https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/java/org/lazan/t5/stitch/demo/pages/MapPropBindingDemo.java
>>
>> Source Code:
>>
>> https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/binding/MapPropBindingFactory.java
>>
>> https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/binding/MapPropBinding.java
>>
>> https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/services/StitchModule.java
>>
>> Enjoy!
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://tapestry.1045711.n5.nabble.com/t5-3-6-Constructing-Forms-from-Maps-tp5719952p5720034.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>

Re: [t5.3.6] Constructing Forms from Maps

Posted by Muhammad Gelbana <m....@gmail.com>.
You've been so generous with your knowledgeable replies, thank you :)

On Thu, Feb 14, 2013 at 7:41 PM, Lance Java <la...@googlemail.com>wrote:

> I've just added a mapprop: binding prefix to tapestry-stitch. The binding
> is
> a two-way binding which can get() and put() to a map. I've created a demo
> which generates dynamic textfields and updates a serverside map.
> Expressions
> are of the form "mapprop:mapexpression[keyexpression]" where mapexpression
> and keyexpression are normal tapestry property expressions
>
> Demo:
>
> https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/resources/org/lazan/t5/stitch/demo/pages/MapPropBindingDemo.tml
>
> https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/java/org/lazan/t5/stitch/demo/pages/MapPropBindingDemo.java
>
> Source Code:
>
> https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/binding/MapPropBindingFactory.java
>
> https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/binding/MapPropBinding.java
>
> https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/services/StitchModule.java
>
> Enjoy!
>
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/t5-3-6-Constructing-Forms-from-Maps-tp5719952p5720034.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: [t5.3.6] Constructing Forms from Maps

Posted by Lance Java <la...@googlemail.com>.
I've just added a mapprop: binding prefix to tapestry-stitch. The binding is
a two-way binding which can get() and put() to a map. I've created a demo
which generates dynamic textfields and updates a serverside map. Expressions
are of the form "mapprop:mapexpression[keyexpression]" where mapexpression
and keyexpression are normal tapestry property expressions

Demo:
https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/resources/org/lazan/t5/stitch/demo/pages/MapPropBindingDemo.tml
https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/java/org/lazan/t5/stitch/demo/pages/MapPropBindingDemo.java

Source Code:
https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/binding/MapPropBindingFactory.java
https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/binding/MapPropBinding.java
https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/services/StitchModule.java

Enjoy!




--
View this message in context: http://tapestry.1045711.n5.nabble.com/t5-3-6-Constructing-Forms-from-Maps-tp5719952p5720034.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [t5.3.6] Constructing Forms from Maps

Posted by Lance Java <la...@googlemail.com>.
> Well I don't think providing a custom binding factory is the solution since
the map keys will differ so the number of fields is unpredictable, it has to
be dynamic.

Your "map:" binding can be as complex as you like. You can parse your own
expressions:

eg:
<t:loop source="fieldNames" value="fieldName">
   <t:textfield value="map:someProp.someMap(fieldName)" />
</t:loop>



--
View this message in context: http://tapestry.1045711.n5.nabble.com/t5-3-6-Constructing-Forms-from-Maps-tp5719952p5720028.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [t5.3.6] Constructing Forms from Maps

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 12 Feb 2013 11:27:52 -0200, Muhammad Gelbana <m....@gmail.com>  
wrote:

> Based on your answer, I think providing a BeanModelImpl with an
> overridden PropertyConduitSource

You don't need to override it. You'll just need to implement  
PropertyConduit directly and use it. It's actually easy, specially for a  
Map.

-- 
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [t5.3.6] Constructing Forms from Maps

Posted by Muhammad Gelbana <m....@gmail.com>.
Thanks a lot for replying :)

Well I don't think providing a custom binding factory is the solution since
the map keys will differ so the number of fields is unpredictable, it has
to be dynamic.

Based on your answer, I think providing a BeanModelImpl with an
overridden PropertyConduitSource
is the solution but frankly I don't know what I need to do exactly. I find
the BeanModelImpl class complicated enough that I cannot comprehend all
it's aspects. I'll start from the PropertyConduitSource source and may be I
can accomplish something from there.

Hopefully someone with practical past experience can share his knowledge :)


On Tue, Feb 12, 2013 at 1:45 PM, Lance Java <la...@googlemail.com>wrote:

> Form fields have quite a complex relationship with their enclosing form, I
> wouldn't suggest writing to the MarkupWriter.
>
> BeanEditor and BeanEditForm require a BeanModel. Instead of implementing
> all
> of the methods in BeanModel, you can instantiate a BeanModelImpl and pass a
> custom PropertyConduitSource to it.
>
> Another option is to create a custom "map:" Binding/BindingFactory to get()
> and set() values in the underlying maps.
> eg <t:textfield value="map:myMap.someKey" />
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/t5-3-6-Constructing-Forms-from-Maps-tp5719952p5719971.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: [t5.3.6] Constructing Forms from Maps

Posted by Lance Java <la...@googlemail.com>.
Form fields have quite a complex relationship with their enclosing form, I
wouldn't suggest writing to the MarkupWriter.

BeanEditor and BeanEditForm require a BeanModel. Instead of implementing all
of the methods in BeanModel, you can instantiate a BeanModelImpl and pass a
custom PropertyConduitSource to it.

Another option is to create a custom "map:" Binding/BindingFactory to get()
and set() values in the underlying maps.
eg <t:textfield value="map:myMap.someKey" />



--
View this message in context: http://tapestry.1045711.n5.nabble.com/t5-3-6-Constructing-Forms-from-Maps-tp5719952p5719971.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org