rubyjava (2) [Avatar] Offline
#1
In chapter 2, i add the folowing code (of the bold paragraph):

import java.text.NumberFormat;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.list.PageableListView;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
.....
add(new Label("total",new Model() {
@Override
public Object getObject(){
NumberFormat nf = NumberFormat.getCurrencyInstance();
return nf.format(getCart().getTotal());
}

}));

......

It show the error:

java.lang.RuntimeException: Uncompilable source code - getObject() in cannot override getObject() in org.apache.wicket.model.Model; attempting to use incompatible return type
found : java.lang.Object
required: java.io.Serializable
.....

Help me!

Regards

Message was edited by:
rubyjava
Eelco12 (100) [Avatar] Offline
#2
Re: Problem Chapter 2 - section 3.2.2
Are you using Wicket 1.3? Wicket 1.4 has a few changes that can cause this.
rubyjava (2) [Avatar] Offline
#3
Re: Problem Chapter 2 - section 3.2.2
Yes, I use Wicket 1.4 and IDE is NetBeans.So, Can you help me change it?
Eelco12 (100) [Avatar] Offline
#4
Re: Problem Chapter 2 - section 3.2.2
You should either switch to Wicket 1.3, or you should read how to upgrade here: http://cwiki.apache.org/WICKET/migrate-14.html

If you experience problems there, you can search the mailing list archives or ask there.
jps1965 (1) [Avatar] Offline
#5
Re: Problem Chapter 2 - section 3.2.2
Hi Eelco12

Thanks for this response. I am having the same problem, and it's very frustrating. I have been very interested in the Wicket framework and would like to try using it. But I also can't get past this point in the book because I get the same error.

I went to the link you gave rubyjava, and the information there is really not helpful, it isn't clear how to modify the code that's obsolete in the book. I'm a newbie at this and don't know how to relate the getModel() change to the getObject() method call error we're getting.

Can you please just post here the correct code? I am also using NetBeans (6.5.1), and the only Wicket plugin version it gives you the option of installing is for version 1.4. That's not going to help. If I simply import the 1.3.6 jar's, the app builds, but still won't run.

Instead of telling rubyjava, and others, to go look around, or ask some mail archive, can't you just simply post here the correct code to replace the defective source listed on page 61? Wouldn't that be a lot easier? You must know what the corrected code for Wicket 1.4 is, don't you? So why not just post it in this forum rather than tell your reader to go searching for it? Then what's the point of this forum? rubyjava certainly didn't have any trouble posting the source code from the book.

By the way, if there are error fixes or updates to be made in the code listings in a tech book like this, it's customary to have an errata page where the author can post new code to replace the old code that people are still reading in older editions of the book that are out there. This seems to be the prevalent practice with other publishers (Wrox, O'Reilly, etc). It's common for there to be mistakes in a tech book, or just things that have to be updated for new versions of software. Your book is hardly alone in that. But it's good practice to make such amendments readily available to your readers so using the book isn't so frustrating.

Other than these issues, I have found the book to be quite good. It's brief and too the point. I also like the framework. It seems to be a refreshingly simple and concise solution to other tools like Java Server Faces, that seem to be unnecessarily complicated and laden with a mess of xml config files.

Keep up the good work, but please do post the correct code. That's so much more considerate and helpful to your readers than just telling them to go fish around a mail list.

Thanks

jps1965
bselfridge (6) [Avatar] Offline
#6
Re: Problem Chapter 2 - section 3.2.2
Just a thought - can you instead override the Label's getModelObject() method? This might cause the same problem, but it's something to try:

Instead of

add(new Label("total",new Model() {
@Override
public Object getObject(){
NumberFormat nf = NumberFormat.getCurrencyInstance();
return nf.format(getCart().getTotal());
}

}));

Make it

add(new Label("total",new Model()) {
@Override
public Object getModelObject(){
NumberFormat nf = NumberFormat.getCurrencyInstance();
return nf.format(getCart().getTotal());
}

});

This may easily be bologna but I've been able to use this construct in other places.

Also, to jps, did you import the 1.3.6 jars AND delete the 1.4 ones?

Message was edited by:
bselfridge
shane_hayes@sbcglobal.net (7) [Avatar] Offline
#7
Re: Problem Chapter 2 - section 3.2.2
I have the same problem and have been hunting around for hours to try and find the answer. Any help would be greatly appreciated. I'm going to skip over trying to get this to work as I have to make some other progress in the book. I don't think my application is going to need this behavior right away, but it makes me nervous that a side-effect action to update the total in the cart does not work.

Key words: getObject, total, cart
shane_hayes@sbcglobal.net (7) [Avatar] Offline
#8
Re: Problem Chapter 2 - section 3.2.2
I just figured out the solution with a hint from the 1.4.1 examples: http://wicketstuff.org/wicket14/unicodeconverter/?wicket:bookmarkablePage=sources:org.apache.wicket.examples.source.SourcesPage&SourcesPage_class=org.apache.wicket.examples.unicodeconverter.UnicodeConverter

The code needs to have a return type of string:
add(new Label("total", new Model() {

@Override
public String getObject() {
NumberFormat nf = NumberFormat.getCurrencyInstance();
return nf.format(getCart().getTotal());
}
}));