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
Sibasish PanigrahiSibasish Panigrahi 

Re-render issue (JS wipes off and also doesn't display data from controller)

I have a vf page where i'm fetching data from controller.
I face issue when i click  on a button and the panel get refreshed. After refresh i sometime get's the data on vf page from controller and sometimes not, but in debug i always get the required data in controller. If my data doesn't show up, i refresh the whole page 2-3 times and then again click the button and the required data get's displayed. But after 1-2 times it again fails to do the same and i have to repeat the procedure again.

It's wierd and also i'm not getting how to solve it and also unable to get the root cause.

Thanks.
Sampath SuranjiSampath Suranji
Hi,
Can you please share your code
Sibasish PanigrahiSibasish Panigrahi
Hi Sampath,

Below is the partial code of that particular panel which gives this wierd bug.
<apex:actionFunction name="reply" action="{!activeReply}" rerender="sendPanel"/>

<apex:outputPanel id="sendPanel">
	
	<apex:outputPanel rendered="{!reply}">
		<apex:outputPanel id="replyId">
			<div class="form-group row margin-bottom-5">
				<label class="control-label col-sm-1 no-padding-right"> <button class="btn btn-default btn-xs" data-toggle="modal" data-target="#myModal" onclick="getWrp('sendTo')">To...</button></label> 
				<div class="col-sm-11 input-group-xs-custom ">
					<apex:inputText value="{!replyTo}" styleClass="form-control" id="testReply"/>
					<apex:outputPanel rendered="{!validEmailType}">
						<b>Error:</b> Enter valid Email Id
					</apex:outputPanel>
				</div>
			</div>
			<div class="form-group row margin-bottom-5">
				<label class="control-label col-sm-1 no-padding-right"> <button class="btn btn-default btn-xs" data-toggle="modal" data-target="#myModal" onclick="getWrp('sendCc')">Cc...</button></label> 
				<div class="col-sm-11 input-group-xs-custom ">
					<apex:inputText value="{!replyCc}" styleClass="form-control"/>                                                                
				</div>
			</div>
			<div class="form-group row">
				<label class="control-label col-sm-1 no-padding-right">Subject</label> 
				<div class="col-sm-11 input-group-xs-custom ">
					<apex:inputText value="{!replySubject}" styleClass="form-control"/>
					<apex:outputPanel rendered="{!checkSubjectEntered}">
						<b>Error:</b> You must enter a value
					</apex:outputPanel>
				</div>
			</div>
			<div class="form-group row">
				<label class="control-label col-sm-1 no-padding-right">Urgency</label> 
				<div class="col-sm-11 input-group-xs-custom ">
					<apex:inputField value="{!createEmail.Urgency__c}" styleClass="form-control form-control-static"/>
					<!-- <div class="form-control form-control-static">High</div> -->
				</div>
			</div>
			<!-- <div class="form-group row">
				<label class="control-label col-sm-1 no-padding-right">Type</label> 
				<div class="col-sm-11 input-group-xs-custom ">
					<div class="row">
						<apex:selectList id="msgType1" size="1" style="margin-left: 15px; width:32%;margin-left: 105px;font-size: 12px;height: 30px;padding: 5px 10px;line-height: 1.5;border-radius: 3px;display: block;border: 1px solid #ccc;" styleClass="form-control">
							
							<apex:selectOption itemValue="" itemLabel="--Select--"/>
							<apex:selectOptions value="{!items}"/>
						</apex:selectList><p/>
					</div>
				</div>
			</div> -->
		</apex:outputPanel>
	</apex:outputPanel>
</apex:outputPanel>

The {!replyTo} and  {!replyCc} is getting displayed sometime and sometime it shows empty, even though the value of those to variables are coming in controller in debug.

Thanks.
Sampath SuranjiSampath Suranji
Hi,

Cannot get fully idea without seeing the full code. I guess when you click on a button you may call js function and then you call an action function.
inside the action function mention the particular output panel Id which you need to refresh inside the "reRender" attribute.

 
Sibasish PanigrahiSibasish Panigrahi
Hi,

Sorry for the trouble, but the whole code is more than 2k lines and i don't have the auth to show the code too.
You are right, when we click a button, it calls a JS function and then action function is called. I checked it and the panel Id is correct in "reRender" attribute. And also it also works sometimes, displaying the desired output in that particular panel.

Issue is we aren't sure why it's not working always and why just sometime even though we are getting the value of that particular variable in the controller funtion {!activeReply} all the time when it's executed on call action function.

Hope this gives a bit clear idea of what the actual issue is.


Thanks.
Sampath SuranjiSampath Suranji
Hi,
Ok.. I guess your page get post back when you click on button. Just try to call the js function by adding 'return flase'. then it is avoiding the fully page reload.

onclick="getWrp('sendCc');return false;"

regards
 
Sibasish PanigrahiSibasish Panigrahi
Hi,
I tried with "return false;" but still the issue continues.

Thanks.
Sampath SuranjiSampath Suranji
Hi,
Did you mean that it is not rerender the panel when you click a button which is inside the panel or the button is belongs to other panel?
Is 'sendPanel' not renderring totally or it is rendering but not refreshing?
Here is a sample code which I created by your code given and it is working for me.
<apex:page controller="devForumController">
    <script>
    function getWrp(val){
        reply();
    }
    
    </script>
    <apex:form >
        <apex:actionFunction name="reply" action="{!activeReply}" rerender="sendPanel"/>
        <apex:actionFunction name="testFunction" action="{!activeReply1}" rerender="testPanel"/>
        
        <apex:outputPanel id="testPanel">
             <apex:inputText value="{!replyTo1}" styleClass="form-control" />
            <button class="btn btn-default btn-xs" data-toggle="modal"  onclick="testFunction();return false;">Test btn</button>
        </apex:outputPanel>
        
        <apex:outputPanel id="sendPanel">
            
            <apex:outputPanel rendered="{!reply}">
                <apex:outputPanel id="replyId">
                    <div class="form-group row margin-bottom-5">
                        <label class="control-label col-sm-1 no-padding-right">
                            <button class="btn btn-default btn-xs" data-toggle="modal" data-target="#myModal" onclick="getWrp('sendTo');return false;">To...</button></label> 
                        <div class="col-sm-11 input-group-xs-custom ">
                            <apex:inputText value="{!replyTo}" styleClass="form-control" id="testReply"/>
                            <apex:outputPanel rendered="{!validEmailType}">
                                <b>Error:</b> Enter valid Email Id
                            </apex:outputPanel>
                        </div>
                    </div>
                    <div class="form-group row margin-bottom-5">
                        <label class="control-label col-sm-1 no-padding-right"> 
                            <button class="btn btn-default btn-xs" data-toggle="modal" data-target="#myModal" onclick="getWrp('sendCc');return false;">Cc...</button></label> 
                        <div class="col-sm-11 input-group-xs-custom ">
                            <apex:inputText value="{!replyCc}" styleClass="form-control"/>                                                                
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="control-label col-sm-1 no-padding-right">Subject</label> 
                        <div class="col-sm-11 input-group-xs-custom ">
                            <apex:inputText value="{!replySubject}" styleClass="form-control"/>
                            <apex:outputPanel rendered="{!checkSubjectEntered}">
                                <b>Error:</b> You must enter a value
                            </apex:outputPanel>
                        </div>
                    </div>
                   
                   
                </apex:outputPanel>
            </apex:outputPanel>
        </apex:outputPanel>
    </apex:form>
    
</apex:page>
public class devForumController {
    
    public boolean reply{get;set;}
    public string  replyTo{get;set;}
    public string replyTo1{get;set;}
    public string replyCc{get;set;}
    public string replySubject{get;set;}
    public boolean validEmailType{get;set;}
    public boolean checkSubjectEntered{get;set;}
    
    public devForumController(){
        reply = true;
    }
    public void activeReply(){
        system.debug('called reply');
        reply = true;
        replyTo = replyTo + ' updated';
        replyCc = replyCc + ' updted';
        
    }
    public void activeReply1(){
        system.debug('called reply1');
        replyTo1 = replyTo1 + ' updated';
        reply = false;
        
    }
    
}


 
Sibasish PanigrahiSibasish Panigrahi
Hi,
The button is in another pannel and you are right, 'sendPanel' is rendering but the values are not refreshing with new one's.
 
public void activeReply() 
{ 
    reply = true; 
    Property_Email_Items__c emailItem = [Select Id, Name, Send_To__c From 
                                                  Property_Email_Items__c Where Id =: '{{someId}}'];
    replyTo = emailItem.Send_To__c; 
    system.debug('replyTo: '+replyTo);
}

In constructor, the value of replyTo is given null. (replyTo is String).
Only in activeReply it's values are populated.
Whenever the code executes the replyTo values can be seen in system debug always but not in vf page always. Sometimes it shows and sometimes it doesn't.

Sorry if i'm unable to clear things well.


Thanks.
Sampath SuranjiSampath Suranji
Hi,

I'm sorry to say that I'm unable to find a solution without seeing the full code.
Here is my email( sampathjt@gmail.com). If you are Ok to share the VF/Apex code, please email it to me.

regards
Sibasish PanigrahiSibasish Panigrahi
Hi,

I have mailed you. Can you please check once?

Thanks.