+ Start a Discussion
Chris VogeChris Voge 

Clearing Transient form data after page submission


I have some input text fields inside a form and on the controller
class I have these fields set as Transient so they are not part of
the ViewState.

What I want is for these fields to clear out when a user hits a
"Clear" button. This is not happening. Instead, the values from the
previous submit are put back into the fields.

I would not expect this if the fields were Transient.

What am I missing ?

Hello Chris,

I have implemeneted the same functionality as said by you.

I have taken 4 input text fields & one command button on Visualforce Page named as Clear. I have created on method in the custom controller with the page in which i clear those values.

Also, I have re rendred the form so that the form gets refereshed. The binding I have done is with transient variable. Please let me know, if this worked ?
Here, is the attached code... 

<apex:page Controller="myControllerNew1" showHeader="true">
<apex:form id="frm" >
<apex:commandButton action="{!clear}" value="Clear" reRender="frm"/>
 <apex:inputText value="{!value1}" label="Field 1"/>
 <apex:inputText value="{!value2}" label="Field 2"/>
 <apex:inputText value="{!value3}" label="Field 3"/>
 <apex:inputText value="{!value4}" label="Field 4"/>


public class myControllerNew1{

    public transient string value1{get;set;}
    public transient string value2{get;set;}
    public transient string value3{get;set;}
    public transient string value4{get;set;}
    public void clear(){
        value4 = '';
        value3 = '';
        value2 = '';
        value1 = '';


Hope this fulfills your requirement.

Important :

Mark this solution as the Best Answer, if this post provides you with useful information and if this is what you where looking for then please mark it as a solution for others benefits.

Thank You