|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.click.control.AbstractControl
org.apache.click.control.Field
org.apache.click.control.TextField
org.apache.click.extras.control.CreditCardField
public class CreditCardField
Provides a Credit Card control: <input type='text'><select>.
Credit Card |
PageImports
object in the page template.
<html> <head> $cssImports </head> <body> $form </body> </html> $jsImportsAn example page using CreditCardField is provided below:
public class PaymentPage extends Page { private Form form = new Form("form"); private CreditCardField creditCardField = new CreditCardField("creditCard", true); private IntegerField expiryField = new IntegerField("expiryDate", true); public PaymentPage() { form.add(creditCardField); expiryField.setMinLength(4); expiryField.setMaxLength(4); expiryField.setSize(4); form.add(expiryField); form.add(new Submit("ok", " OK ")); form.add(new Submit("cancel", this, "onCancelClick")); addControl(form); } public boolean onCancelClick() { setRedirect("index.htm"); return false; } public void onPost() { if (form.isValid()) { String cardType = creditCardField.getCardType(); Long cardNumber = creditCardField.getCardNumber(); String expiryDate = expiryField.getInteger(); // Make payment .. } } }See also W3C HTML reference INPUT
Field Summary | |
---|---|
static String |
AMEX
The American Express type credit card: "AMEX". |
protected static List |
CARD_OPTIONS
The statically initialized card type options list. |
protected String |
cardType
The type of credit card: ["VISA" | "MASTER" | "AMEX" | "DINERS" | "DISCOVER"]. |
protected Select |
cardTypeSelect
The card type Select. |
static String |
DINERS
The Diners Club type credit card: "DINERS". |
static String |
DISCOVER
The Discovery type credit card: "DISCOVER". |
static String |
HTML_IMPORTS
The CreditCardField imports statement. |
static String |
MASTER
The MasterCard type credit card: "MASTER". |
protected static String |
SELECT_NAME
The card type Select name. |
protected static String |
VALIDATE_CREDITCARD_FUNCTION
The field validation JavaScript function template. |
static String |
VISA
The Visa type credit card: "VISA". |
Fields inherited from class org.apache.click.control.TextField |
---|
maxLength, minLength, size, VALIDATE_TEXTFIELD_FUNCTION |
Fields inherited from class org.apache.click.control.Field |
---|
disabled, error, focus, form, help, label, readonly, required, tabindex, title, validate, value |
Fields inherited from class org.apache.click.control.AbstractControl |
---|
actionListener, attributes, headElements, listener, listenerMethod, messages, name, parent, styles |
Fields inherited from interface org.apache.click.Control |
---|
CONTROL_MESSAGES |
Constructor Summary | |
---|---|
CreditCardField()
Create a credit card field with no name defined. |
|
CreditCardField(String name)
Construct the credit card field with the given name. |
|
CreditCardField(String name,
boolean required)
Construct the credit card field with the given name and required status. |
|
CreditCardField(String name,
String label)
Construct the credit card field with the given name and label. |
|
CreditCardField(String name,
String label,
boolean required)
Construct the credit card field with the given name, label and required status. |
Method Summary | |
---|---|
void |
bindRequestValue()
Bind the request submission, setting the value property and cardType property if defined in the request. |
Long |
getCardNumber()
Return the Credit Card number. |
String |
getCardType()
Return the selected Credit Card type: [ "VISA" | "MASTER" | "AMEX" | "DINERS" | "DISCOVER" ]. |
int |
getControlSizeEst()
|
String |
getHtmlImports()
Return the HTML head import statements for the CreditCardField.js. |
String |
getValidationJavaScript()
Return the field JavaScript client side validation function. |
void |
onDeploy(ServletContext servletContext)
Deploy the extras-control.js file to the click web directory when the application is initialized. |
void |
render(HtmlStringBuffer buffer)
Render the HTML representation of the CreditCardField. |
void |
validate()
Validate the CreditCardField request submission, using the card type to validate the card number. |
Methods inherited from class org.apache.click.control.TextField |
---|
getMaxLength, getMinLength, getSize, getTag, getType, setMaxLength, setMinLength, setSize |
Methods inherited from class org.apache.click.control.Field |
---|
getError, getErrorLabel, getFocus, getFocusJavaScript, getForm, getHelp, getId, getLabel, getRequestValue, getTabIndex, getTextAlign, getTitle, getValidate, getValue, getValueObject, getWidth, isDisabled, isHidden, isReadonly, isRequired, isValid, onInit, onProcess, setDisabled, setError, setErrorMessage, setErrorMessage, setErrorMessage, setErrorMessage, setFocus, setForm, setHelp, setLabel, setListener, setParent, setReadonly, setRequired, setTabIndex, setTextAlign, setTitle, setValidate, setValue, setValueObject, setWidth |
Methods inherited from class org.apache.click.control.AbstractControl |
---|
addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getContext, getHeadElements, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, hasAttribute, hasAttributes, hasStyles, onDestroy, onRender, removeStyleClass, renderTagBegin, renderTagEnd, setActionListener, setAttribute, setId, setName, setStyle, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String VISA
public static final String MASTER
public static final String AMEX
public static final String DINERS
public static final String DISCOVER
protected static final List CARD_OPTIONS
protected static final String SELECT_NAME
protected static final String VALIDATE_CREDITCARD_FUNCTION
public static final String HTML_IMPORTS
protected String cardType
protected Select cardTypeSelect
Constructor Detail |
---|
public CreditCardField(String name)
name
- the name of the fieldpublic CreditCardField(String name, String label)
name
- the name of the fieldlabel
- the label of the fieldpublic CreditCardField(String name, boolean required)
name
- the name of the fieldrequired
- the field required statuspublic CreditCardField(String name, String label, boolean required)
name
- the name of the fieldlabel
- the label of the fieldrequired
- the field required statuspublic CreditCardField()
Method Detail |
---|
public String getCardType()
public Long getCardNumber()
public String getHtmlImports()
getHtmlImports
in interface Control
getHtmlImports
in class AbstractControl
public void bindRequestValue()
cardType
property if defined in the request.
bindRequestValue
in class Field
public int getControlSizeEst()
getControlSizeEst
in class TextField
AbstractControl.getControlSizeEst()
public void render(HtmlStringBuffer buffer)
render
in interface Control
render
in class TextField
buffer
- the specified buffer to render the control's output toAbstractControl.toString()
public String getValidationJavaScript()
getValidationJavaScript
in class TextField
public void validate()
- /click-control.properties
- field-maxlenght-error
- field-minlength-error
- field-required-error
- /org/apache/click/extras/control/CreditCardField.properties
- creditcard-number-error
validate
in class TextField
public void onDeploy(ServletContext servletContext)
onDeploy
in interface Control
onDeploy
in class AbstractControl
servletContext
- the servlet contextControl.onDeploy(ServletContext)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |