use a listview,propertylistview or repeater...

Differences are:

listview: iterates over a list
propertylistviw:-||- and bound the item.model via a compound model, very usefull if you use compound models a lot.
repeater: repeats for int times, as I remember it..



m_salman wrote:
Hi,

I have designed a panel of form text fields which I would like to repeat in
a panel of form.

Here is the code:

EmptyForm.java

public class EmptyForm extends Form {
        private final ValueMap properties = new ValueMap();

        public EmptyForm(final String id)
        {
                super(id);
        }
        
        public void addFormComponent(
                FormComponent formComponent)
        {
                add(formComponent);
        }

        public ValueMap getValueMap()
        {
                return properties;
        }
        
        public final void onSubmit()
        {
                // some stuff
        }

}




EmptyFormPanel.java

public class EmptyFormPanel extends Panel
{
        private EmptyForm emptyForm;
        private ValueMap valueMap;

        /**
         * @see org.apache.wicket.Component#Component(String)
         */
        public EmptyFormPanel(final String id)
        {
                super(id);

                emptyForm = new EmptyForm("emptyForm");
                valueMap = emptyForm.getValueMap();             
                add(emptyForm);
                
                
                List<TextFieldBean> textFields = new ArrayList<TextFieldBean>();
                
                textFields.add(new TextFieldBean("User Name", "userName"));
                textFields.add(new TextFieldBean("Password", "password"));
                
                ListView formTextFieldPanels = new ListView( 
"formTextFieldPanels" ,
textFields)
                {
                        protected void populateItem(ListItem item)
                        {
                                TextFieldBean textFieldBean = (TextFieldBean) 
item.getModelObject();
                                
                                FormTextFieldPanel formTextFieldPanel = new
FormTextFieldPanel("formTextFieldPanels");
                                
                                //item.add(formTextFieldPanel);
                                formTextFieldPanel.addItem(emptyForm, item, 
textFieldBean, valueMap);
                                //emptyForm.add(formTextFieldPanel);
                                
                        }
                        
                };
                
                add(formTextFieldPanels);
                
                
        }
        
        public EmptyForm getEmptyForm()
        {
                return emptyForm;
        }
        
        public ValueMap getValueMap()
        {
                return valueMap;
        }
        
}


EmptyFormPanel.html

<html xmlns:wicket>
<body>
  <wicket:panel wicket:id="emptyFormPanels">
                <form wicket:id="emptyForm">
                        <table>
                                <div wicket:id="formTextFieldPanels"></div>
                                <tr>
                                        <td></td>
                                        <td>
                                                <input type="submit" name="submit" 
value="Sign In"/>
                                                <input type="reset" 
value="Reset"/>
                                        </td>
                                </tr>
                        </table>
                </form>
  </wicket:panel>
</body>
</html>




FormTextFieldPanel.java

public class FormTextFieldPanel extends Panel {
        
public FormTextFieldPanel(String id) {
                super(id);
        }

        
        public void addItem(
                EmptyForm emptyForm,
                ListItem item,
                TextFieldBean textFieldBean,
                ValueMap valueMap)
        {
                item.add(new Label("fieldNameLabel", 
textFieldBean.getFieldName()));
                item.add(new TextField("fieldId", new PropertyModel(valueMap,
textFieldBean.getFieldId())));                                  
                //emptyForm.add(item);
        }
        
        
}


FormTextFieldPanel.html

<html xmlns:wicket>
<body>
  <wicket:panel id="formTextFieldPanels">
                                <tr>
                                        <td align="right" 
wicket:id="fieldNameLabel">fieldName</td>
                                        <td>
                                                <input wicket:id="fieldId" type="text" 
value="[EMAIL PROTECTED]" size="30"/>
                                        </td>
                                </tr>
  </wicket:panel>
</body>
</html>


I would like "FormTextFieldPanel" to repeat inside "EmptyFormPanel"


My problem is with "formTextFieldPanels" component.
If I use
emptyForm.add(formTextFieldPanel);

then I get the error message that "formTextFieldPanels" is being repeated (
" a component by this name already exists")

If I don't use it then I get the error message that this component is
missing.


Can some one please tell me what will be the right way to handle this.
I tried to do search for this and it seems that there is a way of doing this
by using RepeaterView.
If so then please let me know how.


Thank you

-Mohammad

--
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


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

Reply via email to