Take a look at the examples projects too. The phonebook example should
be very usefull to give you an idea how to use typical database driven
applications.
Eelco
On 2/10/06, VGJ <[EMAIL PROTECTED]> wrote:
> I'll try it...not being a Swing programmer and never really having to think
> about how this type of event model works...I had no idea I could do it that
> way.
>
> Thanks very much for the info! I'll see what happens once I get it working.
>
>
> On 2/10/06, Johan Compagner <[EMAIL PROTECTED]> wrote:
> > that looks like very wrong code
> > Don't know where these pieces of code are in:
> >
> > //get default directory
> > Directory ed =
> DirectoryProxy.getDefaultWithEmployees();
> >
> > //get employees from directory
> > List<Employee> employees = ed.getEmployees();
> >
> > but if that is in a webpage constructor or something that it is really
> wrong.
> > Because youre list never changes?
> >
> > Why do you need to split that list?
> >
> > But can't you do something like this:
> >
> > IModel loadingModel = new LoadableDetachableModel()
> > {
> > protected Object load()
> > {
> > //get default directory
> > Directory ed =
> DirectoryProxy.getDefaultWithEmployees();
> >
> > //get employees from directory
> > List<Employee> employees = ed.getEmployees();
> > }
> > };
> >
> > Model modelFirstHalf = new Model(loadingModel)
> > {
> > public Object getObject(final Component component)
> > {
> > // get the loading model
> > Model model = super.getObject(component);
> > List<Employee> employees = model.getObject(null);
> > List<Employee> empList1 = employees.subList(0,
> employees.size()/2);
> > return empList1;
> > }
> >
> > detach()
> > {
> > Model model = super.getObject(component);
> > model.detach();
> > }
> > }
> >
> > and then a second half model also giving that loadingModel.
> >
> > This is just a quick sample. Just give the 2 models a shared object that
> loads the employees once and detached it when
> > the "real" models are detached.
> >
> > johan
> >
> >
> >
> >
> >
> > On 2/11/06, VGJ <[EMAIL PROTECTED]> wrote:
> > > This might put me in a bind then.
> > >
> > > What I showed you before was really a simplified, edited version of the
> code I'm really using.
> > >
> > > What I've got is similar only I have to split that single List into two
> other lists...doing something like this:
> > >
> > > //get default directory
> > > Directory ed =
> DirectoryProxy.getDefaultWithEmployees();
> > >
> > > //get employees from directory
> > > List<Employee> employees = ed.getEmployees ();
> > >
> > > //get full size of employee collection
> > > int listSize = employees.size();
> > > int breakPt = listSize / 2; //...divide in two
> > >
> > > IModel empModel1 = new LoadableDetachableModel()
> > > {
> > > protected Object load()
> > > {
> > > //list 1
> > > List<Employee> empList1 = employees.subList(0, breakPt);
> > >
> > > return empList1;
> > > }
> > > };
> > >
> > > IModel empModel2 = new LoadableDetachableModel()
> > > {
> > > protected Object load()
> > > {
> > > //list 2
> > > List<Employee> empList2 = employees.subList(breakPt,
> listSize);
> > >
> > > return empList2;
> > > }
> > > };
> > >
> > > ...you can probably see my dilemma...to do what I'm doing, I'd have to
> place all of the "global" code inside of each inner-class because I can't
> access it - and that would be unacceptable since I'd have to make another
> round-trip to the database to get the same exact data twice. I know this
> isn't typical but obviously, we all don't write typical code all of the
> time. In this case I'm forced to display the list on the page in two even
> columns side-by-side.
> > >
> > > Any suggestions?
> > >
> > >
> > >
> > > On 2/10/06, Igor Vaynberg < [EMAIL PROTECTED]> wrote:
> > > > if you think that is ugly, maybe wicket is not for you :)
> > > >
> > > > in wicket you use anonymous classes often. an alternative would be to
> make that anonymous class into a private static class, or if it is reusable
> make it a public static class.
> > > >
> > > > unlike many other web frameworks out there wicket requires you to use
> the full facilities of OO in java, so if you want to use wicket you might as
> well learn those.
> > > >
> > > > the loadable model is a good pracice anyways, because it does not
> store your list in session which it would've been given your original code.
> storing that list in session is a waste of space.
> > > >
> > > > i think the problem is that the list that is returned is not
> serializable and so it cannot be stored in session. that is a hibernate
> specific detail. what you can do is copy that list into an array list, but
> that is not a good solution imho, the loadable detachable model is.
> > > >
> > > >
> > > > -Igor
> > > >
> > > >
> > > >
> > > > On 2/10/06, VGJ < [EMAIL PROTECTED]> wrote:
> > > > > Phew, that could get ugly. Could I fix this by making my domain
> classes serializable? Bare with me, I'm still pretty new to Java as well as
> Wicket :)
> > > > >
> > > > >
> > > > >
> > > > > On 2/10/06, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
> > > > > > and if it is, looks like whatever list is returned is not
> serializable so wicket cannot wrap it with a model for you.
> > > > > >
> > > > > > here is how to fix that and make the model detacahable, which is
> good anyways:
> > > > > >
> > > > > >
> > > > > > IModel listModel=new LoadableDetachableModel() {
> > > > > > Object load() {
> > > > > > //get default directory
> > > > > > Directory ed =
> DirectoryProxy.getDefaultWithEmployees();
> > > > > >
> > > > > >
> > > > > > //get employees from directory
> > > > > > return ed.getEmployees();
> > > > > > }
> > > > > > }
> > > > > >
> > > > > > add(new ListView("emoloyees", listModel)...
> > > > > >
> > > > > >
> > > > > > -Igor
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > On 2/10/06, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
> > > > > > > is that the root cause of the exception?
> > > > > > >
> > > > > > > -Igor
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > On 2/10/06, VGJ < [EMAIL PROTECTED]> wrote:
> > > > > > > > I'm trying to convert a single page of an existing application
> using Wicket...just to see how it works. The entire app was built on JDK
> 5.0. It uses hibernate and retrieves lists of data with generics...and it
> may be what is causing my problems since I've spotted a comment here and
> there that Wicket doesn't support Java 5?
> > > > > > > >
> > > > > > > > It's a simple test...I've got my 3 files:
> > > > > > > >
> > > > > > > > CheckIn.html
> > > > > > > > CheckIn.java
> > > > > > > > CheckInApp.java
> > > > > > > >
> > > > > > > > Here's where I'm pulling a List from a proxy class in the
> middle-layer of the application and trying to display it:
> > > > > > > >
> > > > > > > > public class CheckIn extends WebPage
> > > > > > > > {
> > > > > > > > public CheckIn()
> > > > > > > > {
> > > > > > > > //get default directory
> > > > > > > > Directory ed =
> DirectoryProxy.getDefaultWithEmployees();
> > > > > > > >
> > > > > > > > //get employees from directory
> > > > > > > > List<Employee> employees = ed.getEmployees();
> > > > > > > >
> > > > > > > > //list 1
> > > > > > > > add(new ListView("employees", empList)
> > > > > > > > {
> > > > > > > > // This method is called for each 'entry' in the
> list.
> > > > > > > > protected void populateItem(ListItem item)
> > > > > > > > {
> > > > > > > > //get employee object
> > > > > > > > Employee employee =
> (Employee)item.getModelObject();
> > > > > > > >
> > > > > > > > //other employee labels
> > > > > > > > item.add(new Label("firstName",
> employee.getFirstName()));
> > > > > > > > item.add(new Label("lastName",
> employee.getLastName()));
> > > > > > > > }
> > > > > > > > });
> > > > > > > > }
> > > > > > > > }
> > > > > > > >
> > > > > > > > Here's part of the exception I'm getting:
> > > > > > > >
> > > > > > > > ...
> > > > > > > > 14:25:09,613 ERROR RequestCycle:785 - Unexpected runtime
> exception [page = null]
> > > > > > > > java.lang.ClassCastException: java.util.RandomAccessSubList
> > > > > > > > at
> wicket.markup.html.list.ListView.<init>(ListView.java:135)
> > > > > > > > at com.portlets.ui.CheckIn$1.<init>(CheckIn.java:58)
> > > > > > > > at com.portlets.ui.CheckIn.<init>(CheckIn.java:55)
> > > > > > > >
> > > > > > > > Any ideas? Thanks!
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user