Hi Francisco, I can't see anything logically wrong with your code, all though there are things I would have done differently. What is the output of the wicket ajax debug panel when you click on the ajax submit button?
If you want some advice, I would suggest not using a pageablelistview and not keeping your search results as an instance member (unless they are very expensive to create). Instead, look into using DefaultDataTable or extending DataTable. That way you can put all your search logic in your IDataProvider (such as SortableDataProvider), and retrieve only the results you will display in the current page, and not carry them around in the session after the request is over. Hope this helps. best, jim On 6/6/07, Francisco Diaz Trepat - gmail <[EMAIL PROTECTED]> wrote: > Sorry but I cannot find what the problem is. I've search Nabble. > > --------------------------------- > > > > Hello every one, I have a page that uses a panel (code ahead) that has a > form with an AJAX button, it works fine, but some times I have to click on > the Search button 2 times to make it work. I think it has to do with URLs or > something because when it happens it changes the url. > > The code for the page that uses the following panel I don't include because > it only has a statement saying add(new SearchPanel(etc... > > Here is the code, can some one help? > > ps: If any other comments like, your code sucks, please also include them. > > thanks a bunch > > f(t) > > and here is the code: > > package ch.logismata.wicket.panels.ajax; > > import ch.logismata.serverwrapper.DossierSearch; > import ch.logismata.serverwrapper.DossierSearchResult ; > import ch.logismata.serverwrapper.DossierSearchResultList; > import ch.logismata.wicket.pages.NewDossier; > import ch.logismata.wicket.panels.BasePanel; > import java.io.Serializable; > import java.util.ArrayList ; > import wicket.AttributeModifier; > import wicket.Component; > import wicket.PageParameters; > import wicket.ajax.AjaxRequestTarget; > import wicket.ajax.markup.html.form.AjaxSubmitButton; > import > wicket.ajax.markup.html.navigation.paging.AjaxPagingNavigator > ; > import wicket.markup.html.WebMarkupContainer; > import wicket.markup.html.basic.Label; > import wicket.markup.html.form.Form; > import wicket.markup.html.form.TextField; > import wicket.markup.html.link.Link; > import wicket.markup.html.list.ListItem; > import wicket.markup.html.list.PageableListView; > import wicket.markup.html.panel.FeedbackPanel; > import wicket.model.AbstractReadOnlyModel; > import wicket.model.CompoundPropertyModel ; > import wicket.model.Model; > import wicket.model.ResourceModel; > > /** > * Panel to make a Dossier Search and display the results > * > * @author gm > */ > public class DossierSearchPanel extends BasePanel { > private SearchDossierModel m_cSearchDossierModel = new > SearchDossierModel(); > private ArrayList<DossierSearchResult> m_cSearchResults = new > ArrayList<DossierSearchResult>(); > public DossierSearchPanel(String id) { > //Call super base panel > super(id); > // create feedback panel to show errors > final FeedbackPanel feedback = new > FeedbackPanel("searchFeedback"); > //add feedback panel > feedback.setOutputMarkupId(true); > add(feedback); > > // create form with markup id setter so it can be updated via ajax > Form form = new Form("dossierSearchForm", new > CompoundPropertyModel(m_cSearchDossierModel)); > form.setOutputMarkupId(true); > > form.add(new Label("legend", new > ResourceModel("fields.legend"))); > form.add(new Label("nameLabel", new ResourceModel(" > fields.name"))); > //Construct TextFields > TextField cNameTextField = new TextField("name"); > TextField cLastNameTextField = new TextField("lastName"); > //add Fields to the form > form.add(cNameTextField); > form.add(new Label("lastNameLabel", new > ResourceModel("fields.lastName"))); > form.add(cLastNameTextField); > > > > ///Add pageable table > final WebMarkupContainer datacontainer = new > WebMarkupContainer("data"); > datacontainer.setOutputMarkupId(true); > add(datacontainer); > > Model modelForList = new Model(){ > public Object getObject(Component component){ > return m_cSearchResults; > } > }; > > final PageableListView listview = new PageableListView("rows", > modelForList, 10) { > > protected void populateItem(final ListItem item) { > final DossierSearchResult dossierSearchResult = > (DossierSearchResult)item.getModelObject(); > > item.add(new Link("goToDetail") { > public void onClick() { > setResponsePage(NewDossier.class, new > PageParameters("dossierId="+dossierSearchResult.getDossierObjectId())); > } > }.add(new Label("composedName", > dossierSearchResult.getComposedName()))); > > item.add(new Label("streetAddress", > dossierSearchResult.getStreetWithNumber ())); > item.add(new AttributeModifier("class", true, new > AbstractReadOnlyModel() { > public Object getObject(Component component) { > return (item.getIndex () % 2 == 1) ? "even" : "odd"; > } > })); > } > }; > if(m_cSearchResults.size()==0){ > > } > listview.setOutputMarkupId (true); > datacontainer.add(listview); > datacontainer.add(new > AjaxPagingNavigator("navigator", listview)); > datacontainer.setVersioned(false); > > > // add a button that can be used to submit the form via ajax > form.add(new AjaxSubmitButton("searchButton", form) > { > protected void onSubmit(AjaxRequestTarget target, Form form) { > // repaint the feedback panel so that it is hidden > > searchDossiers(m_cSearchDossierModel.getName(), > m_cSearchDossierModel.getLastName()); > if(m_cSearchResults.size()==0){ > datacontainer.setVisible(false); > }else{ > datacontainer.setVisible(true); > } > target.addComponent(feedback); > > target.addComponent(datacontainer); > } > > protected void onError(AjaxRequestTarget target, Form form) { > // repaint the feedback panel so errors are shown > target.addComponent(feedback); > } > }); > //Add Form > add(form); > } > private void searchDossiers(String name, String lastName){ > > String message = null; > try{ > if(m_cSearchResults==null){ > m_cSearchResults = new > ArrayList<DossierSearchResult>(); > } > m_cSearchResults.clear(); > DossierSearch cDossierSearch; > DossierSearchResultList cDossierSearchResultList; > > cDossierSearch = new DossierSearch(); > > if(name==null){ > name = ""; > } > if(lastName==null){ > lastName = ""; > } > > cDossierSearch.setFirstName(name); > cDossierSearch.setName(lastName); > > cDossierSearchResultList = cDossierSearch.search(); > > message = > cDossierSearchResultList.size()>0?cDossierSearchResultList.size()+" > Dossiers found at search.":"No Dossiers found at search."; > info(message); > for(int iIterator=0;iIterator< > cDossierSearchResultList.size();iIterator++){ > > m_cSearchResults.add((DossierSearchResult)cDossierSearchResultList.getItem(iIterator)); > } > /* > for(int iIterator=0;iIterator<100;iIterator++){ > DossierSearchResultEntity cDossierResultEntity = new > DossierSearchResultEntity("DossierObjectId-"+iIterator, > "ComposedName-"+iIterator, "StreetWithNumber-"+iIterator, > "ZipWithLocation-"+iIterator, iIterator); > m_cSearchResults.add(cDossierResultEntity); > }*/ > } catch(Exception xException){ > message = "Error Occured at > DossierSearchPanel.searchDossiers().\n"+xException.toString(); > error(message); > } > } > public boolean isVisible() { > return getWicketSession().isUserLoggedIn(); > } > > /** simple java bean. */ > private static class SearchDossierModel implements Serializable { > private String name, lastName; > > /** > * Gets lastName. > * > * > * @return lastName > */ > public String getLastName() { > return lastName; > } > > /** > * Sets lastName. > * > * > * @param lastName > * lastName > */ > public void setLastName(String lastName) { > this.lastName = lastName; > } > > /** > * Gets name. > * > * @return name > */ > public String getName() { > return name; > } > > /** > * Sets name. > * > * @param name > * name > */ > public void setName(String name) { > this.name = name; > } > } > } > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Wicket-user mailing list > Wicket-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/wicket-user > > ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user