Reputation: 1679
I have a page with a form, which uses @Persist fields for the form controls (text boxes, radio buttons, etc), so that if the form is submitted the data is retained in the form if custom validation fails.
From the docs, "Fields marked with @Persist may not have default values (whether set inline, or inside a constructor)". However, I need to set default values for some form elements (including some @Validate("required") select boxes).
What is the method to achieve this?
Thanks
Upvotes: 1
Views: 1529
Reputation: 3893
First off I don't think you need to @persist your form values, as tapestry will keep them across your validation failed submit. If you so want to set default values you could do so in the @SetupRender like:
@Porperty
@Persist
private String myValue;
@SetupRender
private void setup() {
if(myValue == null) {
myValue = "defaultVal";
}
}
Or you could do it in a null check getter (which is a useful thing when using events as @SetupRender is not called there):
@Persist
private String myValue;
public String getMyValue() {
if(myValue == null) {
myValue = "defaultVal";
}
return myValue;
}
Upvotes: 5