JavaBeat
calling cards | international calling cards | phone card
Search JavaBeat

JAVABEAT
home
articles
tips
QnA
Books
forums
ARTICLE TOPICS
All Articles
Java 5.0
Java 6.0
EJB 3.0
JCA
Struts
JSF
Spring
Groovy
JBoss Seam
Hibernate
Eclipse
JavaFx
Google Guice
J2ME
GWT
WebServices
AJAX
ARCHIVE
2007 | 12 11 10 09 08 07 06 05 04 03
2008 | 07 06 05 04 03 02 01
CERTIFICATION KITS
350 SCJP 1.5 Mock Exams
400 SCJP 1.6 Mock Exams
300 SCWCD 5.0 Mock Exams
300 SCBCD 5.0 Mock Exams
Enter email address:

Latest JavaBeat Articles Delivered by FeedBurner
OUR NETWORK
javabeat
planetoss

Using Forms

TODO

Start with an example using the pojo from 4

Subclass wicket.markup.html.WebPage and in the constructor initialize and add the required Form implementation.

public class EditCustomerPage extends WebPage {
public EditCustomerPage() {
add(new CustomerForm("customerForm", new Customer()));
}
}

Subclass wicket.markup.html.form.Form and in the constructor add the necessary form elements.
These will be bound to the individual html form elements through the wicket:id attributes.

public class CustomerForm extends Form {
public CustomerForm(String name, Customer customer) {
super(id, new CompoundPropertyModel(customer));
add(new TextField("name"));
}
}

The html form itself must contain a wicket:id attribute that matches the Form added to the WebPage. Each form element must also have a corresponding wicket:id to each FormComponent added to the Form. In this example the form is bound to the "customerForm" Form instance and the text input is bound to the "name" TextField. There is also a single submit button that is not bound to any component. Wicket automatically provides the submission handling functionality through the Form base class implementation. Button components only need to be added to the Form if multiple buttons are required.

<form wicket:id="customerForm">
name: <input type="text" wicket:id="name"/><br>
<input type="submit"/>
</form>

Updating the model

What happens when the form is submitted? Describe how the automatic updating of pojo's when property models are used. Describe how to use buttons and a button-less form.

Validation

NO LONGER VALID AS OF RC1, FORM parent method doesn't take a FeedbackPanel

Describe how validation works and how to implement custom validation. Also give a short explanation of how to display messages.

Adding RequiredValidator to a form element will allow only non-null and non-empty values to pass validation successfully.

public CustomerForm(String name, Customer customer, IFeedback feedback) {
super(id, new CompoundPropertyModel(customer), feedback);
add(new TextField("name").add(RequiredValidator.getInstance()));
}

For convenience the class RequiredTextField is provided. This TextField automatically includes a RequiredValidator.

public CustomerForm(String name, Customer customer, IFeedback feedback) {
super(id, new CompoundPropertyModel(customer), feedback);
add(new RequiredTextField("name"));
}

To provide validation feedback a FeedbackPanel can be instantiated. This should be added to the page (for display) and associated with the form by passing it into the form constructor.

public EditCustomerPage() {
FeedbackPanel feedback = new FeedbackPanel("feedback");
add(feedback);
add(new CustomerForm("customerForm", new Customer(), feedback));
}

The FeedbackPanel can then be added to the html with a wicket:id span.

<span wicket:id="feedback">feedback will be here</span>

Finally, create a .properties file in the same directory as your html template and class file using the same naming conventions. In this case it would be called EditCustomerPage.properties. Use this file to define the error messages for each input in the form.

formId.inputId.ValidatorClassName=Your custom message.

Conversion

Describe how conversion works (when using property models) and how to implement custom conversion.

Form components

Give a list with a short description of the form components that are available in core.


Favorites
AffiliatedAds.com
Buy movies
Access Control
Busby seo challenge contest
Sohbet
Chat
Webmaster Hosting Forum
Java Jobs
MyVideoLib
India News
Internet Advances
Sohbet
chat
Latest QnA
SCJD Tips
When we start a thread by applying start() method on it ,how does it knows that to execute run()method?
About Wrapper class in Java
How to configure weblogic 7.0 in MyEclipse?
Static Block and Static Initializer in Java

JavaBeat Website (2004-2008), India
javabeat | about us | planetoss
Copyright (2004 - 2008), JavaBeat