Here is the description (JSF spec 1.1) for the getValue() of the ValueHolder
interface :
***********************************************************
First consult the local value property of this component. If non-null return
it. If the local value property is null, see if we have a ValueBinding for the
value property. If so, return the result of evaluating the property, otherwise
return null.
***********************************************************
So is it a bug of the spec?
During validation, null must be a valid local value.
Do you need a Jira patch?
Yannick
PS : the real patch (tested) is :
public Object getValue()
{
if (isLocalValueSet()) return getLocalValue();
ValueBinding vb = getValueBinding("value");
return vb != null ? (Object)vb.getValue(getFacesContext()) : null;
}
----- Message d'origine ----
De : Mike Kienenberger <[EMAIL PROTECTED]>
À : MyFaces Discussion <[email protected]>; Yannick Goujon <[EMAIL
PROTECTED]>
Envoyé le : Jeudi, 3 Août 2006, 3h57mn 07s
Objet : Re: Re : Validation process problem (UIInput)
On 8/3/06, Yannick Goujon <[EMAIL PROTECTED]> wrote:
> But during rendering phase, to display the relevant value in the html input,
> the renderer of the component get the value if the submitted value is null
>
> // code of the getValue method of the component
> public Object getValue()
> {
> if (_value != null) return _value;
> ValueBinding vb = getValueBinding("value");
> return vb != null ? (Object)vb.getValue(getFacesContext()) : null;
> }
>
> If value is null, the value is retrieved by means of the value binding,
> that's why the field of the form is filled by the value of the database
> instead of an empty string.
Yes, but _value is the local value. If it's not null, it's used
instead of using the backing bean value. So the real issue is that
this only happens if the local value is null and this is a valid local
value.
In theory, I agree with your proposed patch to UIInput's getValue().
In practice, we'll have to see if this is allowed by the JSF spec and the TCK.
You want to check the specs (probably the javadocs for the getValue
method in the 1.1 RI) and see what is required?
Then open a Jira issue on this and attach your patch below.
On 8/3/06, Yannick Goujon <[EMAIL PROTECTED]> wrote:
>
> I think this problem could be resolved by implementing the getValue() method
> in UIInput component as following (if the local value is set => return the
> value without using value binding) :
> public Object getValue()
> {
> if (isLocalValueSet()) return _value;
>
> ValueBinding vb = getValueBinding("value");
> return vb != null ? (Object)vb.getValue(getFacesContext()) : null;
> }
>
> What do you think about this modification of MyFaces implementation?
>
>
> ----- Message d'origine ----
> De : Yannick Goujon <[EMAIL PROTECTED]>
> À : [email protected]
> Envoyé le : Jeudi, 3 Août 2006, 11h00mn 30s
> Objet : Validation process problem (UIInput)
>
>
> Hello,
>
> I'm working on a web application using MyFaces 1.1.1 and I have a bug during
> validation process.
> I tried MyFaces 1.1.5 snapshot and I have the same problem.
>
> Here is my simple test case to reproduce the bug :
>
> Put only two fields in a form :
> - first has a number converter
> - second is required
> - values are managed by a bean (it gets the data from a database).
> In my example, value of field1 = 1 and value of field2 is null in database.
>
> JSP code :
> …
> <h:form id="form">
> <h:inputText id="field1" value="#{myBean.field1}">
> <f:convertNumber type="number"/>
> </h:inputText>
> <h:inputText id="field2" value="#{myBean.field2}" required="true"/>
> <h:commandLink id="commandLink" value="Validate"
> action="#{myBean.action}"/>
> </h:form>
> …
>
> 1) First time the page is rendered : field1=1 and field2 = null. When I
> validate the form, I have a message because field2 is required. In the html
> form, fields have the same values. That's Ok.
> 2) Now entered 'xxxxxxx' if field1 and validate. There are 2 messages
> (value of field1 is not a valid number and field2 is required). In the html
> form, field1= 'xxxxxxx' and field2 is empty. That's Ok
> 3) Now remove the value in field1 and validate. There is a message
> (field2 is required). In the html form, field1=1 and field2 is empty. That's
> not the attempted result. Why field1 is not empty ?
>
> There is a problem in the process validation (validate method) of the
> component UIInput
>
> // validate method of the UIInput
> public void validate(FacesContext context)
> {
> if (context == null) throw new NullPointerException("context");
> Object submittedValue = getSubmittedValue();
> if (submittedValue == null) return;
>
> Object convertedValue = getConvertedValue(context, submittedValue);
>
> if (!isValid()) return;
>
> validateValue(context, convertedValue);
>
> if (!isValid()) return;
>
> Object previousValue = getValue();
> setValue(convertedValue);
> setSubmittedValue(null);
> if (compareValues(previousValue, convertedValue))
> {
> queueEvent(new ValueChangeEvent(this, previousValue,
> convertedValue));
> }
> }
>
> In my test case 3), the submitted value of field1 is '' (empty string). The
> converter returns null without conversion error (that's OK). If you look in
> the validate method, the converted value (null) is set to the value of the
> component and submitted value is set to null.
>
> But during rendering phase, to display the relevant value in the html input,
> the renderer of the component get the value if the submitted value is null
>
> // code of the getValue method of the component
> public Object getValue()
> {
> if (_value != null) return _value;
> ValueBinding vb = getValueBinding("value");
> return vb != null ? (Object)vb.getValue(getFacesContext()) : null;
> }
>
> If value is null, the value is retrieved by means of the value binding,
> that's why the field of the form is filled by the value of the database
> instead of an empty string.
>
> Is it a known bug ? Any workaround ?
>
> Thanks.
>
> Yannick
>