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
Anto HotelbedsAnto Hotelbeds 

Wrapper class, controller and visualforce

Hi,

I have a visualforce page where I am showing all the attachments related to a case with a checkbox to know if the user has marked it. This is the related part of the VF page:
<apex:pageBlock title="Existing Case Attachments">
        <apex:pageBlockTable value="{!listAttachWrapper}" var="item">
            <apex:column title="Select" headerValue="Add Attachment" width="50px,50px">
                <apex:inputCheckbox value="{!item.IsChecked}">
                    </apex:inputCheckbox>
            </apex:column>
            <apex:column headerValue="File">
                <apex:outputLink value="{!URLFOR($Action.Attachment.Download, item.att.Id)}"
                    target="_blank">{!item.att.Name}</apex:outputLink>
            </apex:column>
            <apex:column value="{!item.att.Description}" />
        </apex:pageBlockTable>
    </apex:pageBlock>

I also have my controller with the definition of the wrapper class:

public List<attWrapper> listAttachWrapper {get;set;}
public List <Attachment> selectedmems{get;set;}
   
public class attWrapper{
	public Attachment att {get; set;}
      	public Boolean isChecked{get; set;}
      
      	public attWrapper(Attachment att){
      		this.att=att;
        	if (isChecked==null){
        		isChecked=false;
        	}
      	}
    }

And in the constructor of the method, I get the elements and mark the ischecked field to false:

listAttachWrapper=new List<attWrapper>();
for (Attachment a:[SELECT Name,Description FROM Attachment WHERE ParentId=:case1.Id])
			listAttachWrapper.add(new attWrapper(a));

Finally I have the method that is called from the VF page, where I try to get which attachments have been market to true:

selectedmems=new List<Attachment>();
system.debug('List of members: '+listAttachWrapper);
for (attWrapper att: listAttachWrapper){
                	if (att.IsChecked==true){
                		selectedmems.add(att.att);
                	}
                }
system.debug('The list is:' + selectedmems);

The problem is that I get all the elements with the IsChecked field to false, even though I am selecting them in the VF page.

I have been for two days already with this, can anyone help please?

Thanks a lot!

Antonio




Cloud_forceCloud_force
you should write some java script on click of checkboxes to mark them selected.
you can go through this article to know more: http://www.cloudforce4u.com/2013/07/select-all-checkbox-using-javascript-in.html

t
hanks,
http://www.forcexplore.com
Anto HotelbedsAnto Hotelbeds
Thanks sfdc_Wave.

I think that the java script will  mark all the list check boxed to true. I want to mark one by one. And in the example you sent me there is no javascript for this.

Any other suggestion?

Thanks,

Antonio