You need to sign in to do that
Don't have an account?
Compare string with numeric values, java.lang.NumberFormatException error
Hi Folks, I am stumped and have been looking at this too long. Any help is very much appreciated.
I would like to compare the numeric portion of a string to the numeric portion of another string in a VF page. I am able to use the replaceAll method in APEX without an issue, like this...
if(integer.valueOf(Custom_Textfield_A__c.replaceAll('\\D','')) > integer.valueOf(Custom_Textfield_B__c.replaceAll('\\D',''))) //TODO some field updates here;
I am attempting to compare the same two fields in a VF page to determine whether to highlight a row or not. This is what I was attempting, but without success...
<apex:repeat rows="5" value="{!getLines}" var="l"> <tr> <div style="{!if(value(l.Custom_Textfield_A__c) > value(l.Custom_Textfield_B__c),'background-color:#F3F781','')};"> <td valign="center" width="220px"> <apex:outputText value="{!l.Name}" /> </td> <td valign="center" align="center"> <apex:outputText value="{0}"> <apex:param value="{!Left(l.Line_Type__c,1)}" /> </apex:outputText> </td> <td class="tdv"> <apex:outputField value="{!l.Custom_Textfield_A__c}" /> </td> </div> </tr> </apex:repeat>
The issue arises in the VF page because I cannot determine how to remove the non-numeric characters from the text field and it fails with a java.lang.NumberFormatException. I am not able to switch these fields to numeric due to business requirements, so I am hoping there is an equivalent solution in VF to what I was able to do in APEX.
Steven
I can't think of how you'd do this using formulas. I'd suggest that you create a class that wraps the custom object and provides additional methods. That way you can return a list of the wrapper class rather than your custom object, and have a method called something like "getHighlight()" that returns true if textfield A is greater than textfield B.
All Answers
I can't think of how you'd do this using formulas. I'd suggest that you create a class that wraps the custom object and provides additional methods. That way you can return a list of the wrapper class rather than your custom object, and have a method called something like "getHighlight()" that returns true if textfield A is greater than textfield B.
Thanks for the guidance, Bob. I fumbled my way through learning how to create a rudimentary wrapper class with some success but it seemed a bit convoluted. I likely made it way more complex than it needed to be. Ultimately, I added an attribute to the object that indicated whether the record needed to be highlighted or not. At this stage I only needed a binary solution for this scenario, so adding the attribute worked for now.
That being said, I am going to use your suggestion and implement a wrapper class because I will eventually need to have more conditional control of the VF display and your advice is the best approach. Thanks again.
Steven