Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@NotNull for f:viewParam is not triggered when the parameter is missing in the query string #3343

Closed
ren-zhijun-oracle opened this issue Jul 16, 2014 · 13 comments

Comments

@ren-zhijun-oracle
Copy link
Contributor

@NotNull bean validation isn't being considered for <f:viewParam> whereas its own required="true" and a nested <f:validateRequired> (as per issue 3058) are correctly being considered.

I'd expect the @NotNull also being considered the same way.

Affected Versions

[2.2.7]

@ren-zhijun-oracle
Copy link
Contributor Author

@javaserverfaces Commented
Reported by @BalusC

@ren-zhijun-oracle
Copy link
Contributor Author

@javaserverfaces Commented
Issue-Links:
blocks
JAVASERVERFACES_SPEC_PUBLIC-1329

@ren-zhijun-oracle
Copy link
Contributor Author

@javaserverfaces Commented
@BalusC said:
The solution would be to explicitly set the value to an empty string if the submitted value is null. This also enables full utilization of standard UIInput validation without the need to copypaste parts from it (note that the currently copypasted implementation doesn't trigger PreValdiateEvent and PostValidateEvent at all)

So, instead of the current UIViewParam#processValidators() implementation as it is in Mojarra 2.2.7, starting at line number 259

if (getSubmittedValue() == null && myIsRequired()) {
            String requiredMessageStr = getRequiredMessage();
            FacesMessage message;
            if (null != requiredMessageStr) {
message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
           requiredMessageStr,
           requiredMessageStr);
            } else {
message =
     MessageFactory.getMessage(context, REQUIRED_MESSAGE_ID,
          MessageFactory.getLabel(
               context, this));
            }
            context.addMessage(getClientId(context), message);
            setValid(false);
            context.validationFailed();
            context.renderResponse();
        }
        else {
            super.processValidators(context);
        }

The current and all previous problems can be solved as follows, whereby the standard UIInput validation is fully utilized, including f:validateRequired and @NotNull:

if (getSubmittedValue() == null) {
            setSubmittedValue("");
        }

        super.processValidators(context);

The average developer would anyway already use javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL=true to prevent the model being polluted with empty string.

@ren-zhijun-oracle
Copy link
Contributor Author

@javaserverfaces Commented
@manfredriem said:
Hi Bauke,

Thank you for the writeup, I want to ask for a bit of clarification, what needs to happen when javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL is set to false?

Also can you roll up a minimal example for this and send it to issues@javaserverfaces.java.net?

Thanks!

@ren-zhijun-oracle
Copy link
Contributor Author

@javaserverfaces Commented
@BalusC said:

what needs to happen when javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL is set to false

Set submitted and local value back to null. You could do this after super.processValidators(context) call, only if the submitted value was originally null.

@ren-zhijun-oracle
Copy link
Contributor Author

@javaserverfaces Commented
@manfredriem said:
Can you also supply a reproducer? So we don't regress and we both know we are talking about the same thing. Thanks!

@ren-zhijun-oracle
Copy link
Contributor Author

@javaserverfaces Commented
@manfredriem said:
Lowering priority because of no response

1 similar comment
@ren-zhijun-oracle
Copy link
Contributor Author

@javaserverfaces Commented
@manfredriem said:
Lowering priority because of no response

@ren-zhijun-oracle
Copy link
Contributor Author

@javaserverfaces Commented
File: javaserverfaces-3339.tar.gz
Attached By: @manfredriem

@ren-zhijun-oracle
Copy link
Contributor Author

@javaserverfaces Commented
@manfredriem said:
Closing this as "Works as designed" as the change requires a specification change (the specification issue has been filed and linked so we will tackle the work there).

@ren-zhijun-oracle
Copy link
Contributor Author

@javaserverfaces Commented
Marked as works as designed on Tuesday, December 30th 2014, 7:38:53 am

@ren-zhijun-oracle
Copy link
Contributor Author

@javaserverfaces Commented
This issue was imported from java.net JIRA JAVASERVERFACES-3339

@ren-zhijun-oracle
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant