Why not create a wicket components for the comment div and the makecomment link. Then in the onClick override of the makecomment link you can set the visibility of the comment component. This does require a roundtrip to the server, but is IMO more the wicket-way (tm).

Matthijs

Wayne Pope wrote:
Ok,

so I'm new to this, however things have been progression ok for my first day
with Wicket.
However it seems to me that I must be doing HTML markup manipulation in java
when the manipulation only concerns the view and not the data behind it.
This seems at odds with wicket philosophy. Let me explain:

I have a very simple news feed that I want to be able to comment on, this
textarea should only be visible once I click on a link.

the markup
<div wicket:id="newsItems">
  <strong wicket:id="title"/>
  <p wicket:id="description"/>
  <div id="comment" style="display:none" >
   <textarea><textarea>
  <div>
  <a href="#" wicket:id="makecomment"
onclick="getElementById("comment').style.display='';return false;">Make
comment</a>
</div>

As there are lots of news items, I need to assign a unique id (markup id,
not wicket id) to the <div> element and the corresponding onclick attribute
in the anchor.

So in the java I have to do it this way:
ListView items = new ListView("newsItems",feed) {
            @Override
            protected void populateItem(ListItem item) {
                FeedItem news = (FeedItem) item.getModelObject();
                item.add(new Label("title", new
PropertyModel(news,"title")));
                item.add(new Label("description", new
PropertyModel(news,"description")));

                final int index = item.getIndex();
                item.add(new WebMarkupContainer("makecomment") {
                    protected void onComponentTag(ComponentTag tag) {

tag.getAttributes().put("onclick","getElementById('comment"+index+"').style.display='';return
false;"); }
                });


                item.add(new WebMarkupContainer("comment") {
                    protected void onComponentTag(ComponentTag tag) {
                    tag.getAttributes().put("id","comment"+index); }
                });


            }
        };

        add(items);


Ok so that code is just to demonstrate what I mean. The point is I need to
manipulate the attributes of elements, just so I can setup some javascript
stuff. Is there no better way of just doing this in the markup or some form
of wicket:tag that can insert the current list item index?

thanks
Wayne



--
Matthijs Wensveen
Func. Internet Integration
W http://www.func.nl
T +31 20 4230000
F +31 20 4223500

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

Reply via email to