2

I have an apex:dynamicComponent binded to a pageBlock. In the apex controller, I add dynamic apex components like text boxes, checkboxes and command buttons to a dynamic panelGrid and then add the panel grid to the pageBlock binded to the apex:dynamicComponent.

In a certain case when i click a button (the remove button) present in the dynamic pageBlock I need to remove certain components(textboxes and other fields) rendered on the screen. For doing this, I used an apex action function which is called on click of the 'remove' button. And the action function called another apex function which is supposed to do the do the removing of certain UI components based on the id of the button which is passed as a parameter by the action function.

In this function when I try to access the dynamic pageBlock (which is declared as a public transient data member of the apex controller) I get a reference to null error. Basically the pageBlock value is null.

But when i try to access the dynamic pageBlock in an access function called on a click of a button that is not present within the same dynamic pageBlock but outside the pageBlock, I don't get that error and am able to access its components and values.

Is there any solution to this problem?

I want to access the rendered pageBlockPanel in an action function called from a button click within the panel itself. After I can access the pageBlockPanel, I can remove certain UI Components from it nad then re-Render the pageBlockPanel with only the required values.

Visualforce page having a binding to the apex variable 'pageBlockPanel'.

<apex:dynamicComponent componentValue="{!pageBlockPanel}" id="interviewPanel" />

Declaration of the variable in Apex.

public transient Component.Apex.pageBlock pageBlockPanel{get;set;}

2

These dynamic components can't be made part of the view state (unlike their static tag-based counterparts) because they are not serializable (by design according to Salesforce support). This means that e.g. when there are errors on fields the behaviour you get is not perfect. And it drives the need for the reference being transient.

Consequently the Apex function that "do(es) the removing of certain UI components based on the id of the button" will have to rebuild the dynamic component tree from scratch (and leave out the relevant UI components in the process) because your pageBlockPanel field will be null. Hopefully you will not lose too much state in the process.

I've used these components in one application and would not use them again.

I do not understand why your logic works in one case and not the other though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.