Last active
August 29, 2015 14:11
-
-
Save amonshiz/8764c2348f9b12fe21dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class DataWrapper { | |
public Object value { get; set; } | |
public DataWrapper() {} | |
public DataWrapper(Object theValue) { | |
value = theValue; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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