Reputation: 1919
I am starting a new project using Tapestry 5.x. To get confortable with it I am doing a few expermiment.
For now I am looking for a way to add a little star as the fist element of the label of every field of a form with a "required" constraint of the rendered entity.
For example
public class Address
{
@Validate("required")
public String lastName;
}
Rendered with
<t:beaneditform object="addr" submitlabel="message:submit-label" />
Should render a html like
<div>
<label><span>*</span> First name : </label>
<input type="text" name="firstname" />
</div>
I currently have a code base really close to the one described in the official documentation.
But sadly I haven't found a generic way to implement what I want.
Does any have an advice for me on this one ?
Upvotes: 0
Views: 173
Reputation: 27994
You could do this with a Label mixin. The mixin would use the following to get a reference to the label's field
parameter.
@BindParameter
private Field field;
You could then test for field.isRequired()
in you mixin and tweak the html. More info in mixins here
Once your mixin is working, you could then attach it to every label (even the ones inside BeanEditForm) using a ComponentClassTransformWorker2 as detailed in the blog post here.
Upvotes: 1