You need to sign in to do that
Don't have an account?
How to remove pageBlockSection dynamically?
Hey Guys here's my question:
I have a pageBlock in which I have a repeat tag which dynamically creates pageBlockSections for each record I retrieve in the function call I make in the repeat tag.
What I would like to be able to do, is be able to click on a checkbox, or button at the end of pageblocksection and when clicked, remove that pageblocksection and rerender the pageBlock (hence calling the repeat tag and redrawing the pageBlockSections minus the one just removed).
I'm not sure how to make the checkBoxes bind to the specific record the pageBlockSection it is attached to, I was thinking of making the ID of each pageBlockSection the recordID but you can't seem to set ID values from a getterMethod in your controller.
Any help or guidance is greatly appreciated.
Thank's!
You will probably have to create a wrapper class for your records, then have a boolean variable in there together with your record:
public class myRecord { public Boolean isVisible {get; set;} private SObject record; ... }
The only problem I can see from this would be that since you're using different object types you might have to have a getter method for each object type that converts 'record' into whatever you're using (unsure if this would work) or have lots of variables in this class for each of your object types.
You would then use isVisible for your checkboxes and use rendered="{!isVisible}" for your page block sections. That's the best solution I can think of at this moment.
Thank's for replying Xactium,
Not sure if I understand what you mean... I could build a wrapper class and have a boolean, my main SObject, and it's related types within the wrapper, but then how does this wrapper help me achieve my desired result?
To see if I follow correctly, the checkbox on each pageBlockSection will have to be attached to a method in my controller which sets the isVisible boolean to false (for that particular object the pageSection is displaying) and then I reRender the the pageSections which will go through my repeat tag, which will go through each wrapper obiject check the isVisible flag and only return those values that are FALSE for this flag?
How do I make it so that when I check the checkBox that the particular myRecord object whose isVisible will be set to true, pertains to the same one the checkBox is pertaining to? I don't understand how that will work.
My apologies, still trying to get the hang of this VF stuff =\
Appreciate your patience!
You can use the apex tag inputCheckbox to tie the checkbox to each of the variables. So what you would have is something like this:
// CONTROLLER public void getRecords() { List<myRecord> records = new List<myRecord>(); records.add(new myRecord(myobj)); // Each item in the list will pertain to a pageblocksection } // PAGE <apex:pageBlock id="pb"> <apex:repeat value="{!records}" var="r"> <apex:inputCheckbox value="{!r.isVisible}"> <apex:actionSupport event="onclick" reRender="pb" /> </apex:inputCheckbox> <apex:pageBlockSection rendered="{!r.isVisible}"> <!-- Enter my field data here --> </apex:pageBlockSection> </apex:repeat> </apex:pageBlock>
I haven't tested this code out but hopefully you'll know what I mean a little better from it.
My apologies Xactium,
I knew what you meant about the inputCheckbox and adding the method call from within the repeat tag.
My question is that where do you now set the isInvisible to false? From my understanding in your code when you click on a checkbox, the pageBlock will get created again. But I don't see where you are setting an individual pageBlockSection's "isVisible" value to false?
That is what I am trying to understand right now. so even though we're dynamically creating a list of pageblockSections, we can still invoke actions on each SObject the pageBlockSection is tied to in the controlle.
In this case on the event that we click on the checkbox, the controller method should get called which would (for this particular recordObject, set it's isVisible value to false or remove it from the list of records entirely and then reRender the pb so that it should no longer have a pageBlockSection.
I hope that is clearer.
Thank's for all the help, I appreciate it!