File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Application Frameworks and the fly likes Wicket Custom TextField Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Wicket Custom TextField" Watch "Wicket Custom TextField" New topic

Wicket Custom TextField

Brian Mulholland
Ranch Hand

Joined: Mar 12, 2009
Posts: 61
I am very new to Wicket (just getting started really) and I find the documentation to be very disappointing, and the framework complex. I love the concept and am attracted by the potential power and reuse of the component architecture especially the promise of rapidly extending and creating custom components.

For my first custom component I wanted to modify a TextField to do some things my project does ALL THE TIME like showing a textbox as plain text when it is disabled. I want to override the onRender(MarkupStream) to write out just text when the control is disabled instead of writing a disabled textbox.

Seems simple enough so I wrote the following in my new TextField:

public void onRender(MarkupStream stream){

The renderNext() was something that the javadoc didn't make clear was part of the implied onRender contract, but I found a brief online reference to and it solved on exception, but now that field throws an exception when run saying it wasn't in the hierarchy when it is disabled.

If I call the super.onRender() everything works fine, but as soon as I try to put out HTML that is not adding to what the super wants to render, the thing breaks. Clearly there is more to the implied contract of the onRender() than the docs are saying. This ought to be so easy, but is very frustrating.

Note: I know I could replace the TextField with a Label, this was meant to be a proof of concept where I can modify the HTML written by a component thus demonstrating how 'easy' it is to make a component do anything we want in the page.

Am I going about the idea of subclassing the Component incorrectly? What must the onRender() do to conform to the mysterious undocumented contract?
Joachim Rohde
Ranch Hand

Joined: Nov 27, 2006
Posts: 430

There's already a component which does what you'd like to achieve. It's called AjaxEditableLabel (

Else you're right. The documentation sucks quite much for a beginner. I can recommend the book "Wicket in Action" which really rocks. After reading that book you can solve 90% of your problems with the reference library ( and/or a quick search on the mailing list (which is very responsive and helpful).

"now that field throws an exception when run saying it wasn't in the hierarchy when it is disabled."
Try to use a placeholder for the (disabled) component. For that you have to call setOutputMarkupPlaceholderTag(true) on your component (
I agree. Here's the link:
subject: Wicket Custom TextField
It's not a secret anymore!