You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Davide Vecchi <dv...@amc.dk> on 2015/04/30 15:53:18 UTC

Exception "Parameter 'translate' of component is bound to null" on a field that has no 'translate' attribute.

I have implemented a simple Translator for dates, but I am at a loss trying to understand why I get a RenderQueueException "Parameter 'translate' of component XXX is bound to null. This parameter is not allowed to be null" while actually the TextField component mentioned in that exception certainly does not have a "translate" parameter. Another TextField in the same form does though.

I can reproduce this and here is a stripped-down example, hoping maybe someone spots what's wrong.

Running this example as-is, there is no error and the text field which has the "translate" attribute does show the formatted date, as expected.

Just by uncommenting in the template the other text field, which does not have any "translate" attribute, there will be the exception saying that this field has a "translate" parameter and that it is bound to null.

Tapestry 5.3.7, Java 1.8.0_45, Windows 8.1

----------------------------------------- THIS IS THE TRANSLATOR : ---------------------------------------------

package test.tapestry.translators;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.tapestry5.Field;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.internal.translator.AbstractTranslator;
import org.apache.tapestry5.services.FormSupport;

public class DateTranslator extends AbstractTranslator<Date>
{

       public DateTranslator(String name)
       {
              super(name, Date.class, "date-translator-exception");
       }

       @Override
       public String toClient(Date value)
       {
              return new SimpleDateFormat("yyyy-MM-dd").format(value);
       }

       @Override
       public Date parseClient(Field field, String clientValue, String message) throws ValidationException
       {
              return new Date();// Doesn't matter, never called, there is no submit.
       }

       @Override
       public void render(Field field, String message, MarkupWriter writer, FormSupport formSupport) { }

}
------------------------------------------------------------

----------------------------------------- THIS IS THE TRANSLATOR CONTRIBUTION, FROM AppModule.java : ---------------------------------------------

public static void contributeTranslatorAlternatesSource(MappedConfiguration<String,
                     Translator<?>> configuration, ThreadLocale threadLocale)
       {
              configuration.add("dateTranslator", new DateTranslator("dateTranslator"));
       }

------------------------------------------------------------

----------------------------------------- THIS IS THE PAGE TEMPLATE (MyTest.tml) : ---------------------------------------------

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">

       <body>

              <form t:type="form" t:id="myForm">

                     <t:errors />

                     <div>
                           <label>Formatted date: </label>
                           <input t:type="TextField" t:id="myFormattedDateInputField" t:value="myFormattedDateInputFieldValue" t:translate="dateTranslator" />
                     </div>

                     <!--  UNCOMMENT THIS TO GET THE EXCEPTION.
                     <div>
                           <label>Raw date: </label>
                           <input t:type="TextField" t:id="myRawDateInputField" t:value="myRawDateInputFieldValue" />
                     </div>
                     -->

              </form>

       </body>

</html>

------------------------------------------------------------

----------------------------------------- THIS IS THE PAGE CODE (MyTest.java) : ---------------------------------------------

package test.tapestry.pages.test;

import java.util.Date;

public class MyTest {

       public Date getMyFormattedDateInputFieldValue()
       {
              return new Date();
       }

       public Date getMyRawDateInputFieldValue()
       {
              return new Date();
       }

}
------------------------------------------------------------

----------------------------------------- THIS IS THE EXCEPTION : ---------------------------------------------

org.apache.tapestry5.ioc.internal.util.TapestryException: Parameter 'translate' of component test/MyTest:myrawdateinputfield is bound to null. This parameter is not allowed to be null. [at classpath:test/tapestry/pages/test/MyTest.tml, line 17]
       at org.apache.tapestry5.internal.transform.ParameterWorker$3$1.readFromBinding(ParameterWorker.java:275)
       at org.apache.tapestry5.internal.transform.ParameterWorker$3$1.get(ParameterWorker.java:381)
       at org.apache.tapestry5.corelib.base.AbstractTextField.conduit_get_translate(AbstractTextField.java)
       at org.apache.tapestry5.corelib.base.AbstractTextField.begin(AbstractTextField.java:159)
       at org.apache.tapestry5.corelib.base.AbstractTextField.beginRender(AbstractTextField.java)
       at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$BeginRenderPhase.invokeComponent(ComponentPageElementImpl.java:207)
       at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$AbstractPhase.invoke(ComponentPageElementImpl.java:148)
       at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$BeginRenderPhase.render(ComponentPageElementImpl.java:214)
       at org.apache.tapestry5.internal.services.RenderQueueImpl.run(RenderQueueImpl.java:72)
       at org.apache.tapestry5.internal.services.PageRenderQueueImpl.render(PageRenderQueueImpl.java:124)
       at $PageRenderQueue_14c5fa8ebe19.render(Unknown Source)
       at $PageRenderQueue_14c5fa8ebe18.render(Unknown Source)
       at org.apache.tapestry5.internal.services.MarkupRendererTerminator.renderMarkup(MarkupRendererTerminator.java:37)
       at org.got5.tapestry5.jquery.services.js.JSModule$1.renderMarkup(JSModule.java:40)
       at $MarkupRenderer_14c5fa8ebe1d.renderMarkup(Unknown Source)
       at org.oscy.tapestry.breadcrumbs.services.BreadCrumbsModule$2.renderMarkup(BreadCrumbsModule.java:68)
       at $MarkupRenderer_14c5fa8ebe1d.renderMarkup(Unknown Source)
       at org.apache.tapestry5.services.TapestryModule$31.renderMarkup(TapestryModule.java:1994)
       at $MarkupRenderer_14c5fa8ebe1d.renderMarkup(Unknown Source)
       at org.apache.tapestry5.services.TapestryModule$30.renderMarkup(TapestryModule.java:1978)
       at $MarkupRenderer_14c5fa8ebe1d.renderMarkup(Unknown Source)
       at org.apache.tapestry5.services.TapestryModule$29.renderMarkup(TapestryModule.java:1960)
       at $MarkupRenderer_14c5fa8ebe1d.renderMarkup(Unknown Source)
       at org.apache.tapestry5.services.TapestryModule$28.renderMarkup(TapestryModule.java:1945)
       at $MarkupRenderer_14c5fa8ebe1d.renderMarkup(Unknown Source)
       at org.apache.tapestry5.services.TapestryModule$27.renderMarkup(TapestryModule.java:1931)
       at $MarkupRenderer_14c5fa8ebe1d.renderMarkup(Unknown Source)
       at org.apache.tapestry5.services.TapestryModule$26.renderMarkup(TapestryModule.java:1913)
       at $MarkupRenderer_14c5fa8ebe1d.renderMarkup(Unknown Source)
       at org.apache.tapestry5.services.TapestryModule$25.renderMarkup(TapestryModule.java:1894)
       at $MarkupRenderer_14c5fa8ebe1d.renderMarkup(Unknown Source)
       at $MarkupRenderer_14c5fa8ebe17.renderMarkup(Unknown Source)
       at org.apache.tapestry5.internal.services.PageMarkupRendererImpl.renderPageMarkup(PageMarkupRendererImpl.java:47)
       at $PageMarkupRenderer_14c5fa8ebe15.renderPageMarkup(Unknown Source)
       at org.apache.tapestry5.internal.services.PageResponseRendererImpl.renderPageResponse(PageResponseRendererImpl.java:67)
       at $PageResponseRenderer_14c5fa8ebd23.renderPageResponse(Unknown Source)
       at org.apache.tapestry5.internal.services.PageRenderRequestHandlerImpl.handle(PageRenderRequestHandlerImpl.java:64)
       at org.oscy.tapestry.breadcrumbs.services.BreadCrumbsModule$1.handle(BreadCrumbsModule.java:54)
       at $PageRenderRequestHandler_14c5fa8ebd25.handle(Unknown Source)
       at org.apache.tapestry5.services.TapestryModule$38.handle(TapestryModule.java:2222)
       at $PageRenderRequestHandler_14c5fa8ebd25.handle(Unknown Source)
       at $PageRenderRequestHandler_14c5fa8ebd1b.handle(Unknown Source)
       ....
       ...
------------------------------------------------------------




RE: Exception "Parameter 'translate' of component is bound to null" on a field that has no 'translate' attribute.

Posted by Davide Vecchi <dv...@amc.dk>.
Great, thanks, that solves my problem.

My confusion was that I had not realized that I would get the same exception even without contributing or referencing any translator, because I was binding my TextField to a Date and not to a String so a translator was needed in any case.



My goal is that only TextFields having the t:translate="dateTranslator"  attribute in the tml get translated, and TextFields that don’t have such attribute should keep behaving as they did before (in this case throw an exception if I bind that field to a Date). So I will keep contributing my translator by name to TranslatorAlternativesSource and use t:translate in the tml; then if I want a TextField to show a “non-translated” date I will not give that field the t:translate attribute and I will bind that field to a String instead of a Date, and I will provide a String representation of my Date as the field’s value instead of providing the Date itself.





-----Original Message-----
From: Thiago H de Paula Figueiredo [mailto:thiagohp@gmail.com]
Sent: Thursday, April 30, 2015 22:52
To: Tapestry users
Subject: Re: Exception "Parameter 'translate' of component is bound to null" on a field that has no 'translate' attribute.



On Thu, 30 Apr 2015 12:58:23 -0300, Lance Java <la...@googlemail.com>>

wrote:



> If you want tapestry to use your translator as the default for all

> dates you should contribute to TranslatorSource using a class (instead

> of contributing by name to TranslatorAlternativesSource).

>

> Otherwise, you could annotate individual date fields with

> @Translate("dateTranslator") and leave your code as is.



Exactly. TextField needs a translator to convert between the edited property type and String and vice-versa. Tapestry provides translators for numeric types and String itself. In your case, you're editing a Date, so you need to provide a translator for Date through TranslatorSource or the translate parameter explicitly.



--

Thiago H. de Paula Figueiredo

Tapestry, Java and Hibernate consultant and developer http://machina.com.br



---------------------------------------------------------------------

To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org<ma...@tapestry.apache.org>

For additional commands, e-mail: users-help@tapestry.apache.org<ma...@tapestry.apache.org>



Re: Exception "Parameter 'translate' of component is bound to null" on a field that has no 'translate' attribute.

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 30 Apr 2015 12:58:23 -0300, Lance Java <la...@googlemail.com>  
wrote:

> If you want tapestry to use your translator as the default for all dates
> you should contribute to TranslatorSource using a class (instead of
> contributing by name to TranslatorAlternativesSource).
>
> Otherwise, you could annotate individual date fields with
> @Translate("dateTranslator") and leave your code as is.

Exactly. TextField needs a translator to convert between the edited  
property type and String and vice-versa. Tapestry provides translators for  
numeric types and String itself. In your case, you're editing a Date, so  
you need to provide a translator for Date through TranslatorSource or the  
translate parameter explicitly.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


Re: Exception "Parameter 'translate' of component is bound to null" on a field that has no 'translate' attribute.

Posted by Lance Java <la...@googlemail.com>.
If you want tapestry to use your translator as the default for all dates
you should contribute to TranslatorSource using a class (instead of
contributing by name to TranslatorAlternativesSource).

Otherwise, you could annotate individual date fields with
@Translate("dateTranslator") and leave your code as is.