2

Problem I'm currently trying to create a calendar grid, and I need to submit information selected in the grid to the controller.

I've been using a pageBlockTable and a list of day information to populate the grid, but I dont know the best way to send data associated with each grid section back to the controller. This is what I have thus far (surrounded by form tags).

    <apex:pageBlock title="Calendar">
            <apex:pageBlockTable value="{!calendar}" var="a" id="theGrid">
                <apex:column >
                    <apex:facet name="header">WEDNESDAY</apex:facet>
                    <apex:outputText value="{!a.Wednesday[0]}"></apex:outputText>
                    <apex:inputCheckbox label="{!a.Wednesday[0]}" ></apex:inputCheckbox>
                </apex:column>
                <apex:column >
                    <apex:outputText value="{!a.Wednesday[1]}"></apex:outputText>
                    <apex:inputCheckbox label="{!a.Wednesday[1]}" value="{!test}"></apex:inputCheckbox>
                </apex:column>

                //etc
           </apex:pageBlockTable>
    </apex:pageBlock>

enter image description here

I have inputCheckboxes that will allow for input. My idea is use javascript to traverse the table and look for selected boxes and use the label attribute to identify them for the controller and future saving of data. Is this the only way I can accomplish this, or is there a more direct solution?

Thanks

2
  • Visualforce supports two way binding - from Apex objects to input fields and from input fields to Apex objects. So you don't have to use JavaScript to get the data back to the server. The Apex objects can be classes you create - e.g. with morning and afternoon boolean fields - if you need to do some processing before you persist the data or if the data model maps directly to the screen you can directly use the SObjects.
    – Keith C
    Commented Sep 10, 2015 at 21:58
  • I think I ended up getting a bit confused with the wrapper classes. Salesforce is the first time I've had to implement this type of technique, and in doing so, I had a bit of an oversight. Thanks for the explanation!
    – lisolm
    Commented Sep 11, 2015 at 13:23

1 Answer 1

1

As Keith has already stated in his comment. Yes, you can directly bind data in dataTable. I am not sure how is your data persisted in your database, so I am using a wrapper class for it. Hope the below code gives you a brief idea.

Controller:

public class calenderDateWrapper { 
    public String calenderDate {get; set;} //e.g. Wed-2-Morning
    public Boolean isChecked {get; set;}
}

public class calenderWeekWrapper {
    public List<calenderDateWrapper> Monday = new List<calenderDateWrapper>();
    //etc.
}

Public List<calenderWeekWrapper> calender; //Handle that in your controller constructor 

In your page:

<apex:pageBlockTable value="{!calendar}" var="a" id="theGrid">
    <apex:column >
        <apex:facet name="header">WEDNESDAY</apex:facet>
        <apex:outputText value="{!a.Wednesday[0].calenderDate}"></apex:outputText>
        <apex:inputCheckbox label="{!a.Wednesday[0].calenderDate}" value="{!a.Wednesday[0].isChecked}"></apex:inputCheckbox>
    </apex:column>
    <apex:column >
        <apex:outputText value="{!a.Wednesday[1].calenderDate}"></apex:outputText>
        <apex:inputCheckbox label="{!a.Wednesday[1].calenderDate}" value="{!a.Wednesday[1].isChecked}"></apex:inputCheckbox>
    </apex:column>

    //etc

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .