Note that there are some explanatory texts on larger screens.

plurals
  1. POWicket - updating ListView using AJAX and Wicket Model
    text
    copied!<p>I have a :</p> <ul> <li>Client Class</li> <li>ListView</li> <li>TextField</li> </ul> <p>I need to populate my ListView in order to form a table:</p> <p>WORKING CODE:</p> <pre><code>clientModel = new LoadableDetachableModel() { @Override protected Object load() { return Client.getClientListByCompanyName(searchClientInput.getValue()); } }; searchClientInput.setModel(new Model&lt;String&gt;()); searchClientInput.add(new AjaxFormComponentUpdatingBehavior("onkeyup") { @Override protected void onUpdate(AjaxRequestTarget target) { target.add(clientListViewContainer); } }); clientListView = new ListView&lt;Client&gt;(CLIENT_ROW_LIST_ID, clientModel) { @Override protected void populateItem(ListItem&lt;Client&gt; item) { Client client = item.getModelObject(); item.add(new Label(CLIENT_ROW_COMPANY_CNPJ_ID, client.getCompanyName())); item.add(new Label(CLIENT_ROW_COMPANY_NAME_ID, client.getCompanyCnpj())); } }; clientListViewContainer.setOutputMarkupId(true); clientListViewContainer.add(clientListView); add(clientListViewContainer); </code></pre> <p>Now, in my HTML, I have a TextField. Whenever an user types something in this TextField, a select will be made in the database with whatever he typed. So for each word, a select is made, and the table needs to be updated. I am guessing I will need to use AJAX and possibly a Model. I'm kind of lost about how I can do this, if someone can provide me examples I would be very grateful.</p> <p>EDIT: New code that is throwing exception: <code>Last cause: Attempt to set model object on null model of component: searchClientForm:searchClientInput</code></p> <p>EDIT 2: Ok so the exception was that my TextField didn't had a model to bind data to. So what I did was: <code>searchClientInput.setModel(new Model&lt;String&gt;());</code></p> <p>I also had a problem with the event. Using <code>onkeydown</code> was working, but not as intended. I had Company Name 1-4. If I typed Company Name 1, I would need to press one key again so the table would get updated. With <code>onkeyup</code> this don't happens. Thanks for the help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload