BootsFaces-OSP: Attribute disabled, readonly, contentDisabled, rendered dynamically set fails.

When an input component like b:selectOneMenu, b:commandButton and others is dynamically hidden, blurred or not rendered at first page load by setting attributes like disabled, readonly, rendered, contentDisabled beforehand, the component doesn’t show the value that matches one of collection items.

Case 1: XHTML

<b:form>
...
<!-- Set param beforehand -->
<f:param name="disabledToggle" value="true"/>
...
<b:commandButton look="info" value="Enabled Menu" ajax="true" process="@this"
     actionListener="#{cartaportesController.populateMap(cartaporte)}" update"panel1">
     <f:param name="disabledToggle" value="false"/>
</b:commandButton>

<b:panelGrid id="panel1" columns="1">
     <b:selectOneMenu value="#{cartaportesController.selectedCartaporte.flete}" label="Flete:"
          readonly="#{param['disabledToggle']}">
          <f:selectItems value="#{cartaportesController.fletesConverter}"/>
          <f:converter converterId="cartaportesFletConv"/>
     </b:selectOneMenu>
</b:panelGrid>
...
</b:form

ENTITY

@Entity
@Table(name = "flete")
public class Flete implements Serializable {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id_flete")
    private int id;
    
    @Enumerated
    @Column(name = "tipo", columnDefinition = "int")
    private TipoFlete tipo;
    
    @Enumerated
    @Column(name = "status", columnDefinition = "int")
    private StatusFlete status;
    
    @Enumerated
    @Column(name = "finale", columnDefinition = "int")
    private FinaleFlete finale;
    
    @Column(name = "combustible")
    private double combustible;
    
    @Column(name = "viaticos")
    private double viaticos;

    @NotNull
    @ManyToOne
    @JoinColumn(name="id_transportista")
    private Transportista transportista;

    @NotNull
    @ManyToOne
    @JoinColumn(name="id_ruta")
    private Ruta ruta;

    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "updated")
    private Date updated;

    public Flete() {
    }

    // Getters - Setters...
    
    @Override
    public String toString() {
        return String.format("%1$05d", id) +  " : " + tipo.getTipoFlete() + " : " + ruta;
    }
}

BEAN SELECTITEMS MAP POPULATION METHOD

@Named(value = "cartaportesController")
@ViewScoped
public class CartaportesController implements Serializable {
    private Map<String, Flete> fletesConverter;
...
    public void populateMap(Cartaporte cartaporte) {
        Flete flete = selectedCartaporte.getFlete();
        
        fletesConverter = new TreeMap<>();
        if (flete == null || flete.getStatus() == StatusFlete.PLANEACION) {
             StatusFlete[] asf = {StatusFlete.PLANEACION};        
             fletesConverter.put("- Selecciona -", null);
             for (Flete f : new FleteDaoImpl().findByStatus(asf)) {
                 fletesConverter.put(f.toString(), f);
             }
        } else {
            fletesConverter.put(flete.toString(), flete);
        }
     }

    public Map<String, Flete> getFletesConverter() {
        return fletesConverter;
    }
}

SIMPLE CONVERTER

@FacesConverter(value = "cartaportesFletConv")
public class CartaportesFletConv implements Converter, Serializable {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (value == null) {
            return null;
        }

        return (Flete) context.getApplication().evaluateExpressionGet(context, "#{cartaportesController}", CartaportesController.class)
                .getFletesConverter().get(value);
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        return (value instanceof Flete) ? ((Flete) value).toString() : "";
    }
}

In this requirement, the component value #{cartaportesController.selectedCartaporte.flete} MUST match one of the seletedItems in collection, but it fails to do so because readonly attribute avoids it in some manner. If we change from b:selectOneMenu to JSF h:selectOneMenu or remove the readonly attribute, the value matches fine. The converter plays important part, so I think the menu component doesn’t apply the converter when this component is set readonly beforehand.

Case 2: XHTML

<!-- Set param beforehand -->
<f:param name="disabledToggle" value="true"/>
...
<b:commandButton look="info" value="Open Modal" ajax="true" process="@this"
     actionListener="#{cartaportesController.onView(cartaporte)}" update="@(.modalAgregar)"
     oncomplete="$('.modalAgregar').modal('show')">
     <f:param name="disabledToggle" value="false"/>
</b:commandButton>

<b:modal title="Coordinación" class="modalAgregar">
     <b:panelGrid id="panel2" columns="1">
...
          <b:commandButton value="Agregar" look="success" ajax="true" process="panel2"
               actionListener="#{cartaportesController.addMercancia()}" update="panel2"
               oncomplete="if(!validationFailed) $('.modalAgregar').modal('hide');"
               disabled="#{param['disabledToggle']}"/>
     </b:panelGrid>
</b:modal>

BEAN LISTENERS

@Named(value = "cartaportesController")
@ViewScoped
public class CartaportesController implements Serializable {
    private Cartaporte selectedCartaporte;
...
    public void onView(Cartaporte cartaporte) {
        selectedCartaporte = dao.findById(cartaporte.getId());
        ...
    }
    public void addMercancia() {
        if (selectedCartaporte.getCargas() == null) {
            selectedCartaporte.setCargas(new ArrayList<>());
        }
        selectedCartaporte.addCarga(selectedCarga);
    }
}

In this scenario, b:commandButton Agregar was set to disabled beforehand. User then update param disabledToggle to enable b:commandButton, so as to let him/her apply changes in modal, however the listener is never called because the disabled attribute kept component from registering the listener (I suppose), so it is already spoiled and won’t work, even once enabled. Now, if we change from b:commandButton to JSF h:commandButton or remove the disabled attribute the listener works fine.

In short, my project was plagued with this bug since I use consistently disabled, readonly, rendered and the brand new BootsFaces contentDisabled attributes. Sadly, I had to rearrange and redesign my pages once I noticed this behavior.

Thanks.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 30

Commits related to this issue

Most upvoted comments

@modima65 I’ve just uploaded BootsFaces-1.2.1-SNAPSHOT containing two bugfixes. I still can’t reproduce your bug, so I don’t believe it’s fixed by now but would you mind to have a look?

See #369 on how to get the sneak preview version of BootsFaces.

I apologizing for giving you the information in chapters. I’ve updated my post. In both cases, I’m using actionListeners since both scenarios operate inside their respective b:form and everything occurs inside the same page. No navigation, so no action attribute, just partial updates.