jmrodrigg
jmrodrigg

Reputation: 600

reRender rich:tabPanel without losing data

Using JSF 1.2 and Richfaces 3.3, I have this form:

<h:form>
    <rich:tabPanel switchType="client" id="tabPnl">
        <rich:tab label="MAIN_TAB">
            <h:outputText value="#{msg.date}"/>
            <rich:calendar value="#{MyBean.date}">
                <f:validator validatorId="CalendarValidator" />
            </rich:calendar>
            <h:message for="DataInici" errorClass="error" />

            <h:outputText value="#{msg.selector}"/>
            <h:selectOneMenu id="select_val" value="#{MyBean.selectedItem}">
                <f:selectItem itemLabel="#{msg.select_value}" itemValue="-1" />
                <f:selectItems value="#{MyBean.listOfItems}" />
                <f:validator validatorId="NumSelValidator" />
                <a4j:support event="onchange" reRender="tabPnl" ajaxSingle="true" />
            </h:selectOneMenu>
            <h:message for="select_val" errorClass="error" />
        </rich:tab>

        <rich:tab label="SUBTAB1" id="subtab1" rendered="#{MyBean.selectedItem == 1}">
            // form components such as inputText and/or SelectOneMenu.
        </rich:tab>

        <rich:tab label="SUBTAB2" id="subtab2" rendered="#{MyBean.selectedItem == 2}">
            // Other form components such as inputText and/or SelectOneMenu.
        </rich:tab>
    </rich:tabPanel>

    <h:commandButton value="#{msg.insert}" action="#{MyBean.insertData}">
</h:form>

At the begining, SUBTAB1 and SUBTAB2 are not rendered as the default value for MyBean.selectedItem is -1.

Firstly, the user picks a date in the <rich:calendar> component and, after that, it selects a value in the <h:selectOneMenu>. After that, the desired behaviour (what I want to achieve) is reRender the tabPanel without losing the data already introduced. Consequently, I expect the tabs SUBTAB1 or SUBTAB2 become rendered depending on what the value chosen in the <h:selectOneMenu>.

What I get: The tabPanel is reRendered, the appropiate SUBTAB is rendered but the data introduced in the first tab is lost.

How can I render these tabs without losing the data already introduced? I've tried to reRender the specific tabs, but it dosen't make them become rendered (I suppose it only affects to their content).

Thank you in advance.

Note: All beans involved are Session scoped.

Upvotes: 0

Views: 1675

Answers (1)

Andrey
Andrey

Reputation: 6766

Problem is that the inputs values are not processed on server. Remove ajaxSingle="true" from a4j:support, so the whole form is processed when selectOneMenu value changes. You can use process attribute to limit the submitted area (in case you don't want to process the whole form).

ajaxSingle

Limits JSF tree processing (decoding, conversion, validation and model updating) only to a component that sends the request. Boolean. Default value is "false".

Upvotes: 1

Related Questions