I found a solution that worked.

I didn't realize that by adding the value passed in to a PageParameters
object and then setting the response page I was telling Wicket to add that
to the URL. I got rid of that.

I changed my form to this use the CompoundPropertyModel:
Form<?> form = new Form<CnavDisplay>("searchForm", new
CompoundPropertyModel<CnavDisplay>(this));

I also added a class attribute for search and moved my onsubmit into a
Button declaration.

        final CnavUrlDataProvider dataProvider = new CnavUrlDataProvider();

        final TextField<String> searchField = new
TextField<String>("search", new PropertyModel(this,"search"));
        Form<?> form = new Form<CnavDisplay>("searchForm", new
CompoundPropertyModel<CnavDisplay>(this));
        Button submitButton = new Button("searchButton") {          // (4)
            @Override
            public void onSubmit() {
                if (search != null && !search.isEmpty()) {
                    dataProvider.setSearch(search);
                }
            }
        };

        add(form);
form.add(searchField);
        form.add(submitButton);

Thanks,
Daniel



On Wed, Jun 12, 2013 at 9:39 AM, Daniel Watrous <dwmaill...@gmail.com>wrote:

> Hello,
>
> I created a single page that shows some data using DataView. I then added
> a form and allow a filter argument to be passed in. The problem I'm getting
> is that the first time a search is done, the search value is added to the
> URL for the page. Subsequent searches are ignored due to the query string.
>
> I have looked for some way to change it to GET, but couldn't find that. I
> also looked for some way to prevent the URL from being modified, but I'm
> not clear on why that is happening either.
>
> Any idea how to fix this?
>
> Here's my Page code
>
>     public CnavDisplay(PageParameters parameters) {
>         super(parameters);
>
>         final TextField<String> search = new TextField<String>("search",
> Model.of(""));
>         Form<?> form = new Form<Void>("searchForm") {
>
> @Override
> protected void onSubmit() {
>
> final String searchValue = search.getModelObject();
>
> PageParameters pageParameters = new PageParameters();
> pageParameters.add("search", searchValue);
>  setResponsePage(CnavDisplay.class, pageParameters);
>
> }
>
> };
>
>         add(form);
> form.add(search);
>
>         CnavUrlDataProvider dataProvider = new CnavUrlDataProvider();
>         if (!parameters.get("search").isEmpty()) {
>             dataProvider.setSearch(parameters.get("search").toString());
>         }
>
>         DataView<CnavUrl> dataView = new DataView<CnavUrl>("repeating",
> dataProvider) {
>             private static final long serialVersionUID = 1L;
>
>             @Override
>             protected void populateItem(final Item<CnavUrl> item)
>             {
>                 CnavUrl cnavUrl = item.getModelObject();
> //                item.add(new Label("cnavid",
> String.valueOf(((MorphiaCnavUrl)cnavUrl).getId())));
>                 item.add(new Label("url", cnavUrl.getURL()));
>                 item.add(new Label("type", cnavUrl.getType()));
>
>                 item.add(AttributeModifier.replace("class", new
> AbstractReadOnlyModel<String>()
>                 {
>                     private static final long serialVersionUID = 1L;
>
>                     @Override
>                     public String getObject()
>                     {
>                         return (item.getIndex() % 2 == 1) ? "even" : "odd";
>                     }
>                 }));
>             }
>         };
>
> Here's my application where I mount the page
>
>         mountPage("/cnavlink", CnavDisplay.class);
>
> Any ideas?
>
> Thanks,
> Daniel
>

Reply via email to