On Thu, Jan 29, 2009 at 12:41:31PM +0200, Martin Makundi wrote:
> > 1) working with many attributes of an object
> > we have some pages where we access many attributes of an object, say we want
> > to show all 20 attributes of a person and all 10 attributes of
> > person.getAddress();
> > in the PersonPage.java i would have to add 30 label (or input) components,
> > 30 lines with nearly identical java code: add(new Label("firstName",
> > person.getName() );
> > isn't it tedious to always keep PersonDetails.java and PersonDetails.html
> > files in sync? in jsf/jsp the changes are only in the jsp/xhtml
> 
> There are few options that come into my mind:
> 1. add(new Label(CONSTANT_FIRST_NAME, person.getName() ); // Now you
> can re-use your constant from WicketTests.
> 2. add(new Label(CONSTANT_FIRST_NAME, new PropertyModel(person,
> Person.NAME_CONSTANT) ); // Now you can re-use your Entity's NAME
> -constant from JPA/ORM/Hibernate queries.
> 3. use CompoundPropertyModels. Yes. You will have to sync the names in
> html and in Java. Maybe someone will develop a nice plugin that
> automates this in the future:
> http://cwiki.apache.org/WICKET/working-with-wicket-models.html#WorkingwithWicketmodels-CompoundPropertyModels
> http://cwiki.apache.org/WICKET/more-on-models.html
> 

RepeatingView can also come in handy...

  RepeatingView rv = new RepeatingView("field");
  add(rv);
  String[] props = { "firstName", "lastName", ... };
  for (String prop : props) {
    rv.add(new Label(rv.newChildId(), new PropertyModel(person, prop));
  }

If you have something more complex than a Label, just substitute your
own custom panel.

> > 2) page composition
> You can treat Title just as a Label. See <wicket:head> tag and Wicket
> modularity:
> http://cwiki.apache.org/WICKET/wickets-xhtml-tags.html
> http://www.javalobby.org/java/forums/t60926.html
> http://cwiki.apache.org/WICKET/create-dynamic-markup-hierarchies-using-panels.html
> 

One common approach is to use markup inheritance, then have the parent
class expose overridable methods.

  public abstract class BasePage extends WebPage {

    public BasePage() {
      add(new Label("title", new AbstractReadOnlyModel() {
        public Object getObject() {
          return getPageTitle();
        }
      }));
    }

    public abstract String getPageTitle();
  }

  public class PersonPage extends BasePage {

    public PersonPage(PageParameters pp) {
      // load person object based on pp
    }

    public String getPageTitle() {
      return getPerson().getName();
    }
  }

The trick here is to avoid calling the overridable method directly from
the base class constructor (else we'd call PersonPage.getPageTitle
before the person was loaded). That's what the AbstractReadOnlyMethod
thing is about.

> > 3) preview functionality
> > is this right: as soon as we use page composition and components, the
> > preview feature is gone; how do you experienced wicket users handle this? is
> > it usable in a prototype phase - before the html prototype is decomposed
> > into composition parts and components?
> 
> The runtime page hierarchy is ofcourse visible only at runtime, but
> you can preview each panel separately ofcourse (if it makes sense).
> 

It's important to note that everything outside the <wicket:extend> tag
(for markup inheritance) or the <wicket:panel> tag (for panels) is
ignored by Wicket. You can therefore use this to create a reasonable
harness for previewing...

  <html>
    <head>
      <!-- normally included by BasePage, we include it 
           here to enable preview -->
      <link rel="stylesheet" href="../BasePage.css"/>
    </head>
    <body>
      <h1>My Panel Preview</h1>
      <wicket:panel>
        ...
      </wicket:panel>
    </body>
  </html>

But ultimately the point of a component-based framework is to avoid
copying boilerplate around, so if you're looking for previews of
fully-formed pages you're doing it wrong.

jk

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to