This content has been marked as final.
Show 3 replies
-
1. Re: How to mask credit card output?
fhh Aug 16, 2007 7:05 PM (in response to toddh)Why don't yu simply add another getter to your bean that returns the masked CC number.
Regards
Felix -
2. Re: How to mask credit card output?
matt.drees Aug 16, 2007 7:23 PM (in response to toddh)Just because I'm probably going to use one at some point...
import java.io.Serializable; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.convert.Converter; import org.jboss.seam.annotations.Logger; import org.jboss.seam.annotations.Name; import org.jboss.seam.log.Log; /** * Just for h:outputText components * @author Matthew.Drees * */ @Name("creditCardMaskingConverter") @org.jboss.seam.annotations.faces.Converter public class CreditCardMaskingConverter implements Converter, Serializable { private static final long serialVersionUID = 1L; @Logger Log log; String pattern = "1111********1111"; public Object getAsObject(FacesContext context, UIComponent component, String value) { throw new UnsupportedOperationException(); } public String getAsString(FacesContext context, UIComponent component, Object value) { log.trace("getting #0 as String", value); if (value == null) { throw new IllegalArgumentException("value to convert is null"); } String toString = value.toString(); assertValidity(toString); StringBuilder sb = new StringBuilder(); for(int i = 0; i < 16; i++) { if (pattern.charAt(i) == '*') { sb.append('*'); } else { sb.append(toString.charAt(i)); } } return sb.toString(); } private void assertValidity(String string) { if (string.length() != 16) { throw new IllegalArgumentException("not a 16-digit string: " + string); } } /** * A 16-character string indicating the masking pattern. A '*' at index i means * the converted output will have a '*' at index i. * @param pattern */ public void setPattern(String pattern) { assertValidity(pattern); this.pattern = pattern; } public String getPattern() { return pattern; } public Log getLog() { return log; } public void setLog(Log log) { this.log = log; } }
-
3. Re: How to mask credit card output?
toddh Aug 20, 2007 6:05 PM (in response to toddh)Thanks Matt! That's perfect.