You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Sebastien Briquet (JIRA)" <ji...@apache.org> on 2014/12/18 13:53:13 UTC

[jira] [Commented] (WICKET-5790) VariableInterpolator & #getThrowExceptionOnMissingResource

    [ https://issues.apache.org/jira/browse/WICKET-5790?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14251610#comment-14251610 ] 

Sebastien Briquet commented on WICKET-5790:
-------------------------------------------

About point 2/ (variable patten not replaced). It seems to have been done intentionally in VariableInterpolator
https://github.com/apache/wicket/blob/master/wicket-util/src/main/java/org/apache/wicket/util/string/interpolator/VariableInterpolator.java#L163

But, as #substitute is private and there is no factory method for creating the VariableInterpolator, I think we can change in #substitute
https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java#L218

{code:java}
if (value == null)
{
	return null;
}
else if (value instanceof String)
{
	// small optimization - no need to bother with conversion
	// for String vars, e.g. {label}
	return (String)value;
}
{code}
by
{code:java}
if (value == null || value instanceof String)
{
	return String.valueOf(value);
}
{code}



> VariableInterpolator & #getThrowExceptionOnMissingResource
> ----------------------------------------------------------
>
>                 Key: WICKET-5790
>                 URL: https://issues.apache.org/jira/browse/WICKET-5790
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 6.18.0, 7.0.0-M4
>            Reporter: Sebastien Briquet
>         Attachments: WICKET-5790.zip
>
>
> This ticket is a 2 in 1 issue:
> h4. #getThrowExceptionOnMissingResource() is given as VariableInterpolator ctor arg.
> When you want to raise a validation error like:
> {code:java}
>             ValidationError error = new ValidationError();
>             error.addKey("MyComponent.ConversionError");
>             error.setVariable("myvar", myvalue);
>             this.error(error);
> {code}
> A call is made to FormComponent.MessageSource.substitute which returns {{new VariableInterpolator(...).toString()}}
> The second arg to VariableInterpolator is meant for "exceptionOnNullVarValue" but what is supplied in #substitute() is {{Application.get().getResourceSettings().getThrowExceptionOnMissingResource().}}
> That's where it looks strange because #getThrowExceptionOnMissingResource() represents a flag about missing resources (like _MyComponent.properties_) and has nothing related to null values in my understanding.
> h4. ${var} is not replaced in case of null value (and null is allowed)
> In the previous example, if *#getThrowExceptionOnMissingResource()* return *false* (meaning *exceptionOnNullVarValue* is *false*) and *myvalue* is *null*, the validation error message gives something of the form "value of myvar: ${myvar}" instead of "value of myvar: null".



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