How to add, lets say here, a number of TextFields to a form dynamically, depending on something coming from the database.
For example:
int id = 0;
for(Contract c : contracts) {
String incrementId = "contract_" + id;
add(new TextField(incrementId, new Model(c.getNumber())));
id++;
}
Now, how to reference all those components in the html?
Well, I don't have the answer for that. :D
sure you can do that, but then you yourself have to manage request parameters, yuck. the whole point of components is that they take care of all that messy stuff for you.
if you still want to do that you override webcomponent.onrender () and do something like this: getResponse().write("blah");
however, it seems to me you are still not thinking in terms of components.
if you can give me a more defined usecase i can show you how to break it down into components
for the general usecase you are talking about - ie lets say building a set of checkboxes for a collection that comes out of the database you can use our prebuilt component CheckBoxMultiChoice or you can use the more component oriented version CheckGroup/Check
with CheckGroup/Check your component hierarchy would look like this
CheckGroup - manages the group of avail checkboxes
| Repeater (ListView or another) - iterates over the list of items retrieved from the db
| | Check - checkbox representing a single item from the db list
| | | Label - a label to show text representing a single item from the db list
in this way you can create a list of checkboxes for a list of variable length.
does this clear things up a bit?
-IgorOn 5/4/06, Rivka Shisman <[EMAIL PROTECTED]> wrote:Hi Igor,
I still don't understand where is the servlet functionality of Wicket.
What if I don't want to hand code all my textboxes in the html and instead I want to dynamically add them with "out.print" like possibility from a collection with unknown size that comes from the database.
If I use a panel (as much as I understand what a panel is) I still need it to be a dynamically built panel.
Thanks
Rivka
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Igor Vaynberg
Sent: Thursday, May 04, 2006 7:17 PM
To: [email protected]
Subject: Re: [Wicket-user] dynamic html controls
lets take your exact usecase, hiding and showing form components based on some condition.
there are two basic strategies to do this:
1) add all of them an then toggle visibility
this means you add all possible formcomponents and then override isVisible() on them or call setVisible(false). this will tell wicket not to render the portion of html associated with that component.
so instead of <c:if condition="blah"><input type="text" name="comp" value="${val}"/></c:if> in jsp you would have
add(new TextField("comp",...) {
boolean isVisible() {
return blah;
}
}
and in html <input type="text" wicket:id="comp"/>
2) swapping panels - this is usually used for bigger chunks of the page then formcomponents. a good analagy for this is the tabbed view.
when you click a tab the body of the view has to change to show a different tab's body. each tab's body can be represented as a panel so when a tab is clicked it can swap the panel in the body of the tabbed panel with the panel of its chosing.
see our TabbedPanel for example in code and in our component reference which shows a short example
hope this helps,
-Igor
On 5/4/06, Rivka Shisman < [EMAIL PROTECTED]> wrote:
Hi Eelco,
Do you mean that I should create a "panel" with a link to my own servlet
that shows the dynamic content?
Thanks
Rivka
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]] On Behalf Of Eelco
Hillenius
Sent: Thursday, May 04, 2006 10:21 AM
To: [email protected]
Subject: Re: [Wicket-user] dynamic html controls
You can do what is outlined here:
http://wicket-wiki.org.uk/wiki/index.php/Create_dynamic_markup_hierarchi
es_using_panels
Or - like the article says, add all visible components and use the
isVisible property (or override the method) for turning them on or
off.
Or use Fragments, which work like panels, but have their markup
definded in the same markup (HTML) file.
Eelco
On 5/4/06, Rivka Shisman <[EMAIL PROTECTED] > wrote:
>
>
>
> Hi
>
>
>
> I have no experience with Wicket, but from what I read about it I
don't
> understand where does the dynamic content part come in?
>
> If I have a pair of html file and a java file - how do I conditionally
> show/hide html form controls like I do in JSP?
>
>
>
> For example, I have a JSP page that constructs my form text fields
(and
> labels) from a result of a select from the database?
>
> Is that possible to achieve with Wicket?
>
>
>
> Thanks
>
> Rivka
>
>
>
>
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services,
security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache
Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmdlnk&kid0709&bid&3057&dat1642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user
--
Bruno Borges
[EMAIL PROTECTED]
Sun Certified Java Programmer for 1.4
Sun Certified Web Component Developer for 1.4
