Changing the id of a WebMarkupContainer

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Changing the id of a WebMarkupContainer

Tim Squires
Hi,

I have a tree of objects ( train operators and trains ) and would like a wiper menu.  To create  the menu, I followed the instructions in the tutorial

http://wicket-stuff.sourceforge.net/wicket-contrib-dojo/WiperMenuTutorial.html

and added the details using a ListView for both the top level menu items and the submenus with separate component classess for each.  Tips from a previous post in this forum:

http://www.nabble.com/DOJO-FXOnClickWiper-t988596.html#a2572416

See below for full code.

The problem is when creating a listview of WebMarkupContainers, the id does not change for each iteration of the ListView and therefore the dojo wiper javascript only picks up the first top level menu.  An AttributeModifier was added to change the id but it has no effect:

final WebMarkupContainer trainMenu = new WebMarkupContainer("trainMenu");
trainMenu.add(new AttributeModifier("id", true, new Model("trainMenu_"  
                +operator.getId())));
add(trainMenu);


gives me

<div wicket:id="trainMenu" style="display:none" id="trainMenu_operator:trainMenu">

what I expected to see was

<div wicket:id="trainMenu" style="display:none" id="trainMenu_1234">

Anyone any ideas for doing this a better way or changing the web containers html id?

Thanks, Tim

Menu component code:
public class RTPSTrainOperatorChooser extends Panel {

        public static final int duration = 250;

        public RTPSTrainOperatorChooser(String id, TrainOperator operator) {
                super(id);
                addTrains(operator);
        }

        protected void addTrains(final TrainOperator operator) {

                final Label operatorMenuLabel = new Label("operator", new Model(
                                operator.getName()));
                add(operatorMenuLabel);
                final WebMarkupContainer trainMenu = new WebMarkupContainer("trainMenu");
                trainMenu.add(new AttributeModifier("id", true, new Model("trainMenu_"
                                + operator.getId())));
                trainMenu.add(new FXOnClickWiper(duration, operatorMenuLabel));
                add(trainMenu);

                trainMenu.add(new ListView("trains", new ArrayList<Train>(operator
                                .getTrains())) {
                        // This method is called for each 'entry' in the list.
                        @Override
                        protected void populateItem(ListItem item) {
                                // add the top level of the menu, the operators
                                // this list will always be shown
                                Train train = (Train) item.getModelObject();
                                Label label = new Label("trainLabel", new Model(train
                                                .getDescription()));
                                trainMenu.add(label);
                                item.add(label);
                        }
                });

        }
}


Menu component html:
<html>
  <body>
    <wicket:panel>   
                                                                                               
            <div wicket:id="operator" align="center">Operator</div>
           
            <div wicket:id="trainMenu">
             
                    <div wicket:id="trainLabel" align="center">Train</div>
                   

            </div>
           
    </wicket:panel>   
  </body>
</html>
Reply | Threaded
Open this post in threaded view
|

Re: Changing the id of a WebMarkupContainer

Martijn Dashorst
Administrator
Tim,

I haven't got time to take a look at this, but I'll forward it to the maintainers of the dojo package. They are both offline for the day.

Martijn


On 2/2/06, Tim Squires (sent by Nabble.com) <[hidden email]> wrote:
Hi,

I have a tree of objects ( train operators and trains ) and would like a wiper menu.  To create  the menu, I followed the instructions in the tutorial

<a href="http://wicket-stuff.sourceforge.net/wicket-contrib-dojo/WiperMenuTutorial.html" rel="nofollow" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://wicket-stuff.sourceforge.net/wicket-contrib-dojo/WiperMenuTutorial.html

and added the details using a ListView for both the top level menu items and the submenus with separate component classess for each.  Tips from a previous post in this forum:

<a href="http://www.nabble.com/DOJO-FXOnClickWiper-t988596.html#a2572416" rel="nofollow" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://www.nabble.com/DOJO-FXOnClickWiper-t988596.html#a2572416

See below for full code.

The problem is when creating a listview of WebMarkupContainers, the id does not change for each iteration of the ListView and therefore the dojo wiper javascript only picks up the first top level menu.  An AttributeModifier was added to change the id but it has no effect:

final WebMarkupContainer trainMenu = new WebMarkupContainer("trainMenu");
trainMenu.add(new AttributeModifier("id", true, new Model("trainMenu_"  
                +operator.getId())));
add(trainMenu);


gives me

<div wicket:id="trainMenu" style="display:none" id="trainMenu_operator:trainMenu">

what I expected to see was

<div wicket:id="trainMenu" style="display:none" id="trainMenu_1234">

Anyone any ideas for doing this a better way or changing the web containers html id?

Thanks, Tim

Menu component code:
public class RTPSTrainOperatorChooser extends Panel {

        public static final int duration = 250;

        public RTPSTrainOperatorChooser(String id, TrainOperator operator) {
                super(id);
                addTrains(operator);
        }

        protected void addTrains(final TrainOperator operator) {

                final Label operatorMenuLabel = new Label("operator", new Model(
                                operator.getName()));
                add(operatorMenuLabel);
                final WebMarkupContainer trainMenu = new WebMarkupContainer("trainMenu");
                trainMenu.add(new AttributeModifier("id", true, new Model("trainMenu_"
                                + operator.getId())));
                trainMenu.add(new FXOnClickWiper(duration, operatorMenuLabel));
                add(trainMenu);

                trainMenu.add(new ListView("trains", new ArrayList<Train>(operator
                                .getTrains())) {
                        // This method is called for each 'entry' in the list.
                        @Override
                        protected void populateItem(ListItem item) {
                                // add the top level of the menu, the operators
                                // this list will always be shown
                                Train train = (Train) item.getModelObject();
                                Label label = new Label("trainLabel", new Model(train
                                                .getDescription()));
                                trainMenu.add(label);
                                item.add(label);
                        }
                });

        }
}


Menu component html:
<html>
  <body>
    <wicket:panel>    
                <table border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td bgcolor="#FF6600">
                    <div wicket:id="operator" align="center">Operator</div>
            </td>
          </tr>
          <tr>
            <td bgcolor="#FF9966">
                    <div wicket:id="trainMenu">
                       <span wicket:id="trains">
                            <div wicket:id="trainLabel" align="center">Train</div>
                   </span>
                    </div>
            </td>
          </tr>
                </table>
    </wicket:panel>    
  </body>
</html>


View this message in context: <a href="http://www.nabble.com/Changing-the-id-of-a-WebMarkupContainer-t1045380.html#a2716338" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Changing the id of a WebMarkupContainer
Sent from the <a href="http://www.nabble.com/wicket-stuff-user-f3314.html" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">wicket-stuff-user forum at <a href="http://Nabble.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> Nabble.com.



--
Living a wicket life...

Martijn Dashorst - http://www.jroller.com/page/dashorst

Wicket 1.1.1 is out: http://wicket.sourceforge.net/wicket-1.1