Top 25 Apache Wicket Interview Questions
Q1. Tell Me The Example Of Username Validation In Apache-wicket?
Import org.Apache.Wicket.Validation.CompoundValidator;
import org.Apache.Wicket.Validation.Validator.PatternValidator;
import org.Apache.Wicket.Validation.Validator.StringValidator;
public elegance UsernameValidator extends CompoundValidator<String>
private static final long serialVersionUID = 1L;
public UsernameValidator()
add(StringValidator.LengthBetween(6, 15));
upload(new PatternValidator("[a-z0-9_-]+"));
Q2. How To Create Radio Button In Apache-wicket?
//alternatives in radio button
non-public static very last List<String> TYPES = Arrays.AsList(new String[] "Shared Host", "VPN", "Dedicated Server" );
RadioChoice<String> hostingType = new RadioChoice<String>("web hosting", new PropertyModel<String>(this, "selected"), TYPES);
Q3. How To Create Dropdown Choice In Apache-wicket?
//Java
import org.Apache.Wicket.Markup.Html.Shape.DropDownChoice;
//alternatives in dropdown field
private static final List<String> SEARCH_ENGINES = Arrays.AsList(new String[]
"Google", "Bing", "Baidu" );
//variable to hold the chosen cost from dropdown container,
//and also make "Google" is chosen by means of default
personal String selected = "Google";
DropDownChoice<String> listSites = new DropDownChoice<String>(
"websites", new PropertyModel<String>(this, "selected"), SEARCH_ENGINES);
//HTML for dropdown field
<select wicket:id="sites"></select>
Q4. How To Keep File Validation In Apache-wicket If No File Has Been Selected?
To fix it, simply override the validateOnNullValue() method like this :
FileUploadField fileUpload = new FileUploadField("fileupload",new Model<FileUpload>());
fileUpload .Upload(new AbstractValidator()
public boolean validateOnNullValue()
go back genuine;
protected void onValidate(IValidatable validatable)
FileUpload fileUpload = (FileUpload) validatable.GetValue();
included String resourceKey()
return "yourErrorKey";
);
Now, whilst no document is selected, and submit button is clicked, validation can be performed.
Q5. How To Get Servletcontext In Apache-wicket Application?
Yes, you can get the ServletContext class thru Wicket’s WebApplication elegance like this :
import javax.Servlet.ServletContext;
import org.Apache.Wicket.Page;
import org.Apache.Wicket.Protocol.Http.WebApplication;
import com.Withoutbook.Good day.Hello;
public class CustomApplication extends WebApplication
@Override
public Class<? Extends Page> getHomePage()
ServletContext servletContext = WebApplication.Get().GetServletContext();
return Hello.Elegance; //return default page
Q6. How To Create Checkbox In Apache-wicket?
Final CheckBox chk0 = new CheckBox("checkbox0", Model.Of(Boolean.TRUE));
final CheckBox chk1 = new CheckBox("checkbox1",
new PropertyModel<Boolean>(this, "checkbox1"));
very last CheckBox chk2 = new CheckBox("checkbox2",
new PropertyModel<Boolean>(this, "checkbox2"));
Q7. 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 elegance WicketApplication extends WebApplication
@Override
blanketed void init()
mount(new QueryStringUrlCodingStrategy("error404",ErrorPage404.Elegance));
Q8. What Is Pallet Component In Apache-wicket?
Wicket extension comes with a unique “Palette” thing, which render two pick bins, and allow user to transport objects from one pick container into any other.
//Java
import org.Apache.Wicket.Extensions.Markup.Html.Form.Palette.Palette;
final Palette<Hosting> palette = new Palette<Hosting>("palette",
new ListModel<Hosting>(decided on),
new CollectionModel<Hosting>(listHosting),
renderer, 10, genuine);
//HTML
<span wicket:id="palette"></span>
Q9. How To Create Custom Validator In Apache-wicket?
See summary steps to create a custom validator :
@Implements IValidator.
Import org.Apache.Wicket.Validation.IValidator;
public class Strong PasswordValidator implements IValidator<String>
...
@Override validate(IValidatable validatable).
Public magnificence StrongPasswordValidator implements IValidator<String>
...
@Override
public void validate(IValidatable<String> validatable)
//get enter from attached issue
final String field = validatable.GetValue();
@Attached custom validator to shape issue.
Public elegance CustomValidatorPage extends WebPage
public CustomValidatorPage(final PageParameters parameters)
final PasswordTextField password = new PasswordTextField("password",Model.Of(""));
//connected custom validator to password area
password.Add(new StrongPasswordValidator());
//...
Q10. How To Create Select Option As Menu Wise In Apache-wicket?
//Java
import org.Apache.Wicket.Extensions.Markup.Html.Shape.Choose.Select;
import org.Apache.Wicket.Extensions.Markup.Html.Shape.Choose.SelectOption;
//variable to preserve the chosen fee from dropdown field,
//and also make "jQuery" selected with the aid of default
non-public String selected = "jQuery";
Select languages = new Select("languages", new PropertyModel<String>(this, "decided on"));
shape.Upload(languages);
languages.Upload(new SelectOption<String>("framework1", new Model<String>("Wicket")));
languages.Add(new SelectOption<String>("framework2", new Model<String>("Spring MVC")));
languages.Upload(new SelectOption<String>("framework3", new Model<String>("JSF 2.0")));
languages.Upload(new SelectOption<String>("Script1", new Model<String>("jQuery")));
languages.Upload(new SelectOption<String>("Script2", new Model<String>("prototype")));
//HTML for dropdown container
<select wicket:id="languages">
<optgroup label="Frameworks">
<option wicket:id="framework1" >Wicket (1.Four.7)</option>
<option wicket:id="framework2" >Spring MVC (3.Zero)</option>
<option wicket:id="framework3" >JSF (2.Zero)</option>
</optgroup>
<optgroup label="JavaScript">
<option wicket:id="Script1" >jQuery (1.6.1)</option>
<option wicket:id="Script2" >prototype (1.7)</option>
</optgroup>
</select>
Q11. How To Create A Textarea In Apache-wicket?
//create a textarea subject for deal with
very last TextArea<String> cope with = new TextArea<String>("address",Model.Of(""));
deal with.SetRequired(genuine);
Q12. What Is About Web Application In Wicket?
A net software is a subclass of Application which friends with an example of WicketServlet to serve pages over the HTTP protocol. This magnificence is intended to be subclassed by using framework clients to define a web application.
Q13. How To Create Fileupload Field In Apache-wicket?
//Java
import org.Apache.Wicket.Markup.Html.Form.Upload.FileUploadField;
shape.SetMultiPart(real);
form.Upload(fileUpload = new FileUploadField("fileUpload"));
//HTML
<input wicket:id="fileUpload" type="file"/>
Q14. What Are Wicket Models?
A Model holds a price for a aspect to show and/or edit :
Simple Models
Dynamic Models
Property Models
Compound Property Models
Wrapped Object Models
Resource Models
Detachable Models
Chaining models
Q15. How To Create A Password Field In Apache-wicket?
Create a password field
very last PasswordTextField password = new PasswordTextField("password", Model.Of(""));
//for homes document
password.SetLabel(Model.Of("Password"));
Q16. What Is Wicket Framework?
Wicket is one of the most latest in an extended line of Java web development frameworks.Wicket is a part-basedframework, which puts it in stark evaluation to some of the earlier solutions to the from time to time monotonous assignment of web programming.Wicket builds on top of Sun's servlet API. Wicket is in most cases removed from the request/response nature this is inherent with the internet and Servlets. Instead of building controllers that should service many customers and threads simultaneously, taking in requests, returning responses, and never storing any country, the Wicket developer thinks in terms of stateful components. Instead of creating a controller or movement elegance, he or she creates a web page, locations components on it, and defines how each element reacts to user enter.
It is a light-weight issue-based totally web application framework for the Java programming.
Q17. What Are The Ways To Create A Page In Wicket?
There are 2 methods to Create New Wicket Page.
Create a Page Extending "WebPage" Class.
Create a Page Extending "BasePage" ( BasePage Should Extend "WebPage").
IF you are the usage of first Way you need to Create Whole web page with thier Header,Footer and other parts
and that HTML file's content can be huge (complex).This is an Unreliable manner to create Page. Assume you have to trade a few content material in Header component then you need to edit all pages that having Header Content
If you are the use of 2d way, first Create your BasePage then you may enlarge those web page to other while creating new page. In that page you need to upload best Body component (Content that you want to expose on that Page) Using <wicket:child />
Q18. What Is Base Class For Html Pages?
Base elegance for HTML pages: Webpage Class.
Q19. How To Integrate Apache-wicket With Spring?
Override Wicket utility init() method with this “addComponentInstantiationListener(new SpringComponentInjector(this));“.
File : Wicket application elegance
package deal com.Withoutbook;
import org.Apache.Wicket.Protocol.Http.WebApplication;
import org.Apache.Wicket.Spring.Injection.Annot.SpringComponentInjector;
import com.Withoutbook.Consumer.SimplePage;
public magnificence WicketApplication extends WebApplication
@Override
public Class<SimplePage> getHomePage()
go back SimplePage.Magnificence; // return default page
@Override
covered void init()
wonderful.Init();
addComponentInstantiationListener(new SpringComponentInjector(this));
Now, you can inject Spring bean into Wicket element thru @SpringBean.
Q20. How To Create A Textfield In Apache-wicket?
Very last TextField username = new TextField("username",Model.Of(""));
username.SetRequired(true);
username.Upload(new Username Validator());
Q21. How To Submit A Form In Apache-wicket?
Form<?> form = new Form<Void>("userForm")
@Override
covered void onSubmit()
very last String usernameValue = username.GetModelObject();
PageParameters pageParameters = new PageParameters();
pageParameters.Upload("username", usernameValue);
setResponsePage(SuccessPage.Magnificence, pageParameters);
;
Q22. How To Create Single Selected Listbox?
// unmarried list choice
private static final List<String> FRUITS = Arrays.AsList(new String[] "Apple", "Orange", "Banana" );
ListChoice<String> listFruits = new ListChoice<String>("fruit", new PropertyModel<String>(this, "selectedFruit"), FRUITS);
listFruits.SetMaxRows(five);
Q23. How To Create Multiple Selected Listbox In Apache-wicket?
//choices in list box
private static final List<String> NUMBERS = Arrays.AsList(new String[] "Number 1", "Number 2", "Number three", "Number 4", "Number five", "Number 6" );
//variable to preserve the selected multiple values from listbox,
//and make "Number 6" selected as default fee
non-public ArrayList<String> selectedNumber = new ArrayList<String>(
Arrays.AsList(new String[] "Number 6" ));
ListMultipleChoice<String> listNumbers = new ListMultipleChoice<String>(
"quantity", new Model(selectedNumber), NUMBERS);
//HTML for a couple of choose listbox
<select wicket:id="number"></select>
Q24. How To Create Multiple Checkboxes In Apache-wicket?
Private static final List<String> LANGUAGES = Arrays.AsList(new String[] "Java", ".NET", "PHP", "Python", "C/C++" );
// hold the checkbox values
non-public ArrayList<String> languagesSelect = new ArrayList<String>();
final CheckBoxMultipleChoice<String> listLanguages = new CheckBoxMultipleChoice<String>("languages", new Model(languagesSelect), LANGUAGES);
Q25. Dependency To Start Wicket?
<dependency>
<groupid>org.Apache.Wicket</groupid>
<artifactid>wicket</artifactid>
<version>1.4.17</version>
</dependency>
Wicket want SLF4J !
You have to consist of the slf4j logging implementation, in any other case Wicket could be failed to begin.
Wicket want useful resource filter
Remember to add the aid filter out, Wicket places all documents in same bundle folder, if you didn’t outline the aid clear out to encompass the whole lot “<include>*</include>” , “html”, “residences” or other sources documents may did not copy to the suitable target folder.

