Greets,

After converting my application from JSP to Facelets, I set out to make my "rowStyleClass" attribute on t:dataTable work like it used to.

First, I had to get the attribute working in Facelets. With considerable discussion on the user list (see [1] and [2]) and a lot of help from Mike, I think we've identified some pretty simple code changes to enable this and other similar attributes. I plan to introduce a patch for this, probably tomorrow.

What happened next was that during testing of this change, I could confirm that the attribute did indeed now work, but I was baffled by unexpected behaviour. My EL expression which had previously returned null in certain situations was now returning the empty String. I went to Facelets list for some clarification on this (see [3]) and it turned out to be a requirement of the new EL spec to coerce the nulls into empty string.

Getting an empty String instead of null for this ValueBinding lookup creates a problem because the extended dataTable treats a null value differently and goes looking at the more standard style attributes like rowClasses. With an empty string returned, it assumes it needs to look no further. As a user, there is no way for me to specify that under certain conditions, it should fallback to the other style attributes, e.g. rowClasses.

The best fix we have collectively come up with so far is to coerce the empty string back into a null in the dataTable, so that the renderer does the right thing. I don't see too much downside to this approach, as an empty style string has no relevance in CSS. However, I feel a proposed change like this requires extra discussion before making a decision on it. It's another one of those situation where we have to decide how we want to handle unexpected results due to changes in the newer specs.

If you review the threads a bit, you can see more of the details of the issues. I'll post my preliminary proposed code changes at the bottom.

[1] https://facelets.dev.java.net/servlets/ReadMsg?list=users&msgNo=6875
[2] http://www.nabble.com/Re%3A-Facelets-support-for-a-Tomahawk-dataTable-trick--tf3236491.html
[3] https://facelets.dev.java.net/servlets/ReadMsg?list=users&msgNo=6941

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.


Okay proposed code change in org.apache.myfaces.component.html.ext.HtmlDataTable

Original Method:

    public String getRowStyleClass()
    {
        if (_rowStyleClass != null)
            return _rowStyleClass;
        ValueBinding vb = getValueBinding(JSFAttr.ROW_STYLECLASS_ATTR);
        return vb != null ? (String) vb.getValue(getFacesContext()) : null;
    }


New Method:

    public String getRowStyleClass()
    {
    if (_rowStyleClass != null)
        return _rowStyleClass;

// TODO: temporarily support fully-qualified ext. dataTable attribute names. ValueBinding vb = getValueBinding("org.apache.myfaces.dataTable.ROW_STYLECLASS");
    if (vb != null)
log.warn("org.apache.myfaces.dataTable.ROW_STYLECLASS is deprecated. Please use rowStyleClass instead.");
    else
        vb = getValueBinding(JSFAttr.ROW_STYLECLASS_ATTR);
    if(vb == null)
        return null;
    String bindingValue = (String) vb.getValue(getFacesContext());
    if(bindingValue == "")
        return null;  // Fix for JSF 1.2 EL coercing nulls to empty string
    return bindingValue;
    }

That, along with the change to JSFAttr to change the constant value from "org.apache.myfaces.dataTable.ROW_STYLECLASS" to "rowStyleClass". NOTE: This change affects the shared code!


Reply via email to