开发者

Form value not passed to Seam bean after a4j reRender

I'm making a webapp in Seam but ran into a problem I can't seem to fix.

I have a JSF form where the customer can select a reservation type through a combobox. Based on the selected value, other form components gets rendered.

For example: the customer selects Hours as reservation type, a panelGroup gets rendered where the customer can select a start- and an end hour. But if the customer would select 'part of the day' as reservation type, a selectOneMenu gets rendered where the customer can select a part of the day (morning, afternoon, evening)

The rerendering well but the values of the components with a rendered conditional won't get passed to the bean. They stay null values.

This is the code i'm talking about:

<s:div id="spot"
       rendered="#{selectedProduct.productType.name eq 'Flex Spot'}">

    <h:panelGrid columns="2">
        <h:outputText value="Reservation Type" />
        <h:selectOneMenu value="#{selectedPeriodPart}">
            <s:selectItems
                value="#{productManager.getAvailableDayPartsSpot()}"
                var="daypart"
                label="#{daypart.label}"></s:selectItems>
            <s:convertEnum />

            <a4j:support ajaxSingle="true"
                         event="onchange"
                         action="#"
                         reRender="spot">
            </a4j:support>
        </h:selectOneMenu>

        <h:outputText id="date_spot" value="Date" />

        <a4j:outputPanel id="calendar_spot" layout="block">
            <rich:calendar value="#{reservation.reservationPeriod.startDate}"
                           locale="en" cellWidth="24px"
                           cellHeight="22px"
                           style="width:200px" />
        </a4j:outputPanel>

        <h:outputText rendered="#{selectedPeriodPart eq 'DAY_PART'}"
                      value="Daypart" />

        <h:selectOneMenu value="#{selectedDaypart}"
                         rendered="#{selectedPeriodPart eq 'DAY_PART'}">
            <f:selectItem id="si_morning" itemLabel="Morning (6:00 - 12:00)"
                          itemValue="morning" />
            <f:selectItem id="si_afternoon"
                          itemLabel="Afternoon (12:00 - 18:00)" itemValue="afternoon" />
            <f:selectItem id="si_evening" itemLabel="Evening (18:00 - 00:00)"
                          itemValue="evening" />
        </h:selectOneMenu>

        <h:outputText rendered="#{selectedPeriodPart eq 'HOURS'}"
                      value="Hours" />

        <h:panelGroup id="hou开发者_如何学Pythonrs_spot"
                      rendered="#{selectedPeriodPart eq 'HOURS'}">
            <ui:include src="/includes/reservation/select_hours.xhtml" />
        </h:panelGroup>
    </h:panelGrid>
</s:div>

Note: The calendar value do get passed back to the bean but the value of this piece of code doesn't (it does if you remove the rendered conditional):

selectOneMenu value="#{selectedDaypart}" rendered="#{selectedPeriodPart eq 'DAY_PART'}"


You need to ensure that the conditionals responsible for the outcome of the rendered attribute are also the same in the subsequent request of the form submit. Because when a component isn't rendered, JSF won't apply the request values them.

In a nutshell, the property behind #{selectedPeriodPart} needs to be the same in the subsequent request. There are several solutions:

  1. Put bean in session scope. Easiest solution, but bad for server memory and client experience (updates would be reflected in multiple tabs/windows in same session).

  2. Pass it through using <h:inputHidden>. Not sure though how this fits in the Ajax/Richfaces picture. Better use <a4j:keepAlive> here.

  3. Use a conversation scope. Seam offers facilities for this.


I fixed it -.- Nothing was wrong with the code I posted. Because I wasn't able to solve this issue I continued on an other page in the same conversation. I noticed some more strange behaviour: outjection of a variable didn't work etc.

I figured the mistake was in some other part of the code which, after corrected, fixed the whole problem.

Thx for answering guys!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜