myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rolf Kulemann (JIRA)" <myfaces-...@incubator.apache.org>
Subject [jira] Commented: (MYFACES-228) Sortheader functionality does not work if datatable contains editable components
Date Wed, 04 May 2005 19:59:11 GMT
     [ http://issues.apache.org/jira/browse/MYFACES-228?page=comments#action_64507 ]
     
Rolf Kulemann commented on MYFACES-228:
---------------------------------------

I guess I found the offending code. But before I attach a patch, I would like to discuss the
problem based on code a bit more, because there are some things I do not understand.

The offendning class is http://svn.apache.org/viewcvs.cgi/myfaces/trunk/src/share/org/apache/myfaces/renderkit/RendererUtils.java?rev=167744&view=markup

If you look at the methods getStringValue, getDateValue, and getBooleanValue, the problem/bug
is obvious. Lets look at getStringValue for example:
------------------------------------------------
public static String getStringValue(FacesContext facesContext,
                                        UIComponent component)
    {
        try
        {
            if (!(component instanceof ValueHolder))
            {
                throw new IllegalArgumentException("Component : "+getPathToComponent(component)+"is
not a ValueHolder");
            }

            if (component instanceof EditableValueHolder)
            {
                Object submittedValue = ((EditableValueHolder)component).getSubmittedValue();
                if (submittedValue != null)
                {
                    if (submittedValue instanceof String)
                    {
                        return (String)submittedValue;
                    }
                    else
                    {
                        throw new IllegalArgumentException("Expected submitted value of type
String for component : "
                            +getPathToComponent(component));
                    }
                }
            }

            Object value = ((ValueHolder)component).getValue();

            ....
            return value.toString();
------------------------------------------------

As soon as an EditableValueHolder should be rendered, the submmited value is rendered and
not the value backed by the underlying model. In case of the sortheader action, this is wrong,
since the old unsorted model will be rendered.

I guess there is a good reason why the submitted value is rendered, BUT I can not understand
why such a distiction is made in the render process, since IMHO only values from the model
should be redndered. I have commented out the hole section 
-------------------------------------------------
/*if (component instanceof EditableValueHolder)
            {
                Object submittedValue = ((EditableValueHolder)component).getSubmittedValue();
                if (submittedValue != null)
                {
                    if (submittedValue instanceof String)
                    {
                        return (String)submittedValue;
                    }
                    else
                    {
                        throw new IllegalArgumentException("Expected submitted value of type
String for component : "
                            +getPathToComponent(component));
                    }
                }
            }*/
-------------------------------------------------

and sorting works just fine. Dunno what side effects this would cause. So what is the reason
for this check? Again, only values from the model should be rendered, but I guess there is
a reason, why you render the submitted values of EditableValueHolders and not the values backed
by the model.

Answers?


> Sortheader functionality does not work if datatable contains editable components
> --------------------------------------------------------------------------------
>
>          Key: MYFACES-228
>          URL: http://issues.apache.org/jira/browse/MYFACES-228
>      Project: MyFaces
>         Type: Bug
>     Versions: 1.0.9 beta
>  Environment: WindowsXP, JDK 1.4.1_06, Tomcat 5.5
>     Reporter: Rolf Kulemann
>     Priority: Critical

>
> I'm using a dataTable with sortheader. Everything is fine as long as I
> use outputText instead of a inputText. If I use inputText, the
> List/array is sorted correct on the srever side when my value binding is invkoked by
the datatable, but the old model (unsorted) is displayed.
> I debuged that a bit and recognized, that as soon as I click any command button, the
sorted list gets displayed correctly. This is because refresh() is called in the datatable
when clicking a commandButton. Refresh isn't called when u click on the sort header command.
On the other hand using outputText works fine. While looking at the HtmlDataTableHack class
i found
>  private static int restoreDescendantComponentStates(UIComponent component,
>                                                         EditableValueHolderState[] states,
>                                                         EditableValueHolderState[] initialStates,
>                                                         int counter, int level)
>     {
>         for (Iterator it=getChildrenAndOptionalFacetsIterator(level, component); it.hasNext();)
>         {
>             UIComponent child = (UIComponent)it.next();
>             //clear this descendant's clientId:
>             child.setId(child.getId()); //HACK: This assumes that setId always clears
the cached clientId. Can we be sure?
>             if (child instanceof EditableValueHolder)
>             {
>                 if (states != null)
>                 {
>                     states[counter].restore((EditableValueHolder)child);
>                 }
>                 else if (initialStates != null)
>                 {
>                     initialStates[counter].restore((EditableValueHolder)child);
>                 }
>                 else
>                 {
>                     // No state saved yet and no initial state !?
>                     // Should never be possible, but let's reset the component
>                     // state to null values
>                     ((EditableValueHolder)child).setValue(null);
>                     ((EditableValueHolder)child).setLocalValueSet(false);
>                     ((EditableValueHolder)child).setValid(true);
>                     ((EditableValueHolder)child).setSubmittedValue(null);
>                 }
>                 counter++;
>             }
>             counter = restoreDescendantComponentStates(child, states, initialStates,
counter,level+1);
>         }
>         return counter;
>     }
> Not sure, but it seems that this codes cuases the old model state to be rendered and
not the newly sorted one. If I have time, I will track it down a bit more.
> You can simply reproduce this by changing the sortTable example. You
> only need to change outputText into inputText.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Mime
View raw message