You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Adam Huječek (JIRA)" <ji...@apache.org> on 2015/01/28 12:56:35 UTC

[jira] [Created] (WICKET-5824) PropertyValidator sets "Required" flag too late in StatelessForm

Adam Huječek created WICKET-5824:
------------------------------------

             Summary: PropertyValidator sets "Required" flag too late in StatelessForm
                 Key: WICKET-5824
                 URL: https://issues.apache.org/jira/browse/WICKET-5824
             Project: Wicket
          Issue Type: Bug
          Components: wicket-bean-validation
    Affects Versions: 7.0.0-M4
         Environment: Windows 7, Wildfly 8.1.0
            Reporter: Adam Huječek
            Assignee: Igor Vaynberg
            Priority: Minor


I am writing a simple stateless form with validation based on annotations in Wicket 7.0.0-SNAPSHOT. When the model's field is annotated @NotNull and PropertyValidator is added to its form component, the validation error is not generated if user's input is empty. It seems to me that the "Required" flag is set too late, because while debugging I noticed that isRequired is called at least once before PropertyValidator's onConfigure. In the end the component has the flag set but without effect. As a workaround I have created descendants of CheckBox, TextArea and TextField with isRequired overriden as follows:
{code}
    @Override
    public boolean isRequired() {
        if (!isRequiredRecurse) {
            isRequiredRecurse = true;
            configure(); //this should let PropertyValidator call setRequired
            isRequiredRecurse = false;
        }
        return super.isRequired();
    }
{code}

Martin Grigorov kindly explained what is wrong here:
The problem comes from the fact that you use stateless form. The required flag is set for the form component on the rendered page, but later when the form is submitted a new page with a new form (and components) is created and the flag is gone.
Since there is no Behavior#onInitialize() we can only use #onBind() but as WICKET-5329 says at this time the parent may be not yet available and the logic breaks whenCompoundPropertyModel is used.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)