Request for help with generics-related compiler warnings

2009-11-07 Thread Philip Johnson

Greetings, Wicket Wizards,

I am updating a sample Wicket program from 1.3.6 to 1.4.3 and running into 
a few generics-related issues.   I am hoping you folks can quickly set me 
straight. My code appears to run successfully and passes its JUnit tests, 
despite the warnings I would like to remove.  The purpose of the code is 
to demonstrate simple use of Forms, Lists, and Tables and associated 
testing of these constructs using WicketTester.


First off, although you hopefully will not need to, you can download the 
sample code from here:

http://ics-wicket-examples.googlecode.com/files/wicket-example02-1.0.1106.zip

Unzip, cd into the directory, and type ant, It should download Ivy, then 
download Wicket, Jetty, SLF4J, and JUnit, and finally compile the system, 
generating the following generic-related warnings.   Let me now show you 
what they are:


Problem 1:  please take a look at line 39 of TablePage.java:
http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TablePage.java

The problematic line is:
new ListDataProvider(contacts)

and obviously requires a generic argument, but neither of the following 
work:

 new ListDataProviderContact(contacts)  // my preferred guess
 new ListDataProviderListContact(contacts)

The compiler warning is:
   [javac] TablePage.java:39: warning: [unchecked] unchecked call to 
ListDataProvider(java.util.ListT) as a member of the raw type 
org.apache.wicket.markup.repeater.data.ListDataProvider

   [javac] new ListDataProvider(contacts)) {
   [javac] ^
   [javac] TablePage.java:39: warning: [unchecked] unchecked conversion
   [javac] found   : 
org.apache.wicket.markup.repeater.data.ListDataProvider
   [javac] required: 
org.apache.wicket.markup.repeater.data.IDataProviderjava.util.Listedu.hawaii.wicket.TablePage.Contact

   [javac] new ListDataProvider(contacts)) {
   [javac] ^

Problem 2:  on line 49 of the same file, TablePage.java:
http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TablePage.java

The line is:
Contact contact = (Contact) item.getModelObject();

Since the preceding line provides a parameterized declaration of  item 
(ItemListContact item), I don't understand why I need to cast here. 
But the code does not compile if I don't.  Then, I get the following 
warning:


   [javac] TablePage.java:49: warning: [unchecked] unchecked cast
   [javac] found   : java.util.Listedu.hawaii.wicket.TablePage.Contact
   [javac] required: edu.hawaii.wicket.TablePage.Contact
   [javac] Contact contact = (Contact) item.getModelObject();
   [javac]
^

Problem 3:  WicketTester and generics.

I clearly don't understand how to test with WicketTester.  Take a look at 
lines 37-39 of TestListPage:

http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TestListPage.java

This is a mess, and generates the following warning:
   [javac] TestListPage.java:39: warning: [unchecked] unchecked cast
   [javac] found   : capture#294 of ?
   [javac] required: java.util.Listjava.lang.String
   [javac] ListString metaVars = (ListString) 
varsModel.getObject();


I have a feeling that my whole approach to getting values out of the table 
for testing is wrong, but I don't know what the correct approach is.


If any of you can give me a hand, the first Mai Tai is on me the next time 
you are in Hawaii.


Thanks!
Philip





-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Request for help with generics-related compiler warnings

2009-11-07 Thread Ernesto Reinaldo Barreiro
This does not produces any warnings

public class TablePage extends WebPage {

  /** Support serialization. */
  private static final long serialVersionUID = 1L;

  /**
   * Creates a page containing a table of Contacts.
   */
  public TablePage() {

// Initialize our list of Contact instances.
// Use ArrayList, not List, since ArrayList is Serializable.
ArrayListContact contacts = new ArrayListContact();
contacts.add(new Contact(Joe Smith, 123 Honu St., Kailua, HI
96734));
contacts.add(new Contact(Sally Forth, 456 Alapapa St., Honolulu, HI
96813));

// Create the dataview to display our list of contact instances.
// Note that the following commented out line is OK from a type
perspective.
// ListDataProviderContact test = new
ListDataProviderContact(contacts);

// But we can't say new ListDataProviderContact in the next line. Why?
DataViewContact dataView = new DataViewContact(ContactList,
new ListDataProviderContact(contacts)) {
  /** For serialization. */
  private static final long serialVersionUID = 1L;

  /**
   * Display each row in the table.
   *
   * @param item A Contact instance to be displayed.
   */
  public void populateItem(ItemContact item) {
Contact contact = (Contact) item.getModelObject();
item.add(new Label(Name, contact.getName()));
item.add(new Label(Address, contact.getAddress()));
  }
};

// Add the dataview to the TablePage.
add(dataView);
  }

  /**
   * An inner class implementing a record of data to be displayed as a row
in the table. Package
   * private so that TestTablePage can access it.
   *
   * @author Philip Johnson
   */
  static class Contact implements Serializable {
/** Support serialization. */
private static final long serialVersionUID = 2L;
private String name;
private String address;

/**
 * Create a new contact, given a name and an address.
 *
 * @param name The name.
 * @param address The address.
 */
public Contact(String name, String address) {
  this.name = name;
  this.address = address;
}

/**
 * Return the name.
 *
 * @return The name of this contact.
 */
public String getName() {
  return name;
}

/**
 * Return the address of this contact.
 *
 * @return The address.
 */
public String getAddress() {
  return address;
}
  }
}

at least on my IDE

Best,

Ernesto

On Sat, Nov 7, 2009 at 9:42 AM, Philip Johnson john...@hawaii.edu wrote:

 Greetings, Wicket Wizards,

 I am updating a sample Wicket program from 1.3.6 to 1.4.3 and running into
 a few generics-related issues.   I am hoping you folks can quickly set me
 straight. My code appears to run successfully and passes its JUnit tests,
 despite the warnings I would like to remove.  The purpose of the code is to
 demonstrate simple use of Forms, Lists, and Tables and associated testing of
 these constructs using WicketTester.

 First off, although you hopefully will not need to, you can download the
 sample code from here:
 
 http://ics-wicket-examples.googlecode.com/files/wicket-example02-1.0.1106.zip
 

 Unzip, cd into the directory, and type ant, It should download Ivy, then
 download Wicket, Jetty, SLF4J, and JUnit, and finally compile the system,
 generating the following generic-related warnings.   Let me now show you
 what they are:

 Problem 1:  please take a look at line 39 of TablePage.java:
 
 http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TablePage.java
 

 The problematic line is:
 new ListDataProvider(contacts)

 and obviously requires a generic argument, but neither of the following
 work:
  new ListDataProviderContact(contacts)  // my preferred guess
  new ListDataProviderListContact(contacts)

 The compiler warning is:
   [javac] TablePage.java:39: warning: [unchecked] unchecked call to
 ListDataProvider(java.util.ListT) as a member of the raw type
 org.apache.wicket.markup.repeater.data.ListDataProvider
   [javac] new ListDataProvider(contacts)) {
   [javac] ^
   [javac] TablePage.java:39: warning: [unchecked] unchecked conversion
   [javac] found   : org.apache.wicket.markup.repeater.data.ListDataProvider
   [javac] required:
 org.apache.wicket.markup.repeater.data.IDataProviderjava.util.Listedu.hawaii.wicket.TablePage.Contact
   [javac] new ListDataProvider(contacts)) {
   [javac] ^

 Problem 2:  on line 49 of the same file, TablePage.java:
 
 http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TablePage.java
 

 The line is:
 Contact contact = (Contact) item.getModelObject();

 Since the preceding line provides a parameterized declaration of  item
 (ItemListContact item), I don't understand why I need to cast here. But
 the code does not compile if I don't.  Then, I get the following warning:

   [javac] TablePage.java:49: 

Re: Request for help with generics-related compiler warnings

2009-11-07 Thread Ernesto Reinaldo Barreiro
and the casting is no longer needed

DataViewContact dataView = new DataViewContact(ContactList,
new ListDataProviderContact(contacts)) {
  /** For serialization. */
  private static final long serialVersionUID = 1L;

  /**
   * Display each row in the table.
   *
   * @param item A Contact instance to be displayed.
   */
  public void populateItem(ItemContact item) {
Contact contact = item.getModelObject();
item.add(new Label(Name, contact.getName()));
item.add(new Label(Address, contact.getAddress()));
  }
};

Regards,

Ernesto

On Sat, Nov 7, 2009 at 10:14 AM, Ernesto Reinaldo Barreiro 
reier...@gmail.com wrote:

 This does not produces any warnings

 public class TablePage extends WebPage {

   /** Support serialization. */
   private static final long serialVersionUID = 1L;

   /**
* Creates a page containing a table of Contacts.
*/
   public TablePage() {

 // Initialize our list of Contact instances.
 // Use ArrayList, not List, since ArrayList is Serializable.
 ArrayListContact contacts = new ArrayListContact();
 contacts.add(new Contact(Joe Smith, 123 Honu St., Kailua, HI
 96734));
 contacts.add(new Contact(Sally Forth, 456 Alapapa St., Honolulu, HI
 96813));

 // Create the dataview to display our list of contact instances.
 // Note that the following commented out line is OK from a type
 perspective.
 // ListDataProviderContact test = new
 ListDataProviderContact(contacts);

 // But we can't say new ListDataProviderContact in the next line.
 Why?
 DataViewContact dataView = new DataViewContact(ContactList,
 new ListDataProviderContact(contacts)) {
   /** For serialization. */
   private static final long serialVersionUID = 1L;

   /**
* Display each row in the table.
*
* @param item A Contact instance to be displayed.
*/
   public void populateItem(ItemContact item) {
 Contact contact = (Contact) item.getModelObject();
 item.add(new Label(Name, contact.getName()));
 item.add(new Label(Address, contact.getAddress()));
   }
 };

 // Add the dataview to the TablePage.
 add(dataView);
   }

   /**
* An inner class implementing a record of data to be displayed as a row
 in the table. Package
* private so that TestTablePage can access it.
*
* @author Philip Johnson
*/
   static class Contact implements Serializable {
 /** Support serialization. */
 private static final long serialVersionUID = 2L;
 private String name;
 private String address;

 /**
  * Create a new contact, given a name and an address.
  *
  * @param name The name.
  * @param address The address.
  */
 public Contact(String name, String address) {
   this.name = name;
   this.address = address;
 }

 /**
  * Return the name.
  *
  * @return The name of this contact.
  */
 public String getName() {
   return name;
 }

 /**
  * Return the address of this contact.
  *
  * @return The address.
  */
 public String getAddress() {
   return address;
 }
   }
 }

 at least on my IDE

 Best,

 Ernesto

 On Sat, Nov 7, 2009 at 9:42 AM, Philip Johnson john...@hawaii.edu wrote:

 Greetings, Wicket Wizards,

 I am updating a sample Wicket program from 1.3.6 to 1.4.3 and running into
 a few generics-related issues.   I am hoping you folks can quickly set me
 straight. My code appears to run successfully and passes its JUnit tests,
 despite the warnings I would like to remove.  The purpose of the code is to
 demonstrate simple use of Forms, Lists, and Tables and associated testing of
 these constructs using WicketTester.

 First off, although you hopefully will not need to, you can download the
 sample code from here:
 
 http://ics-wicket-examples.googlecode.com/files/wicket-example02-1.0.1106.zip
 

 Unzip, cd into the directory, and type ant, It should download Ivy, then
 download Wicket, Jetty, SLF4J, and JUnit, and finally compile the system,
 generating the following generic-related warnings.   Let me now show you
 what they are:

 Problem 1:  please take a look at line 39 of TablePage.java:
 
 http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TablePage.java
 

 The problematic line is:
 new ListDataProvider(contacts)

 and obviously requires a generic argument, but neither of the following
 work:
  new ListDataProviderContact(contacts)  // my preferred guess
  new ListDataProviderListContact(contacts)

 The compiler warning is:
   [javac] TablePage.java:39: warning: [unchecked] unchecked call to
 ListDataProvider(java.util.ListT) as a member of the raw type
 org.apache.wicket.markup.repeater.data.ListDataProvider
   [javac] new ListDataProvider(contacts)) {
   [javac] ^
   [javac] TablePage.java:39: warning: [unchecked] unchecked 

Re: Request for help with generics-related compiler warnings

2009-11-07 Thread PhilipJohnson

Thanks so much, both of you! 

Anyone have any ideas about the WicketTester code? 

Problem 3:  WicketTester and generics.

I clearly don't understand how to test with WicketTester.  Take a look at
lines 37-39 of TestListPage:
http://code.google.com/p/ics-wicket-examples/source/browse/trunk/example02/src/edu/hawaii/wicket/TestListPage.java

This is a mess, and generates the following warning:
[javac] TestListPage.java:39: warning: [unchecked] unchecked cast
[javac] found   : capture#294 of ?
[javac] required: java.util.Listjava.lang.String
[javac] ListString metaVars = (ListString)
varsModel.getObject();


Cheers,
Philip

-- 
View this message in context: 
http://old.nabble.com/Request-for-help-with-generics-related-compiler-warnings-tp26242997p26245535.html
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org