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
krishna mohan 29krishna mohan 29 

can we get back given value in apex:inputfield after rerendering the output panel?

Hi all, 
I need inputfield capability to get given input even after it is rerendered(hidden or shown) onchange of picklist value.

like if option 'a' is selected in picklist, the apex:inputfield with type textarea is shown and user enters data, and selecting 'b' hides rerenders and hides the field, and again if 'a' is selected i need field shown with previously given data in the field.
Thanks in advance.
shankar sudalaimanishankar sudalaimani
Hi Krishna,
try this code
VisualForce:
<apex:page controller="Sample">
<apex:form >
<apex:actionFunction name="changeBoolCall" action="{!changeBool}"/>
    <apex:pageblock id="pg">
        <apex:pageblockSection >
            <apex:pageblockSectionItem >
                Select currency :
            </apex:pageblockSectionItem>
            <apex:pageblockSectionItem >
               <apex:selectList value="{!curency}" size="1" multiselect="false">
                   <apex:selectOption itemLabel="--- None ---" itemValue="none"/>
                   <apex:selectOption itemLabel="Indian Rupee" itemValue="inr"/>
                   <apex:actionSupport event="onchange" action="{!changeBool}" reRender="pg"/>
               </apex:selectList>
            </apex:pageblockSectionItem>           
            <apex:pageblockSectionItem >
                Enter the amount:
            </apex:pageblockSectionItem>     
            <apex:pageblockSectionItem >
               <apex:inputtext value="{!amount}" rendered="{!curencyBool}"/>
            </apex:pageblockSectionItem>                  
        </apex:pageblockSection>
    </apex:pageblock>
</apex:form>   
</apex:page>

Apex:
public class Sample
{
    public String curency {get;set;}
    public String amount {get;set;}
    public Boolean curencyBool {get;set;}
   
    public sample()
    {       
        curency = 'none';
        if(curency == 'none')
        {
         curencyBool = false;
        }   
    }
   
    public void changeBool()
    {       
        if(curency != 'none')
        {
            curencyBool = true;
        }
        else
        {
            curencyBool = false;
        }
    }
      
}
sfdc loginsfdc login
Hi krishna 
 
you can take reference of this code
as we can use rerender
 rendered="{!IF( Campaign.Primary_Campaign_Attribute__c == 'Religious Affiliation', true, false )}" >
 
<apex:page standardController="Campaign" showHeader="true" >
	<apex:form>
		<apex:outputPanel id="t1">
			<apex:pageBlock>
				<apex:pageBlockSection columns="2" title="Information">
					<apex:inputField value="{!Campaign.Name}" />
					<apex:inputField value="{!Campaign.StartDate}" />
					<apex:inputField value="{!Campaign.Status}" />
					<apex:inputField value="{!Campaign.Type}" />
					<apex:inputField value="{!Campaign.Primary_Campaign_Attribute__c}"> 
						<apex:actionSupport event="onchange" rerender="t1" />
					</apex:inputField>
				</apex:pageBlockSection>
				<apex:pageBlockSection columns="1" title="Primary Campaign">
					<apex:inputField value="{!Campaign.Primary_Campaign_Attribute_Religion__c}" rendered="{!IF( Campaign.Primary_Campaign_Attribute__c == 'Religious Affiliation', true, false )}" >
						<apex:actionSupport event="onchange" rerender="t1" />
					</apex:inputField>
					<apex:inputField value="{!Campaign.Primary_Campaign_Attribute_Christianity__c}" rendered="{!IF( Campaign.Primary_Campaign_Attribute_Religion__c == 'Christian', true, false )}" />
				</apex:pageBlockSection>
			</apex:pageBlock> 
		</apex:outputPanel>
	</apex:form>
</apex:page>
krishna mohan 29krishna mohan 29
Thank you Shankar,
I had tried similar one but can we do that if we are using action:region to process request for the picklist.
krishna mohan 29krishna mohan 29
<apex:page controller="Sampletestfiel">
<apex:form >
<apex:actionFunction name="changeBoolCall" action="{!changeBool}"/>
    <apex:pageblock id="pg">
        <apex:pageblockSection >
            <apex:pageblockSectionItem >
                Select currency :
            </apex:pageblockSectionItem>
            <apex:pageblockSectionItem ><apex:actionRegion >
               <apex:selectList value="{!curency}" size="1" multiselect="false">
                   <apex:selectOption itemLabel="--- None ---" itemValue="none"/>
                   <apex:selectOption itemLabel="Indian Rupee" itemValue="inr"/>
                   <apex:selectOption itemLabel="Chinese Rupee" itemValue="inr2"/>

                   <apex:actionSupport event="onchange" action="{!changeBool}" reRender="pg"/>
               </apex:selectList></apex:actionRegion>
            </apex:pageblockSectionItem>           
            <apex:pageblockSectionItem >
               
            </apex:pageblockSectionItem>     
            <apex:pageblockSectionItem >
               <apex:inputfield value="{!sample.amount}" rendered="{!curencyBool}"/>
            </apex:pageblockSectionItem>                  
        </apex:pageblockSection>
    </apex:pageblock>
</apex:form>   
</apex:page>

When trying with similar code using input field and action region  the value is refreshing and not returning to the field.
shankar sudalaimanishankar sudalaimani
Hi,
Ya,if you are using the action region it particularly refresh the values so it clear the value.then we have two chances.one is prior value in workflow another one is view state in vf and apex.