This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Wicket Custom TextField" Watch "Wicket Custom TextField" New topic
Author

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:

@Override
public void onRender(MarkupStream stream){
if(this.isEnabled())
super.onRender(stream);
else{
getResponse().write(this.getModel().getObject().toString());
this.renderNext(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: 423

There's already a component which does what you'd like to achieve. It's called AjaxEditableLabel (http://wicket.apache.org/docs/1.4/org/apache/wicket/extensions/ajax/markup/html/AjaxEditableLabel.html).

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 (https://cwiki.apache.org/WICKET/reference-library.html) 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 (http://wicket.apache.org/docs/1.4/org/apache/wicket/Component.html#setOutputMarkupPlaceholderTag%28boolean%29).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wicket Custom TextField
 
Similar Threads
Wicket AJAX question
Parsing an HTML file
paging for dynamic rows
NotSerializableException + jsf custom components
Is Wicket for real big websites