You need to sign in to do that
Don't have an account?
Anto Hotelbeds
inputcheckbox and wrapper class
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:
I also have my controller with the definition of the wrapper class:
And in the constructor of the method, I get the elements and mark the ischecked field to false:
Finally I have the method that is called from the VF page, where I try to get which attachments have been market to true:
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
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
So now the visualforce page looks like:
To whom it may help, remember to keep the button and the list where you are using the wrapper class under the same <apex:form>!!
Thanks to eveyrone for your help!
All Answers
And the related part of the class( i have change it a little bit to try more solutions, but still not working):
The command button code:
Any help is appreciated.Thanks!
Antonio
In method public List<attWrapper> getlistAttachs(), dont fetch and return at the same time.
When you perform any action, the page reloads, then pageblocktable loads and getlistAttachs() get invoked, hence it fetches the default values in the listAttachWrapper.
This should be the code for getlistAttachs() method.
Include the above code in contsructor or other method.
Hope this Helps.
Regards,
Amritesh
I did the change as indicated. I added in the constructor method the second part:
And substitue the getListAttachs by the following:
But I am still getting false in the listAttachWrapper as you can see in the debug log:
I really dont understand what I am doing wrong.....
Replace
<apex:pageBlockTable value="{!listAttachs}" var="item">
to
<apex:pageBlockTable value="{!listAttachWrapper}" var="item">
This should solve the issue.
Regards.
So now the visualforce page looks like:
To whom it may help, remember to keep the button and the list where you are using the wrapper class under the same <apex:form>!!
Thanks to eveyrone for your help!