Search code examples
jsfjsf-1.2icefacesicefaces-1.8

Null value submitted for a conditionally disabled field in a reusable JSF popup


I have a popup dialog developed in IceFaces 1.8.x (JSF 1.2).

The dialog is reusable (used for account creation as well as modification) and has a cancel button with immediate = true (to avoid validations). This dialog suffered a problem in the past ,where old values were rendered on re-opening the dialog, but that problem is now fixed as directed here (by setting submittedValue to null etc.).

The problem that I am facing now is specific to a conditionally disabled input field (<ice:inputText>) and here is what happens:

  1. The popup is first opened (say for account creation) and this field is NOT disabled.
  2. User then cancels this dialog and, as we have incorporated the fix mentioned above (setSubmittedValue(null)), the submittedValue for this field is set to null (along with other fields).
  3. Now the user opens "modify account" dialog, where in this field IS disabled. Everything seems to be rendered fine until user makes any changes to the form.
  4. When user changes some field (say name) in the form, a partial submit happens for the name field as expected, but along with it null value is submitted for this disabled field.

This problem can be worked around by adding a null check in the setter method for the field in question, but this is not the desired solution for the project - as there are multiple places where this could be needed and doesn't seem like a very intuitive thing to do.

So I need to understand:

  1. Why is the setter for this disabled field getting called in the first place? and that too with a null value. The setter is not called for any other enabled fields.
  2. More importantly, is there any way to fix this (other than adding null check in the setter)?

Solution

  • You must be using rendered attribute to show/hide the dialog

    <ice:panelPopup modal="true" rendered="#{bean.enabled}">

    When dialog is reopened, it is coming up with some residual values from previous instance

    The solution (or workaround) is to use <c:if> instead of rendered attribute, this way the DOM is completely destroyed when dialog closes and created from scratch when dialog opens

    <c:if test="#{bean.enabled}">
        <ice:panelPopup modal="true">
        ...
        </ice:panelPopup>
    </c:if>
    

    This way you even would not need the fix to set submittedValue to null