Work with HTML FORM and Java Servlets

From Documentation

Stop.png This documentation is for an older version of ZK. For the latest one, please click here.

Work with HTML FORM and Java Servlets

Stop.png This documentation is for an older version of ZK. For the latest one, please click here.

The event-driven model is simple and powerful, but it might not be practical to rewrite all servlets to replace with event listeners.

The name Property

To work with legacy Web applications, you could specify the name property as you did for HTML pages. For example,

Html 4.png

<window xmlns:h="[]">
	<h:form method="post" action="/my-old-servlet">
					<datebox name="when" />
					<textbox name="name" />
					<combobox name="department">
						<comboitem label="RD" />
						<comboitem label="Manufactory" />
						<comboitem label="Logistics" />
					<h:input type="submit" value="Submit" />

Once users press the submit button, a request is posted to the my-old-servlet servlet with the query string as follows.


Thus, as long as you maintain the proper associations between name and value, your servlet could work as usual without any modification.

Components that Support the name Property

All input-types components support the name property, such as textbox, datebox, decimalbox, intbox, combobox, bandbox, slider and calendar.

In addition, list boxes and tree controls are also support the name property. If the multiple property is true and users select multiple items, then multiple name/value pairs are posted.

 <listbox name="who" multiple="true" width="200px">
         <listheader label="name"/>
         <listheader label="gender"/>
     <listitem value="mary>
         <listcell label="Mary"/>
         <listcell label="FEMALE"/>
     <listitem value="john">
         <listcell label="John"/>
         <listcell label="MALE"/>
     <listitem value="jane">
         <listcell label="Jane"/>
         <listcell label="FEMALE"/>
     <listitem value="henry">
         <listcell label="Henry"/>
         <listcell label="MALE"/>

Html 5.png

If both John and Henry are selected, then the query string will contain:


Notice that, to use list boxes and tree controls with the name property, you have to specify the value property for listitem and treeitem, respectively. They are the values being posted to the servlets.

Rich User Interfaces

Because a form component could contain any kind of components, the rich user interfaces could be implemented independent of the existent servlets. For example, you could listen to the onOpen event and fulfill a tab panel as illustrated in the previous sections. Yet another example, you could dynamically add more rows to a grid control, where each row might control input boxes with the name property. Once user submits the form, the most updated content will be posted to the servlet.

Last Update : 2022/01/19

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.