Skip to content

Instantly share code, notes, and snippets.

@amonshiz
Last active August 29, 2015 14:11
Show Gist options
  • Save amonshiz/8764c2348f9b12fe21dc to your computer and use it in GitHub Desktop.
Save amonshiz/8764c2348f9b12fe21dc to your computer and use it in GitHub Desktop.
public with sharing class DataWrapper {
public Object value { get; set; }
public DataWrapper() {}
public DataWrapper(Object theValue) {
value = theValue;
}
}
<apex:component controller="NameInputTextComponentController">
<apex:attribute name="value" assignTo="{!theValue}" description="Wrapped value" type="DataWrapper" required="true" />
<apex:form >
<apex:inputText value="{!name}" id="__inputTextComponent">
<apex:actionSupport event="onblur" action="{!formatName}" reRender="__inputTextComponent" />
</apex:inputText>
</apex:form>
</apex:component>
public with sharing class NameInputTextComponentController {
public NameInputTextComponentController() {}
public DataWrapper theValue { get; set; }
public String name {
get {
return (String)theValue.value;
}
set {
System.debug('the new value : ' + value);
theValue.value = value;
}
}
public PageReference formatName() {
List<String> splits = name.split(' ');
List<String> capitalizedSplits = new List<String>();
for (String s : splits) {
capitalizedSplits.add(s.capitalize());
}
name = String.join(capitalizedSplits, ' ');
return null;
}
}
<apex:page controller="NameInputTextPageController" showHeader="true" sidebar="true">
<c:NameInputTextComponent value="{!theName}" id="nameComponent" />
<apex:pageMessages id="messages" />
<apex:form>
<apex:commandButton action="{!empty}" reRender="nameComponent, messages" value="Rerender" />
</apex:form>
</apex:page>
public with sharing class NameInputTextPageController {
public NameInputTextPageController() {}
public DataWrapper theName {
get {
if (theName == null) {
theName = new DataWrapper('First Name');
}
return theName;
}
set;
}
public PageReference empty() {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, (String)theName.value));
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment