Play Games

Search This Blog

Tuesday, October 18, 2016

How to display multiple options for a field to select(Multiple checkboxes)

Problem : I want to design the vf page as shown in the image below.

Apex Class :
public class MultipleCheckboxes {
    public List<MultipleCheckboxWrap> lstRecords {get;set;}
    public MultipleCheckboxes () {
    
        lstRecords = new List<MultipleCheckboxWrap>();
        lstRecords.add(new MultipleCheckboxWrap('English',false,false,false,false));
        lstRecords.add(new MultipleCheckboxWrap('Maths',false,false,false,false));
        lstRecords.add(new MultipleCheckboxWrap('Science',false,false,false,false));
    }
    public class MultipleCheckboxWrap {
        public string fieldLabel {get;set;}
        public boolean isOne {get;set;}
        public boolean isTwo {get;set;}
        public boolean isThree {get;set;}
        public boolean isFour {get;set;}
        public MultipleCheckboxWrap (String l,boolean one,boolean two,boolean three,boolean four) {
            fieldLabel =l;
            isOne = one;
            isTwo = two;
            isThree = three;
            isFour  = four;
            
        }
        
    }
    public void m() {
        List<string> lstpicklist1;
        List<string> lstpicklist2;
        for(MultipleCheckboxWrap s : lstRecords ) {
            if(s.isOne == true) {
                lstpicklist1.add(s.fieldLabel);    
            }
            if(s.isTwo == true) {
                lstpicklist2.add(s.fieldLabel);    
            }
        }
    }
}
Visualforce Page :
<apex:page controller="MultipleCheckboxes">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockTable value="{!lstRecords}" var="a">
            <apex:column value="{!a.fieldLabel}" title="picklist Value" headerValue="picklist Value"/>
            <apex:column headerValue="One"><apex:inputCheckbox value="{!a.isOne}" title="One" /></apex:column>
            <apex:column headerValue="Two"><apex:inputCheckbox value="{!a.isTwo}" title="Two" /></apex:column>
            <apex:column headerValue="Three"><apex:inputCheckbox value="{!a.isTwo}" title="Three" /></apex:column>
            <apex:column headerValue="Four"><apex:inputCheckbox value="{!a.isTwo}" title="Four" /></apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:form>
</apex:page>

No comments:

Post a Comment