Thursday, September 6, 2012

How to create a form using ATG Framework



A Form is collection of components i.e input controls such as text box, radio button.... Web Applications require forms to get input from the user. For e.g You might need user information to register to your website or credentials to log in to your website... In this article, Let us see how to create a form using ATG(ART TECHNOLOGY GROUP). A Form can be created in ATG as shown below.
<dsp:form action=”simple.jsp” method=”post”>
<dsp:input type=”text” name=”Emp_name” bean=”/com/src/Employee.empname”/>
<dsp:input type=”password” name=”Emp_name” bean=”/com/src/Employee.empname” value=””/>
<dsp:input type=”submit” value=”Submit”/>
</dsp:form>
The tag dsp:form requires a action attribute and method attribute. The action attribute specifies the next action to be carried out on form submission. The method holds the method name that is used to submit the form (Refer HTML FORM METHODS).
Form Elements can be created as shown in the above example dsp:input tag is used to create the form components to get input from the user. dsp:input can create two kinds of controls:
A form field that gets input from the user that is passed to a component.
A submit button or image for the submission of the form.
All dsp:input tags must be embedded between <dsp:form>..</dsp:form> tags.
The syntax of a dsp:input tag is as shown below
<dsp:input [type="input-control"] [name="input-name"] bean="property-spec" ["source-spec"][checked="{true|false}"] [default="value"][priority=integer-value]/>
The attributes of dsp:input are as follows

Type
The Type attribute specifies the HTML input type such as a checkbox, radio button, or text box, if type is specified, the default type “Text” is considered as the input type. The attribute type can hold the below values.
Text – used to create a text box.
Checkbox- used to create a check box.
Radio- used to create a radio button.
Submit- specifies to display a submit button.
Image - specifies a submit control that uses the image specified by the src or pageattribute.
Password - To create text box for pasword .
Based on the type of input the other attributes of a dsp:input tag varies, For Example a check box control has an attribute checked (to check or uncheck) which is not applicable for a input of type Text i.e. text box.

Name
The Name attribute assigns a name to the input field, which enables access to it during form processing. The name must be unique for all input types other than radio and checkbox.
Bean
The Bean attribute specifies the property that this input field updates on form submission.
For Example in the below code the control emp_name refers to bean Component Employee and property empname. On Submission of the form the value specified in the text box is set to the bean component’s property which can stored for future use.
<dsp:input type=”text” name=”Emp_name” bean=”/com/src/Employee.empname”/>
Checked
The checked attribute is applicable only if the type is set to a checkbox or radio. The checked attribute is used to check or uncheck a radio button or checkbox.
Default
The default attribute specifies the default value of the component. If no input is specified the default value is set to the component’s property.
Priority
The priority attribute specifies the priority of this input field during form processing, relative to other input fields.
Value
The attribute value id valid only if the type attribute is set to submit. Value is the value set for submit button’slabel.
Embedding custom attributes
A dsp:input tag can embed one or more custom attributes by using the dsp:tagAttributetag. The syntax of a dsp:attribute tag is as follows.
<dsp:input ...>
dsp:tagAttribute name="attr-name" value="value"/>
<dsp:input/>
The tag dsp:tagAttributetags is specifically used to add attributes to the generated HTML beyond the fixed set of attributes supported by the DSP tag library.

! make money !

No comments:

Post a Comment