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
Sandy singhSandy singh 

filed value change at run time read mode or edit mode

Hi All,

 

 I need to access address variable in visual force page, so that if address is have some value its display as output text &

if it has null value in controller it display blank as a input textArea field in visual page. My Controller is below.

 

class myController {

public myController(){this.address='my address' ;}

public String address{ set(this.address=address;}

get(

if(address!=null)  return address ; else{address=null; return address;}

}

}

 

Please help me on this requirement. 

 

Thanks in advance,

Sandy

 

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

 

You can try below code snippets

 

<apex:page controller="myController" >
<apex:form >
    <div id="foroutputtext">
		<apex:outputText value="{!address}"></apex:outputText>
    </div>
    <div id="forinputputtext">
		<apex:inputtextarea value="{!address}"/>
    </div>
</apex:form>
<script>
 var addressvalue='{!address}';
	if(addressvalue.length>0)
	{
		document.getElementById("forinputputtext").style.display='none';
	}
	else
	{
		document.getElementById("foroutputtext").style.display='none';
	}
</script>
</apex:page>

 Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

 

You can try below code snippets

 

<apex:page controller="myController" >
<apex:form >
    <div id="foroutputtext">
		<apex:outputText value="{!address}"></apex:outputText>
    </div>
    <div id="forinputputtext">
		<apex:inputtextarea value="{!address}"/>
    </div>
</apex:form>
<script>
 var addressvalue='{!address}';
	if(addressvalue.length>0)
	{
		document.getElementById("forinputputtext").style.display='none';
	}
	else
	{
		document.getElementById("foroutputtext").style.display='none';
	}
</script>
</apex:page>

 Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

This was selected as the best answer
JPClark3JPClark3

I think this will work also:

<apex:form >
<apex:pageBlock>
<apex:pageBlockSection>
<apex:outputText value="{!address}" rendered="{!address != null}"/>
<apex:inputtextarea value="{!address}"  rendered="{!address == null}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

 Controller:

class myController {
public myController()
  {this.address='my address' ;}
public String address { get; set; }
}
}

 

Sandy singhSandy singh

Thanks Clark,

 Your solution is perfect for my requirement.