The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

jon.janisch (4) [Avatar] Offline
#1
If you run the source code from chapter 4, several of the database fields will not be populated.

Below are the values that are not inserted:

User table
--------------
'notes'

Address table
--------------
'city'
'postalCode'
'street2'

The errors are because of multiple copy-paste errors throughout AddressEdit.java and UserEdit.java
charlie.collins (125) [Avatar] Offline
#2
Re: Chapter 4 source code full of errors
I don't think this is accurate, or fair. All the examples were tested across multiple platforms and worked correctly.

Looking at the README, the database content is generated for you (but the database itself is not). The DB is generated through JPA using persistence.xml (http://gwt-in-practice.googlecode.com/svn/trunk/Ch4-CoreAppDesign/src/META-INF/persistence.xml - note hbm2ddl auto).

Also the User class itself does have a notes property (http://gwt-in-practice.googlecode.com/svn/trunk/Ch4-CoreAppDesign/src/com/manning/gwtip/user/client/User.java). And, address has all the fields noted here too (http://gwt-in-practice.googlecode.com/svn/trunk/Ch4-CoreAppDesign/src/com/manning/gwtip/user/client/Address.java).

So you may have some other problems going on causing issues, but it's not a copy-paste related thing? Exactly what errors in the code are you presuming to refer to? And, what are the actual errors you are seeing?
jon.janisch (4) [Avatar] Offline
#3
Re: Chapter 4 source code full of errors
Hi Charlie,

All of the persistence stuff is fine as you stated, the errors are in the view components like I said in the original post.

The errors that I can remember are listed below. The [ code ] formatter on these forums appears to be broken (atleast in preview mode) so I didn't use it.

In AddressEdit.java:
----------------------------------------------------------------
Line 81:
street1.addChangeListener(
new ChangeListener() {
public void onChange(Widget sender) {
address.setStreet1(street1.getText());
}
});

The block of code for street1 (starts at line 64) is duplicated for street 2.

It should be:
street2.addChangeListener(
new ChangeListener() {
public void onChange(Widget sender) {
address.setStreet2(street2.getText());
}
});

----------------------------------------------------------------
Further down you have:
street1.addChangeListener(
new ChangeListener() {
public void onChange(Widget sender) {
address.setCity(city.getText());
}
});

You change the city when "street1" changes instead of when "city" changes. So it should be:
city.addChangeListener(
new ChangeListener() {
public void onChange(Widget sender) {
address.setCity(city.getText());
}
});
----------------------------------------------------------------
Likewise for the postal code:
street1.addChangeListener(
new ChangeListener() {
public void onChange(Widget sender) {
address.setPostalCode(postalCode.getText());
}
});

Should be:
postalCode.addChangeListener(
new ChangeListener() {
public void onChange(Widget sender) {
address.setPostalCode(postalCode.getText());
}
});

----------------------------------------------------------------
In UserEdit, you create an array of listeners of size 5:
private PropertyChangeListener[] listeners = new PropertyChangeListener[5];


...but you only add 4 listeners. I added the following code to the file to make it work:

listeners[4] = new PropertyChangeListener(){
public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
notes.setText( (String) propertyChangeEvent.getNewValue() );
}
};
// When the model changes
user.addPropertyChangeListener( "notes", listeners[4]);
notes.addChangeListener( new ChangeListener(){
public void onChange(Widget sender) {
user.setNotes( notes.getText() );
}
});

Hope this clears things up! Great book by the way smilie

Jonathan
charlie.collins (125) [Avatar] Offline
#4
Re: Chapter 4 source code full of errors
Ok Jon, I really appreciate the feedback, and will go back and look at the view components (and the entire example).

I know I have run that chapters examples multiple times, on multiple platforms, but probably did not set every field and test (street 2, for example).

I hope we didn't do that same thing in the text where we show those classes, doh! (I don't recall if we show those items in their entire or not, I actually was not the author of chapter 4, Cooper was).

Again, thanks for the input, and I will get the issues fixed.
jon.janisch (4) [Avatar] Offline
#5
Re: Chapter 4 source code full of errors
No problem charlie. I believe the book is fine since it only lists part of the file for demonstration purposes.