Customize validation message for fields generated dynamically

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Customize validation message for fields generated dynamically

mr nobody
This post was updated on .
Hi,

I have a component for generated fields dynamically, something similar to
the example bellow:

<div t:type="loop" t:source="params" value="currentParam" encoder="encoder"
t:formstate="ITERATION">
    <t:submitNotifier>
      <t:delegate to="activeBlock" />
    </t:submitNotifier>
  </div>

...

 <t:remove>
   
  </t:remove>
  <t:block t:id="text">
    <div class="form-group">
      <label class="col-sm-4 control-label">${label}</label>
      <t:if test="param.mandatory">
        <div class="col-sm-8">
          <input t:type="TextField" value="param.value"
t:validate="required"
            t:disabled="readonly" maxlength="${maxLength}" class="property
text" />
        </div>
        <p:else>
          <div class="col-sm-8">
            <input t:type="TextField" value="param.value"
t:disabled="readonly"
              maxlength="${maxLength}" class="property text" />
          </div>
        </p:else>
      </t:if>
    </div>
  </t:block>
  <t:remove>
   
  </t:remove>
  <t:block t:id="yesno">
    <div class="form-group">
      <label class="col-sm-4 control-label">${label}</label>
      <div class="col-sm-8">
        <t:Checkbox t:id="checkBox1" type="checkbox" value="param.value"
          t:disabled="readonly" class="property yesno" />
      </div>
    </div>
  </t:block>

and so on...

The messages (e.g. You must provide a value for Textfield.) are generated
by tapestry. When generating an error message for the validator, tapestry
will look for a message under a key, which is built from four parts,
separated by an hyphen.
1. id of the form which contains the field.
2. id of the field.
3. validator name.
4. the word message

I would like to customize the name of the field in the message according
with the value of the label, not according with the id because its value is
generated by the framework and i cannot generated it dynamically, as far as
I know.

Anyone knows how to deal with this problem?

Regards,

Robson Pires
Reply | Threaded
Open this post in threaded view
|

Re: Customize vadation message for fields generated dynamically

Dimitris Zenios
Hi

All tapestry fields support a label attribute as well

/**
 * The user presentable label for the field. If not provided, a
reasonable label is generated from the component's
 * id, first by looking for a message key named "id-label"
(substituting the component's actual id), then by
 * converting the actual id to a presentable string (for example,
"userId" to "User Id").
 */
@Parameter(defaultPrefix = BindingConstants.LITERAL)
protected String label;


Dimitris Zenios



On Wed, Dec 16, 2015 at 5:39 PM, Robson Pires <[hidden email]>
wrote:

> Hi,
>
> I have a component for generated fields dynamically, something similar to
> the example bellow:
>
> <div t:type="loop" t:source="params" value="currentParam" encoder="encoder"
> t:formstate="ITERATION">
>     <t:submitNotifier>
>       <t:delegate to="activeBlock" />
>     </t:submitNotifier>
>   </div>
>
> ...
>
>  <t:remove>
>     <!-- TEXT -->
>   </t:remove>
>   <t:block t:id="text">
>     <div class="form-group">
>       <label class="col-sm-4 control-label">${label}</label>
>       <t:if test="param.mandatory">
>         <div class="col-sm-8">
>           <input t:type="TextField" value="param.value"
> t:validate="required"
>             t:disabled="readonly" maxlength="${maxLength}" class="property
> text" />
>         </div>
>         <p:else>
>           <div class="col-sm-8">
>             <input t:type="TextField" value="param.value"
> t:disabled="readonly"
>               maxlength="${maxLength}" class="property text" />
>           </div>
>         </p:else>
>       </t:if>
>     </div>
>   </t:block>
>   <t:remove>
>     <!-- YES/NO -->
>   </t:remove>
>   <t:block t:id="yesno">
>     <div class="form-group">
>       <label class="col-sm-4 control-label">${label}</label>
>       <div class="col-sm-8">
>         <t:Checkbox t:id="checkBox1" type="checkbox" value="param.value"
>           t:disabled="readonly" class="property yesno" />
>       </div>
>     </div>
>   </t:block>
>
> and so on...
>
> The messages (e.g. You must provide a value for Textfield.) are generated
> by tapestry. When generating an error message for the validator, tapestry
> will look for a message under a key, which is built from four parts,
> separated by an hyphen.
> 1. id of the form which contains the field.
> 2. id of the field.
> 3. validator name.
> 4. the word message
>
> I would like to customize the name of the field in the message according
> with the value of the label, not according with the id because its value is
> generated by the framework and i cannot generated it dynamically, as far as
> I know.
>
> Anyone knows how to deal with this problem?
>
> Regards,
>
> Robson Pires
>