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
Salvatore ParacuolloSalvatore Paracuollo 

Rerender Visualforce Dynamic Component

Hi all,
I'm trying to rerender a visualforce dynamic component in my visualforce page on the onclick button event: I tried with a remote action on a button tag element (I'd like to avoid the form element on Vf page for view state problems) and it didn't work; so I tried with an apex button element, too, but no luck: can anyone help me? thanks

This is the code:

- Controller:
public class provaController{
    public boolean var{get; set;}    
    public integer count;
    
    public provaController(){
        var = false;
        count = 0;
    }
    
    public void add(){
        var = true;
    }
    
    public Component.Apex.OutputText getThePanel() { 
        system.debug('****panel');
        count++;       
        String stringaFinale = '<p>first call</p>';                 
        if(count>1) stringaFinale = stringaFinale +  '<p>second call</p>';
        
        Component.Apex.OutputText outTextGlobal = new Component.Apex.OutputText();
        outTextGlobal.value = stringaFinale;
        outTextGlobal.escape = false;

        stringaFinale = null;
        return outTextGlobal;
    }
         
    @RemoteAction
    global static void click() {
        system.debug('****remote');
    }
}

- Vf page:
<apex:page controller="provaController" id="idController" >   
    <div  id="provaDiv" >
        <apex:dynamicComponent componentValue="{!thePanel}" invokeAfterAction="true"/>   
    </div>
    
    <apex:form >
        <apex:commandButton action="{!add}" value="button" id="theButton" reRender="idController,provaDiv"/>
    </apex:form>  
</apex:page>
Best Answer chosen by Salvatore Paracuollo
William LópezWilliam López
Hello Salvatore,

I would say Add a new outputPanel and that should fix the issue.
 
<apex:page controller="provaController" id="idController" >  
	
	<apex:outputPanel id="mainPanel">
	
		<div  id="provaDiv" >
			<apex:dynamicComponent componentValue="{!thePanel}" invokeAfterAction="true"/>   
		</div>
		
		<apex:form >
			<apex:commandButton action="{!add}" value="button" id="theButton" reRender="mainPanel"/>
		</apex:form>  
	
	</apex:outputPanel>
	
</apex:page>
Then just change the method in the controller.
 
public PageReference Add(){     
     var = true;
      return null;
  }

That should do the trick.

An outputPanel its the same as using a HTML div,or span and its the component that should be used when you need AJAX Refreshes, so you can also change the <div id="provaDiv" > that you have for an <apex:outputPanel>

Please let me know how it goes.

Regards,

​Don't forget to mark your thread as 'SOLVED' with the answer that best helps you. 
 

All Answers

AMIT KAMBOJAMIT KAMBOJ
Please try to use this below VF page. If this solves your issues please  mark this answer as solution.

FYI : I added $Component
<apex:page controller="provaController" id="idController" >   
    <div  id="provaDiv" >
        <apex:dynamicComponent componentValue="{!thePanel}" invokeAfterAction="true"/>   
    </div>
    
    <apex:form >
        <apex:commandButton action="{!add}" value="button" id="theButton" reRender="$Component.idController,provaDiv"/>
    </apex:form>  
</apex:page>

 
William LópezWilliam López
Hello Salvatore,

I would say Add a new outputPanel and that should fix the issue.
 
<apex:page controller="provaController" id="idController" >  
	
	<apex:outputPanel id="mainPanel">
	
		<div  id="provaDiv" >
			<apex:dynamicComponent componentValue="{!thePanel}" invokeAfterAction="true"/>   
		</div>
		
		<apex:form >
			<apex:commandButton action="{!add}" value="button" id="theButton" reRender="mainPanel"/>
		</apex:form>  
	
	</apex:outputPanel>
	
</apex:page>
Then just change the method in the controller.
 
public PageReference Add(){     
     var = true;
      return null;
  }

That should do the trick.

An outputPanel its the same as using a HTML div,or span and its the component that should be used when you need AJAX Refreshes, so you can also change the <div id="provaDiv" > that you have for an <apex:outputPanel>

Please let me know how it goes.

Regards,

​Don't forget to mark your thread as 'SOLVED' with the answer that best helps you. 
 
This was selected as the best answer