Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6810897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:15:42+00:00 2026-05-26T20:15:42+00:00

This code is from the Wicket in Action book. final WebMarkupContainer parent = new

  • 0

This code is from the Wicket in Action book.

    final WebMarkupContainer parent = new WebMarkupContainer("comments");
    parent.setOutputMarkupId(true);
    add(parent);
    List<String> comments = ...

    parent.add(new ListView("list", comments) {

        @Override
        protected void populateItem(ListItem item) {
            item.add(new Label("comment", item.getModel()));
        }
    });

    Form form = new Form("form");
    final TextArea editor = new TextArea("editor", new Model(""));
    editor.setOutputMarkupId(true);
    form.add(editor);
    form.add(new AjaxSubmitLink("save") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            comments.add(editor.getModelObjectAsString());
            editor.setModel(new Model(""));
            target.addComponent(parent);
            target.focusComponent(editor);
        }
    });
    parent.add(form);

It doesn’t compile. Inside the override method, the row

comments.add(editor.getModelObjectAsString());

generates the following errors in Eclipse

“Multiple markers at this line. Cannot refer to a non-final variable comments inside an inner class defined in a different method. The method getModelObjectAsString() is undefined for the type TextArea.”

I love programming books written by the authors of a framework with examples that don’t work =) seriously though, what is wrong here and how can it be fixed?

EDIT:

In order for it to compile in Wicket 1.4, the code needs to change to

    /* Java code */
    final WebMarkupContainer parent = new WebMarkupContainer("comments");
    parent.setOutputMarkupId(true);
    add(parent);
    final List<String> comments = new ArrayList<String>();

    parent.add(new ListView("list", comments) {

        @Override
        protected void populateItem(ListItem item) {
            item.add(new Label("comment", item.getModel()));
        }
    });

    Form form = new Form("form");
    //final TextArea editor = new TextArea("editor", new Model(""));
    final TextArea editor = new TextArea("editor", new Model(""));
    editor.setOutputMarkupId(true);
    form.add(editor);
    form.add(new AjaxSubmitLink("save") {
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            comments.add((String) editor.getModelObject());
            editor.setModel(new Model(""));
            target.addComponent(parent);
            target.focusComponent(editor);
        }
    });
    parent.add(form);

But if the list is made final, then wont it be impossible to dynamically alter its contents?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:15:42+00:00Added an answer on May 26, 2026 at 8:15 pm

    Putting my comment into a real answer:

    The problem is the not the final on the TextArea, but that the Wicket in Action book is written for Wicket 1.3 and the APi has changed for version 1.4 / 1.5.

    The migration guide for Wicket i.4 states that the members have been renamed to getDefaulModelXXX().

    Have fun with wicket.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hI, I'm trying to get this code from Larry Nyhoff's book to compile in
I read this code from my book: class B extends A {...} class G<E>
Just copy this code from perl cook book 2nd ed pp. 796 it returns:
Consider this code from the official OpenJDK source of java.awt.font.TextLayout : public final class
I got this piece of code from a book viz. sams teach yourself android
I got this code from Andy Tanenbaum's book. I am trying to run it.
I got this code from Jquery in Action: $.fn.photoslide = function(options) { var settings
I tried to run this code from the book 'Python Standard Library' of 'Fred
In this code (from the WCF REST starterkit - preview2): protected override SampleItem OnAddItem(SampleItem
I'm using this code from Microsoft to play audio notifications for my application. It's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.