On 20/11/2007, Nino Saturnino Martinez Vazquez Wael
<[EMAIL PROTECTED]> wrote:
>
>
> Gwyn Evans wrote:
> > On 20/11/2007, Nino Saturnino Martinez Vazquez Wael
> > <[EMAIL PROTECTED]> wrote:
> >
> >> Bump for replies..? Does my mail make sense? Do I need to specify
> >> anything further?
> >>
> >> Nino Saturnino Martinez Vazquez Wael wrote:
> >>
> >>> Hi
> >>>
> >>> I've been "playing" with both forms and listviews. And I wanted to
> >>> extend a form creating my own form that has captcha validation as
> >>> standard, I cant just seem to find where to place the markup when
> >>> extending Form?
> >>>
> >
> > Well, off-hand, I'd expect that the easiest way would be to do it
> > using markup inheritance -
> > http://wicket.apache.org/examplemarkupinheritance.html.
> >
> >
> Hm  the link you gave  talks about inheritance for a page. However this
> would mean that I had to put the <wicket:child> into the form in order
> to add stuff to the form right? What about inheritance for a panel, that
> way I could use it as a form. However I got some strange errors when
> trying todo this. Heres some pseduo
>
>
> panel.html
>
> <wicket:panel>
>
> <img wicket:id="myCaptchaimg"></img>
>
> <form wicket:id="form">
>
> <input wicket:id="captchamatchingtext" />
> <wicket:child>
> </form>
> </wicket:panel>
>
> panel.java
>
> private final Form form
>
> panel(String id)
> {
> super(id);
> form=new Form("form");
> add(form);
>
> form.add(new textfield..)
> add(new captcha...);
> }
>
> public addToForm(Component child){
> form.add(child);
> }
>
> Then the extending panels can add more stuff to the form.. Is this
> supposed to work?

If I understand it correctly, I'd have thought so, yes, although if
just getting started, I'd be tempted to get things going on a basic
page, then start refactoring.

> >>> I then tried doing it with a panel but also ran into
> >>> sometroubles.
> >>>
> >
> >
> >>> Also I've been noticing that if you use a compound model with a
> >>> listview forexample my page has a  compound model called article I add
> >>> the listview new listview("comments"). I would expect my item in the
> >>> populate implementation to get fed a comment compoundmodel, but it
> >>> does only get the compound model for the page, I then have to call
> >>> item.getModelObject and set the compundmodel manually. Is this
> >>> something that has been overseen, or am I missing the bigger picture?
> >>>
> >
> > I think so...  Compare this...
> >
> > HTML:
> >         <ul wicket:id="comments">
> >               <li wicket:id="comment">Dummy comment</li>
> >         </ul>
> >
> > Java: (compressed for vertical size!)
> >
> >   class Article {
> >     private List comments = Arrays.asList(new String[]{"Comment One",
> > "Comment Two", "Comment Three"});
> >     public List getComments() { return comments; }
> >   }
> >
> > and
> >
> >   public MyPage(final PageParameters parameters) {
> >     setModel(new CompoundPropertyModel(new Article()));
> >     ListView listView = new ListView("comments") {
> >       protected void populateItem(ListItem item) {
> >         item.add(new Label("comment", (String)item.getModelObject()));
> >       }
> >     };
> >   }
> >   add(listView);
> >
> > gives the following output:
> >
> >     * Comment One
> >     * Comment Two
> >     * Comment Three
> >
> >
> > /Gwyn
> >
> This is what I meant extending your example a but, it feels odd to make
> an extra compoundpropertymodel:
>
>  class Article {
>     private List<comment> comments=new arraylist<comments>...
>     public List getComments() { return comments; }
>   }
> class Comment{
>         private String text...
>         private String author
>         ....trival getters and setters...
> }
>
>  public MyPage(final PageParameters parameters) {
>     setModel(new CompoundPropertyModel(new Article()));
>     ListView listView = new ListView("comments") {
>       protected void populateItem(ListItem item) {
>         setModel(new *CompundPropertyModel*(item.getModelObject()
> ))
>         item.add(new Label("comment"));
>         item.add(new Label("author"));
>
>       }
>     };
>   }
>   add(listView);

I see.  You can do it like that, but personally, for just a cople of
labels I'd just implement populateItem() as follows:

 protected void populateItem(ListItem item) {
   final Comment comment = (Comment)item.getModelObject();
   item.add(new Label("text", comment.getText()));
   item.add(new Label("author", comment.getAuthor()));
 }

By the way, my HTML was incorrect before.  If should be more like this...

<ul>
  <li wicket:id="comments">
    <span wicket:id="author"></span>: <span wicket:id="text"></span>
  </li>
</ul>

/Gwyn
-- 
Download Wicket 1.3.0-rc1 now! - http://wicketframework.org

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to