RE: Dynamic list of strings in a form

2008-05-02 Thread Blower, Andy
(Apologies - I sent the wrong tml file - please ignore my last email)

I've been trying to use FormInjector to create a dynamic form and not getting 
very far. I've taken the demo that Igor gave links to and simply taken it out 
of the border element. It works fine unless I add the t:label component in the 
block. It seems to me that as soon as there is more than one kind of component 
in the injected block, the inserted HTML is just "" without any form elements. Two textfields work, and 
a textfield and an 'any' component work, but not label or radio with a 
textfield. I suspect it's all form components.

Here's the modified demo. Remove the label component to see it working. Add 
back in to see it broken again. I think this might be connected with 
TAPESTRY-2322.

Am I doing something wrong here, or is it a bug?


http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>

Tapestry Integration Test Application #1








  






Add a row








Current sum: ${sum}  

public class FormInjectorDemo
{
@Persist
private double _sum;
private double _value;
@Inject
private Block _newRow;
@Inject
private PageRenderSupport _pageRenderSupport;
@Component
private FormInjector _formInjector;

public double getSum() {
return _sum;
}
public double getValue() {
return _value;
}
public void setValue(double value) {
_value = value;
}
void onPrepareForSubmit() {
_sum = 0;
}
void onAfterSubmit() {
_sum += _value;
}

void afterRender()
{
_pageRenderSupport.addScript(
"$('addnewrow').observe('click', function() { 
$('%s').trigger(); return false; });",
_formInjector.getClientId());
}

Object onActionFromFormInjector() {
return _newRow;
}
}


> -Original Message-
> From: Igor Drobiazko [mailto:[EMAIL PROTECTED]
> Sent: 15 April 2008 15:28
> To: Tapestry users
> Subject: Re: Dynamic list of strings in a form
>
> Ups, wrong template url. This one is the correct one:
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-
> core/src/test/app1/FormInjectorDemo.tml?view=markup
>
> On Tue, Apr 15, 2008 at 4:20 PM, Igor Drobiazko
> <[EMAIL PROTECTED]>
> wrote:
>
> > Have a look at the FormInjector component. This component is what you
> > need.
> > http://tapestry.apache.org/tapestry5/tapestry-
> core/ref/org/apache/tapestry/corelib/components/FormInjector.html
> >
> > An example can be found here:
> >
> > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-
> core/src/test/java/org/apache/tapestry/integration/app1/pages/FormInjec
> torDemo.java?view=markup
> >
> > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-
> core/src/test/app1/FormFragmentDemo.tml?view=markup
> >
> >
> >
> > On Tue, Apr 15, 2008 at 3:51 PM, Michael Dukaczewski <
> > [EMAIL PROTECTED]> wrote:
> >
> > > I am using Tapestry 5.0.11 and have a problem with a dynamic list
> of
> > > strings in a form. What I am trying, is the following:
> > >
> > > In the Page.java:
> > >
> > > @Persist
> > > private List items;
> > >
> > > @Property
> > > private String item;
> > >
> > > public List getItems() {
> > >if (items == null) {
> > >items = new LinkedList();
> > >}
> > >return items;
> > > }
> > >
> > > public void onSelectedFromAdd() {
> > >getItems().add("");
> > > }
> > >
> > > And in the Page.tml:
> > >
> > > 
> > >
> > >
> > >
> > >
> > >
> > > 
> > >
> > >
> > > I have a list of values, the user has to enter. The number of
> values,
> > > that have to be typed in, is dynamic, so the user has to extend the
> form.
> > > The add button works, but the values are not saved. Can someone
> tell me,
> > > that I am doing wrong?
> > >
> > >
> > > ---
> --
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> >
> > --
> > Best regards,
> >
> > Igor Drobiazko
>
>
>
>
> --
> Best regards,
>
> Igor Drobiazko

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Dynamic list of strings in a form

2008-05-02 Thread Blower, Andy
I've been trying to use FormInjector to create a dynamic form and not getting 
very far. I've taken the demo that Igor gave links to and simply taken it out 
of the border element. It works fine unless I add the t:label component in the 
block. It seems to me that as soon as there is more than one kind of component 
in the injected block, the inserted HTML is just "" without any form elements. Two textfields work, and 
a textfield and an 'any' component work, but not label or radio with a 
textfield. I suspect it's all form components.

Here's the modified demo. Remove the label component to see it working. Add 
back in to see it broken again. I think this might be connected with 
TAPESTRY-2322.

Am I doing something wrong here, or is it a bug?


http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>

Tapestry Integration Test Application #1















Add a row








Current sum: ${sum}



public class FormInjectorDemo
{
@Persist
private double _sum;
private double _value;
@Inject
private Block _newRow;
@Inject
private PageRenderSupport _pageRenderSupport;
@Component
private FormInjector _formInjector;

public double getSum() {
return _sum;
}
public double getValue() {
return _value;
}
public void setValue(double value) {
_value = value;
}
void onPrepareForSubmit() {
_sum = 0;
}
void onAfterSubmit() {
_sum += _value;
}

void afterRender()
{
_pageRenderSupport.addScript(
"$('addnewrow').observe('click', function() { 
$('%s').trigger(); return false; });",
_formInjector.getClientId());
}

Object onActionFromFormInjector() {
return _newRow;
}
}

> -Original Message-
> From: Igor Drobiazko [mailto:[EMAIL PROTECTED]
> Sent: 15 April 2008 15:28
> To: Tapestry users
> Subject: Re: Dynamic list of strings in a form
>
> Ups, wrong template url. This one is the correct one:
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-
> core/src/test/app1/FormInjectorDemo.tml?view=markup
>
> On Tue, Apr 15, 2008 at 4:20 PM, Igor Drobiazko
> <[EMAIL PROTECTED]>
> wrote:
>
> > Have a look at the FormInjector component. This component is what you
> > need.
> > http://tapestry.apache.org/tapestry5/tapestry-
> core/ref/org/apache/tapestry/corelib/components/FormInjector.html
> >
> > An example can be found here:
> >
> > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-
> core/src/test/java/org/apache/tapestry/integration/app1/pages/FormInjec
> torDemo.java?view=markup
> >
> > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-
> core/src/test/app1/FormFragmentDemo.tml?view=markup
> >
> >
> >
> > On Tue, Apr 15, 2008 at 3:51 PM, Michael Dukaczewski <
> > [EMAIL PROTECTED]> wrote:
> >
> > > I am using Tapestry 5.0.11 and have a problem with a dynamic list
> of
> > > strings in a form. What I am trying, is the following:
> > >
> > > In the Page.java:
> > >
> > > @Persist
> > > private List items;
> > >
> > > @Property
> > > private String item;
> > >
> > > public List getItems() {
> > >if (items == null) {
> > >items = new LinkedList();
> > >}
> > >return items;
> > > }
> > >
> > > public void onSelectedFromAdd() {
> > >getItems().add("");
> > > }
> > >
> > > And in the Page.tml:
> > >
> > > 
> > >
> > >
> > >
> > >
> > >
> > > 
> > >
> > >
> > > I have a list of values, the user has to enter. The number of
> values,
> > > that have to be typed in, is dynamic, so the user has to extend the
> form.
> > > The add button works, but the values are not saved. Can someone
> tell me,
> > > that I am doing wrong?
> > >
> > >
> > > ---
> --
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> >
> > --
> > Best regards,
> >
> > Igor Drobiazko
>
>
>
>
> --
> Best regards,
>
> Igor Drobiazko

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Dynamic list of strings in a form

2008-05-02 Thread Blower, Andy
I've not seen these demos before and although they look like integration tests, 
they also look really informative and very useful starting points for 
experimentation. There doesn't seem to be any release or package with them in 
and I can't figure out how to retrieve them en masse from the svn repository 
(probably don't have permissions anyway) so is there any way to get hold the 
source of these demo/test apps to learn and play around with? Obviously I could 
get a file at a time from the viewvc webpages.. but that would take a rather 
long (and boring) time.

> -Original Message-
> From: Igor Drobiazko [mailto:[EMAIL PROTECTED]
> Sent: 15 April 2008 15:28
> To: Tapestry users
> Subject: Re: Dynamic list of strings in a form
>
> Ups, wrong template url. This one is the correct one:
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-
> core/src/test/app1/FormInjectorDemo.tml?view=markup
>
> On Tue, Apr 15, 2008 at 4:20 PM, Igor Drobiazko
> <[EMAIL PROTECTED]>
> wrote:
>
> > Have a look at the FormInjector component. This component is what you
> > need.
> > http://tapestry.apache.org/tapestry5/tapestry-
> core/ref/org/apache/tapestry/corelib/components/FormInjector.html
> >
> > An example can be found here:
> >
> > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-
> core/src/test/java/org/apache/tapestry/integration/app1/pages/FormInjec
> torDemo.java?view=markup
> >
> > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-
> core/src/test/app1/FormFragmentDemo.tml?view=markup
> >
> >
> >
> > On Tue, Apr 15, 2008 at 3:51 PM, Michael Dukaczewski <
> > [EMAIL PROTECTED]> wrote:
> >
> > > I am using Tapestry 5.0.11 and have a problem with a dynamic list
> of
> > > strings in a form. What I am trying, is the following:
> > >
> > > In the Page.java:
> > >
> > > @Persist
> > > private List items;
> > >
> > > @Property
> > > private String item;
> > >
> > > public List getItems() {
> > >if (items == null) {
> > >items = new LinkedList();
> > >}
> > >return items;
> > > }
> > >
> > > public void onSelectedFromAdd() {
> > >getItems().add("");
> > > }
> > >
> > > And in the Page.tml:
> > >
> > > 
> > >
> > >
> > >
> > >
> > >
> > > 
> > >
> > >
> > > I have a list of values, the user has to enter. The number of
> values,
> > > that have to be typed in, is dynamic, so the user has to extend the
> form.
> > > The add button works, but the values are not saved. Can someone
> tell me,
> > > that I am doing wrong?
> > >
> > >
> > > ---
> --
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> >
> > --
> > Best regards,
> >
> > Igor Drobiazko
>
>
>
>
> --
> Best regards,
>
> Igor Drobiazko

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Dynamic list of strings in a form

2008-04-23 Thread Michael Dukaczewski
Thank you very much, that was exactly what I was looking for. I am new
to tapestry and it was not clear for me how loops are working, but now I
understand it.  :-)

Also many thanks to the other guys that replied.

@Marcus: Grid didn’t work for me, because I didn't have any Bean that I
could pass.

@Francois: Looks like a nice component and a generic solution for that
kind of problem. But I think it was bit overkill for me.

@Igor: FormInjector may work, if I always start with one input field.
But I also have to provide an edit form where already can be a set of
values. I am not sure how I could implement this using the FormInjector.

Regards,
Michael


Josh Canfield schrieb:
> Hey Michael,
> 
> I know a couple of guys have replied, but I think there is a much
> simpler answer to your problem.
> 
> drop the item property from your page and add getter/setters that
> update the your items list based on the index in the loop:
> 
> @Property
> private int _index;
> 
> public String getItem() {
>   if ( items.size() <= _index ) {
>   // what to do when the index is out of bounds?
>   }
>   return items.get(_index);
> }
>   
> public void setItem(String s) {
>   if ( items.size() <= _index ) {
>   // what to do when the index is out of bounds?
>   }
>   items.set(_index, s);
> }
> 
> 
> and update the loop div in your template to bind the index property:
> 
> 
> The way your page was written you were telling tapestry to update the
> item property for each value in the list, which it dutifully did. But,
> what you really wanted was it to put the items into your list.
> 
> Hope that helps,
> Josh
> 
> On Tue, Apr 15, 2008 at 6:51 AM, Michael Dukaczewski
> <[EMAIL PROTECTED]> wrote:
>> I am using Tapestry 5.0.11 and have a problem with a dynamic list of strings
>> in a form. What I am trying, is the following:
>>
>> In the Page.java:
>>
>> @Persist
>> private List items;
>>
>> @Property
>> private String item;
>>
>> public List getItems() {
>>if (items == null) {
>>items = new LinkedList();
>>}
>>return items;
>> }
>>
>> public void onSelectedFromAdd() {
>>getItems().add("");
>> }
>>
>> And in the Page.tml:
>>
>> 
>>
>>
>>
>>
>>
>> 
>>
>>
>> I have a list of values, the user has to enter. The number of values, that
>> have to be typed in, is dynamic, so the user has to extend the form.
>> The add button works, but the values are not saved. Can someone tell me,
>> that I am doing wrong?
>>
>>
>> -
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
> 
> 
> 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Dynamic list of strings in a form

2008-04-15 Thread Josh Canfield
Hey Michael,

I know a couple of guys have replied, but I think there is a much
simpler answer to your problem.

drop the item property from your page and add getter/setters that
update the your items list based on the index in the loop:

@Property
private int _index;

public String getItem() {
if ( items.size() <= _index ) {
// what to do when the index is out of bounds?
}
return items.get(_index);
}

public void setItem(String s) {
if ( items.size() <= _index ) {
// what to do when the index is out of bounds?
}
items.set(_index, s);
}


and update the loop div in your template to bind the index property:


The way your page was written you were telling tapestry to update the
item property for each value in the list, which it dutifully did. But,
what you really wanted was it to put the items into your list.

Hope that helps,
Josh

On Tue, Apr 15, 2008 at 6:51 AM, Michael Dukaczewski
<[EMAIL PROTECTED]> wrote:
> I am using Tapestry 5.0.11 and have a problem with a dynamic list of strings
> in a form. What I am trying, is the following:
>
> In the Page.java:
>
> @Persist
> private List items;
>
> @Property
> private String item;
>
> public List getItems() {
>if (items == null) {
>items = new LinkedList();
>}
>return items;
> }
>
> public void onSelectedFromAdd() {
>getItems().add("");
> }
>
> And in the Page.tml:
>
> 
>
>
>
>
>
> 
>
>
> I have a list of values, the user has to enter. The number of values, that
> have to be typed in, is dynamic, so the user has to extend the form.
> The add button works, but the values are not saved. Can someone tell me,
> that I am doing wrong?
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Dynamic list of strings in a form

2008-04-15 Thread Marcus
Hi Michael,

Try Grid component instead a Loop.

Marcus


Re: Dynamic list of strings in a form

2008-04-15 Thread Francois Armand

Michael Dukaczewski wrote:

[...]









I have a list of values, the user has to enter. The number of values, 
that have to be typed in, is dynamic, so the user has to extend the form.
The add button works, but the values are not saved. Can someone tell 
me, that I am doing wrong?


It can't work because after the loop is rendered, you don't have a 
conduit between list item and the textfield anymore.
You should look at what is done in the beaneditorn and just use it and 
provide your own "listmodel", which would be a special bean model where 
properties are the elements of the list.


Ok, I see that I'm really clear :) Here is an example of what I've done 
some time ago.
It is an hight level component that takes a list of "something" and 
create and form for it (all element of the list are editable thanks to 
the "something editor", an add button allow to add a blank element at 
the end of the list, and a delete button follow each field).
(Note : it was done in an old T5 version, and should take advantage of 
all the new nice features like Generics in components)

The java part:
http://sventon.ow2.vservers.linagora.com/svn/showfile.svn?path=/interldap-wui-common/trunk/src/main/java/org/interldap/wui/t5lib/components/ListEditor.java&revision=HEAD&name=interldap_ow2
And the matching template :
http://sventon.ow2.vservers.linagora.com/svn/showfile.svn?path=/interldap-wui-common/trunk/src/main/resources/org/interldap/wui/t5lib/components/ListEditor.tml&revision=HEAD&name=interldap_ow2

So, the part that you want to look at is the "ListObjectBeanModelSource" :
http://sventon.ow2.vservers.linagora.com/svn/showfile.svn?path=/interldap-wui-common/trunk/src/main/java/org/interldap/wui/t5lib/data/ListObjectBeanModelSource.java&revision=HEAD&name=interldap_ow2

Ok, an real life example that build a "composed search filter" (the like 
you have in thunderbird when you want to search email on multiple 
criteria) :


http://sventon.ow2.vservers.linagora.com/svn/showfile.svn?path=/interldap-wui-common/trunk/src/main/resources/org/interldap/wui/t5lib/components/search/SearchCriterionComposition.tml&revision=HEAD&name=interldap_ow2

Each criteria is an element in the list, there is an editor for 
criterium added in the know editor of bean editor, and that's all ! This 
simple component build the form for you.


There is a big drawback: this kind of feature should be made only client 
side, or almost. Here, each add/remove send a request to the server...


Hope it will help !

--
Francois Armand
Etudes & Développements J2EE
Groupe Linagora - http://www.linagora.com
Tél.: +33 (0)1 58 18 68 28
---
InterLDAP - http://interldap.org 
FederID - http://www.federid.org/

Open Source identities management and federation


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Dynamic list of strings in a form

2008-04-15 Thread Igor Drobiazko
Ups, wrong template url. This one is the correct one:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormInjectorDemo.tml?view=markup

On Tue, Apr 15, 2008 at 4:20 PM, Igor Drobiazko <[EMAIL PROTECTED]>
wrote:

> Have a look at the FormInjector component. This component is what you
> need.
> http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry/corelib/components/FormInjector.html
>
> An example can be found here:
>
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/FormInjectorDemo.java?view=markup
>
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFragmentDemo.tml?view=markup
>
>
>
> On Tue, Apr 15, 2008 at 3:51 PM, Michael Dukaczewski <
> [EMAIL PROTECTED]> wrote:
>
> > I am using Tapestry 5.0.11 and have a problem with a dynamic list of
> > strings in a form. What I am trying, is the following:
> >
> > In the Page.java:
> >
> > @Persist
> > private List items;
> >
> > @Property
> > private String item;
> >
> > public List getItems() {
> >if (items == null) {
> >items = new LinkedList();
> >}
> >return items;
> > }
> >
> > public void onSelectedFromAdd() {
> >getItems().add("");
> > }
> >
> > And in the Page.tml:
> >
> > 
> >
> >
> >
> >
> >
> > 
> >
> >
> > I have a list of values, the user has to enter. The number of values,
> > that have to be typed in, is dynamic, so the user has to extend the form.
> > The add button works, but the values are not saved. Can someone tell me,
> > that I am doing wrong?
> >
> >
> > -
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
> --
> Best regards,
>
> Igor Drobiazko




-- 
Best regards,

Igor Drobiazko


Re: Dynamic list of strings in a form

2008-04-15 Thread Igor Drobiazko
Have a look at the FormInjector component. This component is what you need.
http://tapestry.apache.org/tapestry5/tapestry-core/ref/org/apache/tapestry/corelib/components/FormInjector.html

An example can be found here:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/FormInjectorDemo.java?view=markup
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFragmentDemo.tml?view=markup


On Tue, Apr 15, 2008 at 3:51 PM, Michael Dukaczewski <[EMAIL PROTECTED]>
wrote:

> I am using Tapestry 5.0.11 and have a problem with a dynamic list of
> strings in a form. What I am trying, is the following:
>
> In the Page.java:
>
> @Persist
> private List items;
>
> @Property
> private String item;
>
> public List getItems() {
>if (items == null) {
>items = new LinkedList();
>}
>return items;
> }
>
> public void onSelectedFromAdd() {
>getItems().add("");
> }
>
> And in the Page.tml:
>
> 
>
>
>
>
>
> 
>
>
> I have a list of values, the user has to enter. The number of values, that
> have to be typed in, is dynamic, so the user has to extend the form.
> The add button works, but the values are not saved. Can someone tell me,
> that I am doing wrong?
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-- 
Best regards,

Igor Drobiazko