function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
msb-appsupport1.3905906418879758E12msb-appsupport1.3905906418879758E12 

How to check whatever I want from a list?


Hi,
I have displayed a list of result. And I want to check the on I want with a check function.

How could I do it?

Thanks so much.

The below is related code.

<apex:pageblockSection columns="2" id="result_section">
            <apex:pageblockTable value="{!ticket_result_list}" var="tItem" id="result_table">
                <apex:column headerValue="Ticket Search Result">
                    <apex:outputText value="No result" rendered="{!NOT(found)}"/>
                    <apex:outputText value="{!tItem.name}" rendered="{!found}"/>
                </apex:column>
                <apex:column headerValue="Check-in">
                     <apex:commandButton action="{!check}" value="Check-in" reRender="ticket_check_in"/>
                </apex:column>
                <apex:column headerValue="Uncheck">
                    <apex:commandButton action="{!uncheck}" value="Uncheck" reRender="ticket_check_in"/>
                </apex:column>
            </apex:pageblockTable>
        </apex:pageblockSection>

public PageReference check() {
        //what should I do here to check the on I want.
        update ticketFound;
        return null;
    }

The following is the result list.

This image is not available because: You don’t have the privileges to see it, or it has been removed from the system
Phillip SouthernPhillip Southern
So if I'm understanding correctly, you want for each line item of the table, an object (tickets?) and two buttons.  You'll need to do a wrapper class so that you can build that....the wrapper class will have an instantiation of the object and then two pagereference methods of check and uncheck.  On compiling the data for the table, you'll need a List of the wrapper class...that is what you'll reference and then iterate over the table.

Reference for wrapper class: http://wiki.developerforce.com/page/Wrapper_Class
msb-appsupport1.3905906418879758E12msb-appsupport1.3905906418879758E12
Hi, 
I have tried your answer. The problem I got is I could not update the selected field.

It seems when I check the checkbox, the value {!tItem.selectedCheck} and {!tItem.selectedUnCheck} could not got update.

Could you tell me how to solve it?

Thanks so much.

The following is my code:

<!-- display the result and check-in -->
        <apex:pageblockSection columns="2" id="result_section">
            <apex:pageblockTable value="{!ticket_result_list}" var="tItem" id="result_table">
                <apex:column headerValue="Ticket Search Result">
                    <apex:outputText value="No result" rendered="{!NOT(found)}"/>
                    <apex:outputText value="{!tItem.ticket.name}" rendered="{!found}"/>
                </apex:column>
               
                <!-- check box to select which the user want to check-->
                <apex:column headerValue="Check-in">
                    <apex:inputCheckbox value="{!tItem.selectedCheck}"/>
                </apex:column>
                <apex:column headerValue="Uncheck">
                    <apex:inputCheckbox value="{!tItem.selectedUncheck}"/>
                </apex:column>

                <!--
                <apex:column headerValue="Check-in">
                     <apex:commandButton action="{!check}" value="Check-in" reRender="result_table"/>
                </apex:column>
                <apex:column headerValue="Uncheck">
                    <apex:commandButton action="{!uncheck}" value="Uncheck" reRender="result_table"/>
                </apex:column>
                -->
            </apex:pageblockTable>
        </apex:pageblockSection>
            <p />
            <apex:commandButton action="{!check}" value="Check-in" reRender="result_table"/>
            <p />
            <apex:commandButton action="{!uncheck}" value="Uncheck" reRender="result_table"/>
        </apex:pageBlock>

--------------------------------------------------------------------------------------------------------------------------------

//check button and uncheck button
    public PageReference check() {
        List<DisplayTicket> selectedTickets = new List<DisplayTicket>();
       
        for(DisplayTicket selectTic: getTicket_result_List()) {
            if(selectTic.selectedCheck == True) {
                selectTic.ticket.sbxe1__sbx_Attended__c = TRUE;
                update selectTic.ticket;
            }
        }
       
        selectedTickets = null;

        return null;
    }   

    public PageReference uncheck() {
        List<DisplayTicket> selectedTickets = new List<DisplayTicket>();
       
        for(DisplayTicket selectTic: getTicket_result_List()) {
            if(selectTic.selectedCheck == FALSE && selectTic.selectedUncheck == TRUE) {
                selectTic.ticket.sbxe1__sbx_Attended__c = FALSE;
                update selectTic.ticket;
            }
        }
       
        selectedTickets = null;

        return null;
    }

public class DisplayTicket {
        public sbxe1__Ticket__c ticket {
            get; set;
        }
        public Boolean selectedCheck {
            get; set;
        }
        public Boolean selectedUncheck {
            get; set;
        }       
        public DisplayTicket(sbxe1__Ticket__c item) {
            this.ticket = item;
            selectedCheck = false;
            selectedUncheck = false;
            //this.no_found_msg = 'No result';
        }
        public String name {
            get {return ticket.Name;}
        }
        public String no_found_msg {
            get {return 'No result';}
        }

    }


Phillip SouthernPhillip Southern
Can you post your full class?  Looks like you've only included the two pagereference methods and the wrapper class.  Your pageblocktable should be iterating over the List of the wrapper class.  Also that List needs to be available and instantiated outside the pagereference methods.