[ 
http://issues.apache.org/jira/browse/MYFACES-214?page=comments#action_65954 ]
     
Philipp Ahlner commented on MYFACES-214:
----------------------------------------

Since many components (like HtmlSelectBooleanCheckbox) expects a boolean value 
as submitted value (only the decode-method of each renderer knows what type as 
submittedValue has to set), I'm tending to discard the idea to "fake" 
submittedValue. I can now provide a patch which hides the not-selected tabs 
with a <div style="display:none">-tag. The disadvantage of this solution is 
that the content of each tab is transferred to the browser, but this solution 
never breaks the jsf-spec.
Please forget all patches I've submitted before :-)


I've changed the HtmlTabbedPaneRenderer.writeTabCell() method. If a tab is 
hidden, the components are enclosed in a div tag.

protected void writeTabCell(ResponseWriter writer, FacesContext facesContext, 
HtmlPanelTabbedPane tabbedPane,
            int tabCount, int selectedIndex) throws IOException {
        HtmlRendererUtils.writePrettyLineSeparator(facesContext);
        HtmlRendererUtils.writePrettyIndent(facesContext);
        writer.startElement(HTML.TD_ELEM, tabbedPane);
        writer.writeAttribute(HTML.COLSPAN_ATTR, Integer.toString(tabCount + 
1), null);
        writer.writeAttribute(HTML.STYLE_ATTR, TAB_CELL_STYLE + 
"background-color:" + tabbedPane.getBgcolor(), null);
        HtmlRendererUtils.renderHTMLAttribute(writer, tabbedPane, 
"tabContentStyleClass", HTML.STYLE_CLASS_ATTR);

        int tabIdx = 0;
        List children = tabbedPane.getChildren();
        for (int i = 0, len = children.size(); i < len; i++) {
            UIComponent child = getUIComponent((UIComponent) children.get(i));
            if (child instanceof HtmlPanelTab) {
                // the inactive tabs are hidden with a div-tag
                if (tabIdx != selectedIndex) {
                    writer.startElement(HTML.DIV_ELEM, tabbedPane); 
                    writer.writeAttribute(HTML.STYLE_ATTR, "display:none", 
null);
                    RendererUtils.renderChild(facesContext, child);
                    writer.endElement(HTML.DIV_ELEM);
                }
                else
                {
                    RendererUtils.renderChild(facesContext, child);
                }
                                
                tabIdx++;
            } else {
                RendererUtils.renderChild(facesContext, child);
            }
        }

        writer.endElement(HTML.TD_ELEM);
    }


A second change is necessary (we cannot only decode the visible tab, all 
components are correctly rendered and must be decoded) in 
HtmlPanelTabbedPane.processDecodes:


public void processDecodes(javax.faces.context.FacesContext context)
    {
        if (context == null) throw new NullPointerException("context");
        decode(context);

        int tabIdx = 0;
        int selectedIndex = getSelectedIndex();

        Iterator it = getFacetsAndChildren();

        while (it.hasNext())
        {
            UIComponent childOrFacet = getUIComponent((UIComponent) it.next());
            childOrFacet.processDecodes(context);
        }
    }

I've tested my solution with the examples and Firefox 1.0.4 (LinuX). I'll test 
the solution with a IE in the next days.
I've changed the tabbedPane.jsp in the examples at the 3rd pane as follows to 
test my solution:

from:
<h:inputText id="inp3"/>
to:
<h:inputText id="inp3" required="true"/>

I would propose this change in the examples for tests in the future.


> TabbedPane : wrong validation behavior
> --------------------------------------
>
>          Key: MYFACES-214
>          URL: http://issues.apache.org/jira/browse/MYFACES-214
>      Project: MyFaces
>         Type: Bug
>     Versions: 1.0.9 beta
>  Environment: MyFaces 1.0.9rc3, Tomcat 5.0.27, j2sdk1.5.0_01
>     Reporter: Philipp Ahlner

>
> Requirements for reproduction:
> - min. two tabs with min. one required Input-Fields
> - a submit button on each tab
> - an "<h:messages styleClass="errors" showDetail="true" 
> showSummary="true"/>"-tag to see all validation errors regardless which tab 
> is selected
> Expected behavior:
> - if the submit button is pressed, !both! fields should be validated 
> regardless which tab is selected
> Steps to reproduce:
> 1. start a new session
> 2. let the required text fields empty
> 3. press the submit button in the first tab.
> Behavior:
> Only the field(s) on the first tab is validated.
> The interesting effect:
> Select the second tab and press submit. The validation errors on !both! tab 
> occours. If the tab was 
> activated at least one time in a new session, all fields were validated 
> correctly.
> Further informations: 
> http://www.mail-archive.com/users%40myfaces.apache.org/msg03525.html

-- 
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

Reply via email to