I have a class that accepts an integer and runs it through a very simple "decode" algorithim and spits back out a string. I just need some help on how to input the integer to an field and return on rerender on CommandButton to an output field.
Here is what I have so far:
Page:
<apex:page controller="Decode">
<!-- Pass parameters from visualforce page to controller -->
<apex:form >
<apex:pageblock >
Input Here = <apex:inputText value="{!inputValue}"/>
<apex:commandButton value="Submit" reRender="outputID"/>
</apex:pageblock>
<apex:pageblock >
<b>Output here = </b>
<apex:outputText value="{!sPassowrd}" id="outputID">
</apex:outputText>
</apex:pageblock>
</apex:form>
</apex:page>
Controller:
public with sharing class Decode {
public static String Decode(Integer inputValue) {
String sPassword;
Integer iTemp;
Integer iChar;
String sChar;
Map<Integer,String> codeValues = new Map<Integer,String>();
codeValues.put(12,'A');
codeValues.put(28,'B');
codeValues.put(19,'C');
codeValues.put(5, 'D');
codeValues.put(24,'E');
codeValues.put(10,'F');
codeValues.put(1, 'G');
codeValues.put(17,'H');
codeValues.put(30,'I');
codeValues.put(27,'J');
codeValues.put(4, 'K');
codeValues.put(31,'L');
codeValues.put(8, 'M');
codeValues.put(33,'N');
codeValues.put(13,'O');
codeValues.put(36,'P');
codeValues.put(6, 'Q');
codeValues.put(21,'R');
codeValues.put(2, 'S');
codeValues.put(32,'T');
codeValues.put(15,'U');
codeValues.put(11,'V');
codeValues.put(22,'W');
codeValues.put(7, 'X');
codeValues.put(25,'Y');
codeValues.put(34,'Z');
codeValues.put(14,'1');
codeValues.put(23,'2');
codeValues.put(9, '3');
codeValues.put(16,'4');
codeValues.put(18,'5');
codeValues.put(3, '6');
codeValues.put(29,'7');
codeValues.put(26,'8');
codeValues.put(20,'9');
codeValues.put(35,'0');
For (Integer i = 0; i < 5 ; i++){
iTemp = inputValue/73;
iChar = (inputValue - (iTemp*73));
inputValue = iTemp;
sChar = codeValues.get(iChar);
if (String.isNotEmpty(sChar)){
if (String.isNotEmpty(sPassword)){
sPassword = (sChar + sPassword);
}
else {
sPassword = sChar;
}
}
}
return sPassword;
}
}
Working code for anyone interested:
public with sharing class Decode {
public String inputValue { get; set; }
public String sPassword { get; set; }
public void getDecode()
{
if (inputValue == null) return;
try
{
sPassword = decode(Integer.valueOf(inputValue));
}
catch (TypeException t)
{
ApexPages.addMessages(t);
}
}
public static String Decode(Integer inputValue) {
String sPassword;
Integer iTemp;
Integer iChar;
String sChar;
Map<Integer,String> codeValues = new Map<Integer,String>();
codeValues.put(12,'A');
codeValues.put(28,'B');
codeValues.put(19,'C');
codeValues.put(5, 'D');
codeValues.put(24,'E');
codeValues.put(10,'F');
codeValues.put(1, 'G');
codeValues.put(17,'H');
codeValues.put(30,'I');
codeValues.put(27,'J');
codeValues.put(4, 'K');
codeValues.put(31,'L');
codeValues.put(8, 'M');
codeValues.put(33,'N');
codeValues.put(13,'O');
codeValues.put(36,'P');
codeValues.put(6, 'Q');
codeValues.put(21,'R');
codeValues.put(2, 'S');
codeValues.put(32,'T');
codeValues.put(15,'U');
codeValues.put(11,'V');
codeValues.put(22,'W');
codeValues.put(7, 'X');
codeValues.put(25,'Y');
codeValues.put(34,'Z');
codeValues.put(14,'1');
codeValues.put(23,'2');
codeValues.put(9, '3');
codeValues.put(16,'4');
codeValues.put(18,'5');
codeValues.put(3, '6');
codeValues.put(29,'7');
codeValues.put(26,'8');
codeValues.put(20,'9');
codeValues.put(35,'0');
For (Integer i = 0; i < 5 ; i++){
iTemp = inputValue/73;
iChar = (inputValue - (iTemp*73));
inputValue = iTemp;
sChar = codeValues.get(iChar);
if (String.isNotEmpty(sChar)){
if (String.isNotEmpty(sPassword)){
sPassword = (sChar + sPassword);
}
else {
sPassword = sChar;
}
}
}
return sPassword;
}
}
<apex:page controller="Decode">
<!-- Pass parameters from visualforce page to controller -->
<apex:form >
<apex:pageblock >
Input Here = <apex:inputText value="{!inputValue}"/>
<apex:commandButton value="Submit" reRender="outputID" action="{!getDecode}"/>
</apex:pageblock>
<apex:pageblock >
<b>Output here = </b>
<apex:outputText value="{!sPassword}" id="outputID">
</apex:outputText>
</apex:pageblock>
</apex:form>
</apex:page>