You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by hese <10...@gmail.com> on 2010/11/09 17:29:12 UTC

form submit doesnt work when using an encoder

hi

I have a form in which I use a grid with an encoder.  Strangely when I
include the encoder attribute in the grid component onSubmit() or
onSuccessFrom...() dont get called.  When I remove the the encoder attribute
they are called.


Any ideas???

TML

 <form t:type="form" t:id="upload" t:context="id">
<t:errors/>
  <t:upload t:id="file" class="text medium" />
  <t:submit class="button" value="${message:button.make}" t:id="make" />
  <t:submit class="button" value="${message:button.upload}" t:id="save"/>

<table>
  <t:grid t:id="tags1" t:source="tagRows" t:row="tagRow"
t:encoder="tagRowEncoder" t:rowclass="prop:evenodd.next">
</t:grid>
</table>

</form>


JAVA

@Property
	private TagRowEncoder tagRowEncoder;

void onPrepare() {
		tagRowEncoder = new TagRowEncoder();
	}


private class TagRowEncoder implements ValueEncoder<TagRow> {

    	@Override
    	public String toClient(TagRow value) {
			Long key = value.getKey();
			return key.toString();
		}

    	@Override
		public TagRow toValue(String keyAsString) {
			long key = Common.toLong(keyAsString);
			for (TagRow holder : tagRows) {
				if (holder.getKey() == key) {
					return holder;
				}
			}
			throw new IllegalArgumentException("Received key \"" + key
					+ "\" which has no counterpart in this collection: " + tagRows);
		}
}
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/form-submit-doesnt-work-when-using-an-encoder-tp3257152p3257152.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: form submit doesnt work when using an encoder

Posted by hese <10...@gmail.com>.
Thanks Juan!  Looks like this could have been the problem.  Will try it and
let you know.
-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/form-submit-doesnt-work-when-using-an-encoder-tp3257152p3258966.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: form submit doesnt work when using an encoder

Posted by "Juan E. Maya" <ma...@gmail.com>.
The PREPARE event is executed when the form is render and when is
submitted as explained here:
http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/EventConstants.html#PREPARE


On Wed, Nov 10, 2010 at 4:59 PM, Juan E. Maya <ma...@gmail.com> wrote:
> SetupRender is only executed when the page is being render. Encoders
> are used during render and during submit so  you should use the
> PREPARE event of your form.
>
>
> On Wed, Nov 10, 2010 at 4:49 PM, hese <10...@gmail.com> wrote:
>>
>>
>> sorry, not sure I understand what you mean ... but I am initializing my
>> souce values in setupRender() like this -
>>
>> @Property
>> private List<TagRow> tagRows;
>>
>> void setupRender() {
>>        loadTags();
>> }
>>
>> should I be initializing it elsewhere?
>>
>> Actually, now I am doing it without the encoder (coz i cannot waste anymore
>> time with this) and it works.  but would still love to know what the problem
>> was.
>>
>>
>> --
>> View this message in context: http://tapestry.1045711.n5.nabble.com/form-submit-doesnt-work-when-using-an-encoder-tp3257152p3258889.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
>>
>>
>

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


Re: form submit doesnt work when using an encoder

Posted by "Juan E. Maya" <ma...@gmail.com>.
SetupRender is only executed when the page is being render. Encoders
are used during render and during submit so  you should use the
PREPARE event of your form.


On Wed, Nov 10, 2010 at 4:49 PM, hese <10...@gmail.com> wrote:
>
>
> sorry, not sure I understand what you mean ... but I am initializing my
> souce values in setupRender() like this -
>
> @Property
> private List<TagRow> tagRows;
>
> void setupRender() {
>        loadTags();
> }
>
> should I be initializing it elsewhere?
>
> Actually, now I am doing it without the encoder (coz i cannot waste anymore
> time with this) and it works.  but would still love to know what the problem
> was.
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/form-submit-doesnt-work-when-using-an-encoder-tp3257152p3258889.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
>
>

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


Re: form submit doesnt work when using an encoder

Posted by hese <10...@gmail.com>.

sorry, not sure I understand what you mean ... but I am initializing my
souce values in setupRender() like this -

@Property
private List<TagRow> tagRows;

void setupRender() {
    	loadTags();
}

should I be initializing it elsewhere?

Actually, now I am doing it without the encoder (coz i cannot waste anymore
time with this) and it works.  but would still love to know what the problem
was.


-- 
View this message in context: http://tapestry.1045711.n5.nabble.com/form-submit-doesnt-work-when-using-an-encoder-tp3257152p3258889.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: form submit doesnt work when using an encoder

Posted by Christophe Cordenier <ch...@gmail.com>.
Hi

How do you initialize your source values on submit ?


2010/11/9 hese <10...@gmail.com>

>
> hi
>
> I have a form in which I use a grid with an encoder.  Strangely when I
> include the encoder attribute in the grid component onSubmit() or
> onSuccessFrom...() dont get called.  When I remove the the encoder
> attribute
> they are called.
>
>
> Any ideas???
>
> TML
>
>  <form t:type="form" t:id="upload" t:context="id">
> <t:errors/>
>  <t:upload t:id="file" class="text medium" />
>  <t:submit class="button" value="${message:button.make}" t:id="make" />
>  <t:submit class="button" value="${message:button.upload}" t:id="save"/>
>
> <table>
>  <t:grid t:id="tags1" t:source="tagRows" t:row="tagRow"
> t:encoder="tagRowEncoder" t:rowclass="prop:evenodd.next">
> </t:grid>
> </table>
>
> </form>
>
>
> JAVA
>
> @Property
>        private TagRowEncoder tagRowEncoder;
>
> void onPrepare() {
>                tagRowEncoder = new TagRowEncoder();
>        }
>
>
> private class TagRowEncoder implements ValueEncoder<TagRow> {
>
>        @Override
>        public String toClient(TagRow value) {
>                        Long key = value.getKey();
>                        return key.toString();
>                }
>
>        @Override
>                public TagRow toValue(String keyAsString) {
>                        long key = Common.toLong(keyAsString);
>                        for (TagRow holder : tagRows) {
>                                if (holder.getKey() == key) {
>                                        return holder;
>                                }
>                        }
>                        throw new IllegalArgumentException("Received key \""
> + key
>                                        + "\" which has no counterpart in
> this collection: " + tagRows);
>                }
> }
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/form-submit-doesnt-work-when-using-an-encoder-tp3257152p3257152.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
>
>


-- 
Regards,
Christophe Cordenier.

Committer on Apache Tapestry 5
Co-creator of wooki @wookicentral.com