I'm facing a similar problem; I want to create HTML fragments
dynamically, not just a single widget. I also want to do this in the
context of the net.customware MVP framework. I decided I needed a
handler since the user can increment and decrement the widget count. I
have many of these dynamic widgets; I don't want to use a grid data
entry model.

1. Create an instance manager class. This class manages a private class:
                ViewPieces {
                        int instanceCount;
                        InstanceView instanceViewGenerator;
                        Panel panel;
                        }

                and two structures:
                        1. Map<String, ArrayList<InstanceView>>
                        2. Map<String, ViewPieces>

        It has the following methods:
                getInstance(String instanceId, int instance)
                getInstanceCount(String instanceId)
                onInstanceCountChange
                        This event handler creates a new InstanceView.
                        Fire  an event to this handler when the user
                        changes the instance count.

                register(String instanceId, Panel groupInstance,
                        InstanceView generator)
                instanceId      is the key into the structures managed
                                by InstanceManager
                groupInstance   is the attach point for the generated
                                widget
                generator       is the callback that creates an
                                instance of InstanceView

                Call register in the MVP startProcessing method. e.g.:
instanceManager.register(CONSTANTS.instanceAirConditioning(),
groupAirConditioningInstance, new InstanceView() {
            @Override
            public InstanceView get(int i) {
                return new AirConditioningInstanceView(i);
            }
        });

2. Create an abstract class InstanceView which extends Composite. It has
the following methods:
        asWidget
        buildInstance(String prefix, String instanceId, int instance,
                        Panel parent, Panel attachPoint)
                        This creates whatever widget you need. You
                        probably don't need attachPoint, but you
                        probably do need parent. Called by the
                        generator ctor
                        (e.g. AirConditioningInstanceView())
        get
        getInstanceSeq

I'm happy to share some code if you're interested

On 03/23/2010 01:21 PM, enTropy Fragment wrote:
> You can also add listeners inside the bucle so every texBox can call a
> different method when the inside value changes, for example :)
> 
> If you need the instances of the texboxes outside from the bucle, wich
> seems your case, you can always create an ArrayList and add them to both
> the list and the parent.
> 
> 2010/3/23 rudolf michael <roud...@gmail.com <mailto:roud...@gmail.com>>
> 
>     well this is easy dude.
>     Onblur or onchange over the textbox that serves as an input, you
>     catch that event and parse the input so you can get the desired number.
>     after that you choose in which panel/parent node you want to create
>     those textboxes and accordingly in your listener you can do :
>     for(int i=0; i < number; i++)
>     parent.add(new TextBox());
> 
>     if you want to have names for your textboxes then inside your loop
>     you can do myTextBox.setName("myName"+i);
> 
> 
>     On Tue, Mar 23, 2010 at 5:04 PM, Jochen Schnaidt
>     <j.schna...@t-online.de <mailto:j.schna...@t-online.de>> wrote:
> 
>         Hi,
>         I have a question about coding dynamic parts with GWT. I already
>         searched for an answer, but didn’t find something which could
>         help me.
>         May be I have the wrong keywords? I don’t know…
> 
>         So, the problem: My concept is that my application reads a integer
>         from a TextBox after the user wrote it in there e.g. 3 and then
>         creates 3 new TextBoxes.
> 
>         I read the 3 no problems and have it in a variable but now I want to
>         add the TextBoxes. In a scripting language I can build new
>         objects and
>         give a “dummyname” + digit as name to it and use it normal but
>         in Java
>         I can’t modify my variable’s name. So I need another method.
> 
>         I tried to make something like an array of TextBox but it didn’t
>         work
>         out.
> 
>         So please help me with this. I don’t get it on my own. Thanks a lot.
> 
>         Greetings Jochen
> 
>         --
>         You received this message because you are subscribed to the
>         Google Groups "Google Web Toolkit" group.
>         To post to this group, send email to
>         google-web-toolkit@googlegroups.com
>         <mailto:google-web-toolkit@googlegroups.com>.
>         To unsubscribe from this group, send email to
>         google-web-toolkit+unsubscr...@googlegroups.com
>         <mailto:google-web-toolkit%2bunsubscr...@googlegroups.com>.
>         For more options, visit this group at
>         http://groups.google.com/group/google-web-toolkit?hl=en.
> 
> 
>     -- 
>     You received this message because you are subscribed to the Google
>     Groups "Google Web Toolkit" group.
>     To post to this group, send email to
>     google-web-toolkit@googlegroups.com
>     <mailto:google-web-toolkit@googlegroups.com>.
>     To unsubscribe from this group, send email to
>     google-web-toolkit+unsubscr...@googlegroups.com
>     <mailto:google-web-toolkit%2bunsubscr...@googlegroups.com>.
>     For more options, visit this group at
>     http://groups.google.com/group/google-web-toolkit?hl=en.
> 
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Google Web Toolkit" group.
> To post to this group, send email to google-web-tool...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-toolkit+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to