Apache Wicket Interview Questions and Answers
The Best LIVE Mock Interview - You should go through before Interview
Experienced / Expert level questions & answers
Ques 1. How to create Select Option as menu wise in apache-wicket?
//Java
import org.apache.wicket.extensions.markup.html.form.select.Select;
import org.apache.wicket.extensions.markup.html.form.select.SelectOption;
...
//variable to hold the selected value from dropdown box,
//and also make "jQuery" selected by default
private String selected = "jQuery";
Select languages = new Select("languages", new PropertyModel<String>(this, "selected"));
form.add(languages);
languages.add(new SelectOption<String>("framework1", new Model<String>("Wicket")));
languages.add(new SelectOption<String>("framework2", new Model<String>("Spring MVC")));
languages.add(new SelectOption<String>("framework3", new Model<String>("JSF 2.0")));
languages.add(new SelectOption<String>("Script1", new Model<String>("jQuery")));
languages.add(new SelectOption<String>("Script2", new Model<String>("prototype")));
//HTML for dropdown box
<select wicket:id="languages">
<optgroup label="Frameworks">
<option wicket:id="framework1" >Wicket (1.4.7)</option>
<option wicket:id="framework2" >Spring MVC (3.0)</option>
<option wicket:id="framework3" >JSF (2.0)</option>
</optgroup>
<optgroup label="JavaScript">
<option wicket:id="Script1" >jQuery (1.6.1)</option>
<option wicket:id="Script2" >prototype (1.7)</option>
</optgroup>
</select>
Is it helpful?
Add Comment
View Comments
Ques 2. What is Pallet component in apache-wicket?
Wicket extension comes with a special “Palette” component, which render two select boxes, and allow user to move items from one select box into another.
//Java
import org.apache.wicket.extensions.markup.html.form.palette.Palette;
final Palette<Hosting> palette = new Palette<Hosting>("palette",
new ListModel<Hosting>(selected),
new CollectionModel<Hosting>(listHosting),
renderer, 10, true);
//HTML
<span wicket:id="palette"></span>
Is it helpful?
Add Comment
View Comments
Ques 3. How to create custom validator in apache-wicket?
See summary steps to create a custom validator :
1. Implements IValidator.
import org.apache.wicket.validation.IValidator;
public class StrongPasswordValidator implements IValidator<String>{
...
}
2. Override validate(IValidatable validatable).
public class StrongPasswordValidator implements IValidator<String>{
...
@Override
public void validate(IValidatable<String> validatable) {
//get input from attached component
final String field = validatable.getValue();
}
}
3. Attached custom validator to form component.
public class CustomValidatorPage extends WebPage {
public CustomValidatorPage(final PageParameters parameters) {
final PasswordTextField password = new PasswordTextField("password",Model.of(""));
//attached custom validator to password field
password.add(new StrongPasswordValidator());
//...
}
}
Is it helpful?
Add Comment
View Comments
Ques 4. How to integrate apache-wicket with Spring?
Override Wicket application init() method with this “addComponentInstantiationListener(new SpringComponentInjector(this));“.
File : Wicket application class
package com.withoutbook;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import com.withoutbook.user.SimplePage;
public class WicketApplication extends WebApplication {
@Override
public Class<SimplePage> getHomePage() {
return SimplePage.class; // return default page
}
@Override
protected void init() {
super.init();
addComponentInstantiationListener(new SpringComponentInjector(this));
}
}
Now, you can inject Spring bean into Wicket component via @SpringBean.
Is it helpful?
Add Comment
View Comments
Ques 5. How to get ServletContext in apache-wicket application?
Yes, you can get the ServletContext class via Wicket’s WebApplication class like this :
import javax.servlet.ServletContext;
import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;
import com.withoutbook.hello.Hello;
public class CustomApplication extends WebApplication {
@Override
public Class<? extends Page> getHomePage() {
ServletContext servletContext = WebApplication.get().getServletContext();
return Hello.class; //return default page
}
}
Is it helpful?
Add Comment
View Comments
Ques 6. How to keep file validation in apache-wicket if no file has been selected?
To fix it, just override the validateOnNullValue() method like this :
FileUploadField fileUpload = new FileUploadField("fileupload",new Model<FileUpload>());
fileUpload .add(new AbstractValidator() {
public boolean validateOnNullValue(){
return true;
}
protected void onValidate(IValidatable validatable) {
FileUpload fileUpload = (FileUpload) validatable.getValue();
}
protected String resourceKey() {
return "yourErrorKey";
}
});
Now, when no file is selected, and submit button is clicked, validation will be performed.
Is it helpful?
Add Comment
View Comments
Ques 7. How to create 404 error page?
<filter-mapping>
<filter-name>wicket.wicketTest</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<error-page>
<error-code>404</error-code>
<location>/error404</location>
</error-page>
public class WicketApplication extends WebApplication {
@Override
protected void init() {
mount(new QueryStringUrlCodingStrategy("error404",ErrorPage404.class));
}
}
Is it helpful?
Add Comment
View Comments
Most helpful rated by users:
- What is Wicket Framework?
- What are Wicket Models?
- What is Base class for HTML pages?
- What are the Ways to create a page in wicket?
- How to integrate apache-wicket with Spring?