6

I have an issue with my check box, I want to perform a function on checking my check box and after deselecting it should come back to its original state.

VF Page

<apex:outputLabel for="check2" value="Show Completed" style="margin-left:100px;"/>
   <apex:inputCheckbox id="check2" value="{!ShowCompleted}" >
      <apex:actionSupport event="onchange"  action="{!ShowCompletedTask}" reRender="pbId"/>
   </apex:inputCheckbox>
</apex:outputLabel>

Controller

    public void ShowCompletedTask(){
      if(ShowCompleted == true){ 
          QuerySelector = 'select Subject, OwnerId, Owner.name, status, ActivityDate, ReminderDateTime,        Priority, AccountId, WhoId, Who.name from Task';
          TaskList =  Database.query(QuerySelector);
          for (Task t: TaskList  ) {

               WrapperMethod w = new WrapperMethod(t, false, false, 'Task', false, true);

              TaskWrapperList.add(w);
            }
        }
        String strStatus='Completed'; 
        QuerySelector = 'select Subject, OwnerId, Owner.name, status, ActivityDate, ReminderDateTime, Priority, AccountId, WhoId, Who.name from Task where status != :strStatus';
        TaskList =  Database.query(QuerySelector);
        for (Task t: TaskList  ) {

              WrapperMethod w = new WrapperMethod(t, false, false, 'Task', false, true);

              TaskWrapperList.add(w);
             }

   }
4
  • 3
    What part does not work?
    – Keith C
    Dec 2, 2014 at 15:39
  • When i deselect the check box i.e when the "ShowCompleted == false" then it should give me another list which i have placed below the if block, it is not giving that list. Dec 3, 2014 at 5:01
  • your action method is misnamed - it really is showTasks() as it either shows all tasks (1st query) + all open tasks (2nd query) (if showCompleted is true) or it shows all open Tasks (2nd query) if showCompleted = false. Also, the VF component identified by id=pbId is not shown in OP. Both queries are missing a where clause to restrict the list of Tasks down to a user or account or date range -- otherwise way too many rows will come back
    – cropredy
    Dec 3, 2014 at 5:25
  • Thanks crop, i tried the changes and it is appending the list to my original list. Can please suggest me some thing. My requirement that initial my list display tasks with "Status is not equal to completed" and and when i check the Checkbox "ShowCompleted" it should display me the list with completed tasks as well and when i uncheck it should return the previous list. Dec 3, 2014 at 5:34

2 Answers 2

3

I got my solution, i added an extra if condition for false and it worked.

0

It's onclick() for the checkbox...

You must log in to answer this question.

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