0

Hi I've a really strange situation that I can't get rid of. On the first ajax update of the entire form some values are just fine (they have the expected values) but some others just lose their values in some way (when I go with the debugger over those properties getters/setters I see that they have the expected value in the first part of the debugging session but then their setters just set them back to default value).

I am using Primefaces v7.0.10 and my Backing Bean is marked as @ViewScoped

To refresh the form I am using this p:selectOneMenu on whom onChage event a setter is called which opens a dialog whose outcome is just to refresh the entire form :

<div class="ui-sm-12 ui-g-6">
    <p:selectOneMenu value="#{currentEntity.definitionId}"
        widgetVar="selectProductDefinitionId" filter="true"
        id="inputDefinitionId" required="true" styleClass="ui-g-9"
        label="#{translate['table.product.definitionId']}"
        hideNoSelectionOption="true">
        <f:selectItem itemValue="#{null}"
        itemLabel="#{translate['product.productDefinition.select']}"
        noSelectionOption="true" />
        <f:selectItems value="#{bean.availableProductDefinitions}" />
        <p:ajax listener="#{bean.setProductDefinition}"></p:ajax>
    </p:selectOneMenu>
</div>

Here is some other snippets of the .xhtml file of the view:

<p:confirmDialog widgetVar="importDefinitionInfos"
    header="#{translate['gen.confirm.header']}"
    message="#{translate['product.productDefinition.confirm.message']}">
    <p:commandButton value="#{translate['gen.yes']}" update="form_product"
        action="#{bean.fetchProductDefinition()}"
        oncomplete="PF('importDefinitionInfos').hide();">
        <f:actionListener
            binding="#{bean.setReplaceWithDefinitionData(true)}"></f:actionListener>
    </p:commandButton>
    <p:commandButton value="#{translate['gen.no']}" update="form_product"
        action="#{bean.fetchProductDefinition()}"
        oncomplete="PF('importDefinitionInfos').hide()">
        <f:actionListener
            binding="#{bean.setReplaceWithDefinitionData(false)}"></f:actionListener>
    </p:commandButton>
</p:confirmDialog>


<h:form id="form_product">
    <h:panelGroup layout="block" id="productContent">
        <h:panelGroup styleClass="card no-margin" layout="block">
            <h:panelGroup layout="block"
                rendered="#{not empty currentEntity.id}">
                <h2>#{currentEntity.id} - #{currentEntity.producerProductId}</h2>
            </h:panelGroup>
            <h:panelGroup layout="block" styleClass="entityEditor ui-g"
                id="entityEditor">
                <p:tabView style="margin:20px 0 20px 0;" id="editTabView">
                    <p:tab
                        title="#{translate['table.productDefinition.tabView.title1']}">
                        <h:panelGroup styleClass="ui-g">
                            /*(OK) ALL OF THESE VALUES ARE AS EXPECTED AFTER THE FIRST AJAX UPDATE */
                            <div class="ui-sm-12 ui-g-6">
                                <h:outputLabel styleClass="ui-g-3 required"
                                    for="inputmanufacturerId">#{translate['table.productDefinition.manufacturerId']}</h:outputLabel>
                                <p:selectOneMenu value="#{currentEntity.manufacturerId}"
                                    filter="true" id="inputmanufacturerId" required="true"
                                    styleClass="ui-g-9 icon-top-10-percent"
                                    label="#{translate['table.productDefinition.manufacturerId']}">
                                    <f:selectItems value="#{bean.availableManufacturers}" />
                                </p:selectOneMenu>
                            </div>
                            /*OTHER FORM ELEMENTS*/

                                /*(NOT OK) THIS FIELDSET IS RESET ON THE FIRST AJAX UPDATE */
                            <p:fieldset legend="#{translate['product.extraData.longitude']}"
                                style="margin:20px 0 20px 0; width:100%;" styleClass="ui-g"
                                id="fieldsForLongitude">
                                <div class="ui-sm-12 ui-g-6 ui-lg-4">
                                    <h:outputLabel for="selectHemisphereLongitude"
                                        styleClass="ui-g-3">#{translate['coordinates.hemisphere']}:</h:outputLabel>
                                    <p:selectOneMenu
                                        value="#{bean.longitudeCoordinates.hemisphereLetter}"
                                        filter="false" id="selectHemisphereLongitude"
                                        styleClass="ui-g-9"
                                        label="#{translate['coordinates.hemisphere']}">
                                        <f:selectItems
                                            value="#{bean.getLongitudeHemisphereSelectItems()}" />
                                        <p:ajax event="change" async="true"
                                            listener="#{bean.updateLongitudeCoordinates}"
                                            update="inputGpsCoordinatesLongitude" />
                                    </p:selectOneMenu>
                                </div>
                                <div class="ui-sm-12 ui-g-6 ui-lg-4">
                                    <h:outputLabel for="inputDegreesLongitude" styleClass="ui-g-3">#{translate['coordinates.degrees']}:</h:outputLabel>
                                    <p:inputNumber id="inputDegreesLongitude"
                                        value="#{bean.longitudeCoordinates.degrees}" symbol=" °"
                                        placeholder="°" symbolPosition="s" styleClass="ui-g-9">
                                        <p:ajax event="change" async="true"
                                            listener="#{bean.updateLongitudeCoordinates}"
                                            update="inputGpsCoordinatesLongitude" />
                                    </p:inputNumber>
                                </div>
                                <div class="ui-sm-12 ui-g-6 ui-lg-4">
                                    <h:outputLabel for="inputMinutesLongitude" styleClass="ui-g-3">#{translate['coordinates.minutes']}:</h:outputLabel>
                                    <p:inputNumber id="inputMinutesLongitude"
                                        value="#{bean.longitudeCoordinates.minutes}" symbol=" '"
                                        placeholder="'" symbolPosition="s" styleClass="ui-g-9">
                                        <p:ajax event="change" async="true"
                                            listener="#{bean.updateLongitudeCoordinates}"
                                            update="inputGpsCoordinatesLongitude" />
                                    </p:inputNumber>
                                </div>
                                <div class="ui-sm-12 ui-g-6 ui-lg-4">
                                    <h:outputLabel for="inputDegreesLongitude" styleClass="ui-g-3">#{translate['coordinates.seconds']}:</h:outputLabel>
                                    <p:inputNumber id="inputSecondsLongitude"
                                        value="#{bean.longitudeCoordinates.seconds}" symbol=" ''"
                                        placeholder="''" symbolPosition="s" styleClass="ui-g-9"
                                        decimalPlaces="4">
                                        <p:ajax event="change" async="true"
                                            listener="#{bean.updateLongitudeCoordinates}"
                                            update="inputGpsCoordinatesLongitude" />
                                    </p:inputNumber>
                                </div>
                            </p:fieldset>
/*Other divs*/
</h:form>

The strange behavior is that this issue arise only on first onChange event of that p:selectOneMenu from before .. from the second and onwards onChange events everything is just fine and the entire form has the expected values (even those divs whose values was reset on the first ajax update).

Thanks in advance ...

fatBatman
  • 23
  • 7
  • 1) did this work with JSF 2.2? Or PrimeFaces 6 or a combination? Since I do not see any JSF 2.3 specific code not PrimeFaces 7. Tags are for what is an actual part of the problem. By using specific tags instead of the generic PrimeFaces or JSF tags you imply it is version related. Please correct and add version info (including implementation) in text in the question.2) see https://stackoverflow.com/help/tagging about your title. 3) See [mcve], waaaaaay to much irrelevant code in the question and relevant code missing – Kukeltje May 20 '20 at 08:12
  • Thanks for imroving the title, the least important of the 3 things in my previous comment ;-). Can you also improve or at least comment on the other two? Keep in mind that e.g. the tagging is also in your interest. The number of subscribers on the generic tags is way higher... – Kukeltje May 20 '20 at 09:50

0 Answers0