0
votes

So it's like this.

MyMb:

@Named("MyMb")
@SessionScoped
public class MySuperCoolMb implements Serializable {
    //Tons of attributes

    private List<ListModelOne> lmo = new ArrayList();

    //Tons of methods
}

Outter Model:

public class ListModelOne {

    private coolObject object;
    private List<ReadWrite> permissions;

    //init()
    //setters-getters

}

Inner Model, this is the Model that needs to be bind directly to the selectItems on screen

public class ReadWrite {

    private String accessItem;
    private boolean read = false;
    private boolean write = false;
    //Somewhere in my code i change this from true/false depending
    //what i need and they do change in title in xhtml.
    //setters-getters
}

And my xhtml:

<h3>Cool Title</h3>
<p:accordionPanel value="#{MyMb.lmo}" var="modelOne">
    <p:tab title="#{modelOne.coolObject.ObjectName}">
    <h3>Cool Inner Title</h3>
        <ui:repeat value="#{modelOne.permissions}" var="readWrite">
            <h:panelGrid>
            <h:outputText value="#{readWrite.accessItem}"/>
                <!-- selectManyCheckbox has no value attribute because i don't need/have a list/collection to bind it -->
                <p:selectManyCheckbox>
                    <f:selectItem itemLabel="Read" itemValue="#{readWrite.read}" title="This is set to #{readWrite.read}"/>
                    <f:selectItem itemLabel="Write" itemValue="#{readWrite.write}" title="This is set to #{readWrite.write}"/>
                </p:selectManyCheckbox>
            </h:panelGrid>
        </ui:repeat>
    </p:tab>
</p:accordionPanel>

Everything works fine but the checkboxes (selectItem), can they be bound directly to an attribute of a class and ignote value of p:selectManyCheckboxes? Everything works fine on java, i've debugged and the values are right, they even print OK on "tittle" attribute in the f:selectItem (Some true, and some false)

PS: Also i couldn't understand the difference between ItemLabel, label, ItemValue, Value

2

2 Answers

0
votes

Does anything aspect against using two <p:selectBooleanCheckbox>?

Otherwise I'd propose a code like this:

<h:panelGrid>
    <h:outputText value="#{readWrite.accessItem}"/>
    <p:selectBooleanCheckbox value="Read" itemLabel="#{readWrite.read}" />
    <p:selectBooleanCheckbox value="Write" itemLabel="#{readWrite.write}" />
</h:panelGrid>

Look at this: http://www.primefaces.org/showcase/ui/input/booleanCheckbox.xhtml

ItemValue and ItemLabel are used if you want to dynamically generate your selectOptions (like checkboxes or options in a dropdown-menu etc). Example:

// Java-class...
@Named(
public enum SelectOption(){
    Max, Oliver, John;
}

// In bean...
private List<SelectOption> fornames; // with setter & getter

// In xhtml...
<p:selectManyCheckbox value="#{bean.fornames}">
    <f:selectItems value="#{bean.fornames.values()}" var="forname" 
        itemValue="#{forname}" itemLabel="#{forname.toString()}" />
</p:selectManyCheckbox>

Explanation: the List in your bean will get all selected items. The f:selectItems-tag takes all possible options from the enumeration (you can hand over any collection), and iterates over every "forname"-object in the collection. In this case, the itemValue represents itself as we have a list of that object to save it in, and for the label, we call the toString-Method.

I hope this is explained understandable.

0
votes

the difference between itemlabel and ItemValue is that itemlabel is the label displayed and ItemValue is the value given to selecting