0

I have an editable datatable, containing column with Boolean type. When editing this column, the selectOneMenu is used to select the value "true", "false" or "null". When I enter the edit mode, the default selection is true if the value is null.

How could be solved this issue? Another question it a good approach to use Enity bean (the result of a database query), or I have to create a Managed bean?

Xhtml:

    <p:column headerText="Active">
        <p:cellEditor>
            <f:facet name="output">
                <h:outputText value="#{member.active}" />
            </f:facet>
            <f:facet name="input">
                <h:selectOneMenu value="#{member.active}" style="width:100%">
                    <f:selectItems value="#{memberManagementController.activeLabels}" />
                </h:selectOneMenu>
            </f:facet>
        </p:cellEditor>
    </p:column>

Entity Bean:

@Entity
@NamedQueries({
    @NamedQuery(...
})
@Table(name="Member")
public class Member implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;

    private Boolean active;

    public Boolean getActive() {
        return this.active;
    }

    public void setActive(Boolean active) {
        this.active = active;
    }
    ...
fuqsha
  • 73
  • 1
  • 6

1 Answers1

-1

Change your code to this

<h:selectOneMenu value="#{member.active}" style="width:100%">
    <f:selectItem noSelectionOption="true"/>
    <f:selectItems value="#{memberManagementController.activeLabels}" />
</h:selectOneMenu>

As for your beans, it is preferrable to use managed beans in your view controllers

tfosra
  • 581
  • 5
  • 12
  • This is not correct. Explanation on `noSelectionOption` can be found here: http://stackoverflow.com/q/11360030 – BalusC May 17 '16 at 20:01