You are trying to add an not visible component in AJAX request target, make
sure it has its markup id at browser to be recreated, you can call
tableContainer.setOutputMarkupPlaceholderTag to ensure that.

On Fri, Feb 11, 2011 at 1:16 PM, chechaquo <[email protected]> wrote:

>
> Hello,
>
> I have simple program that should search in db by user's name and show the
> result in table, but it doesn't work ...
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
> <html xmlns:wicket="http://wicket.apache.org";>
>    <head>
>        <title></title>
>        <link wicket:id='stylesheet'/>
>    </head>
>    <body>
>
>        <form wicket:id="searchUserForm">
>            <input type="text" wicket:id="username"/>
>            <input type="button" wicket:id="searchUser" value="Search"/>
>        </form>
>        <div wicket:id="resultTable">
>        <table>
>            <tr  wicket:id="usersList">
>                <td>Name</td>
>                <td>Last Name</td>
>            </tr>
>        </table>
>        </div>
>    </body>
> </html>
>
> public class HomePage extends BasePage {
>
>    private ListView<User> usersList;
>    private WebMarkupContainer tableContainer;
>    private List<User> users = new ArrayList<User>();
>
>    public HomePage() throws Exception {
>        add(new SearchUserForm("searchUserForm"));
>        tableContainer = new WebMarkupContainer("resultTable");
>        usersList = new ListView<User>("usersList", users) {
>
>            @Override
>            protected void populateItem(ListItem<User> item) {
>                User user = item.getModel().getObject();
>                Label name = new Label("firstname", user.getName());
>                item.add(name);
>                Label lastname = new Label("lastname", user.getLastname());
>                item.add(lastname);
>            }
>        };
>        tableContainer.setOutputMarkupId(true);
>        tableContainer.add(usersList);
>        tableContainer.setVisible(false);
>        add(tableContainer);
>
>    }
>
>    final class SearchUserForm extends Form {
>
>        private static final long serialVersionUID = 1L;
>
>        public SearchUserForm(String id) throws Exception {
>            super(id);
>            final TextField<String> username = new
> TextField<String>("username", new Model<String>());
>            AjaxButton searchContact = new AjaxButton("searchUser") {
>
>                private static final long serialVersionUID = 1L;
>
>                @Override
>                public void onSubmit(AjaxRequestTarget target, Form<?> form)
> {
>                    String name = (String) username.getDefaultModelObject();
>                    try {
>                        users.add(new User("name", "surname"));
>                        users.add(new User("name1", "surname1"));
>                        usersList.setList(users);
>                        tableContainer.setVisible(true);
>                        target.addComponent(tableContainer);
>
>                    } catch (Exception e) {
>                        // TODO Auto-generated catch block
>                        e.printStackTrace();
>                    }
>                }
>            };
>
>            add(username);
>            add(searchContact);
>        }
>    }
> }
>
> what I'm doing wrong? I'm really confused...
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Refreshing-listview-using-AJAX-tp3301427p3301427.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>


-- 
Pedro Henrique Oliveira dos Santos

Reply via email to