• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Wicket Custom TextField

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 433
Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic