You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by steviezz <st...@gmail.com> on 2008/03/04 14:42:39 UTC
Use Ajax for loading form dropdowns, but query params for search?
I am using Ajax to populate 3 related DropDownChoice widgets in a search form
(area, country, region) - see my
http://www.nabble.com/Combining-Ajax-and-non-Ajax-pages-tt15587166.html#a15587166
previous thread for more info.
I am trying to maintain the search criteria in a model stored in the session
so that the selected form state (used inside a panel on the site home page
and reused in the search results page) reflects the displayed search results
and survives navigation to and from the home page, page refreshes, back
button clicks, etc. I more or less have this working.
But I now want the results page to be bookmarkable (including query params).
I'm currently trying to use my model object stored in the session just to
maintain the state for the dropdowns, then submit the form to a mounted
bookmarkable page to show the results.
I can then take the page params and pass to my backend to do the actual
search before displaying the results.
Only problem I have now is that if someone comes in via a bookmarked page
link, then the dropdown state will likely not be correctly initialised -
either no model in session (default search form widgets - I can live with
this) or a previous session model reflecting a different set of criteria
than the query params and displayed results (I can't live with this).
The rationale behind doing this whole thing is that I want my search results
to be capable of being spidered from bookmarkable search results pages (so
needs URL params rather than form post). But I do care about human users
seeing incorrect state between the search form selections and the displayed
results.
So now I have to worry about resetting the session model when a bookmarked
page is requested then updating the Ajax dropdowns. It's getting very messy
and I feel I'm digging myself into a hole.
So, is there an easy way to do this, or do I stop digging?
--
View this message in context: http://www.nabble.com/Use-Ajax-for-loading-form-dropdowns%2C-but-query-params-for-search--tp15827399p15827399.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Use Ajax for loading form dropdowns, but query params for
search?
Posted by steviezz <st...@gmail.com>.
Thanks. Yes, your code is similar to what I am doing.
But trying to sych the Ajax dropdown state with the page parameters is
defeating me. There are effectively two ways of getting to the results page
- search form post and directly from a bookmarked URL.
I'm using a CompoundPropertyModel containing my own SearchModel class -
holds the values selected in the dropdowns - not the actual dropdown
objects, eg:
public class SearchModel implements Serializable {
private String area;
private String country;
private String region;
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
// more getters and setters
}
Then in the panel class, I have something like:
final CompoundPropertyModel searchPropertyModel = ((WholSession)
Session.get()).getSearchModel();
setModel(searchPropertyModel);
DropDownChoice areaDDC = getAreaDDC(searchPropertyModel);
private DropDownChoice getAreaDDC(final CompoundPropertyModel model) {
PropertyModel areaModel = new PropertyModel(model, AREA);
LoadableDetachableModel areaLDModel = new LoadableDetachableModel() {
public Object load() {
return ((WholApplication) getApplication()).getAreas();
}
};
DropDownChoice areaDDC = new DropDownChoice(AREA, areaModel, areaLDModel)
{
protected CharSequence getDefaultChoice(Object selected) {
return ALL_AREAS;
}
};
areaDDC.add(new AjaxFormComponentUpdatingBehavior(ONCHANGE) {
protected void onUpdate(AjaxRequestTarget target) {
countryDDC.clearInput();
countryDDC.setModelObject(null);
regionDDC.clearInput();
regionDDC.setModelObject(null);
target.addComponent(countryDDC);
target.addComponent(regionDDC);
}
});
areaDDC.setNullValid(false);
areaDDC.setOutputMarkupId(true);
return areaDDC;
}
SearchModel is set in the session in my panel constructor like:
final CompoundPropertyModel searchPropertyModel = ((WholSession)
Session.get()).getSearchModel();
setModel(searchPropertyModel);
and again in the form's onSubmit()
This mostly works (I still get some unpredictable state with some
combinations of dropdown changes and backbutton clicks when I don't submit
the form). I have set no-cache headers on the pages with the search panel
to make it reload from the server instead of browser cache. I can just
about live with this, but it's clunky.
Essentially, the model I'm using to keep state for the related Ajax
dropdowns gets automatically updated by Wicket. It seems like a backwards
step to somehow manually try to update this from the page query params (not
even sure this is possible). I still can't work out how to do this - but
suspect it's a bad idea.
No doubt my code can be improved (I'm still trying to get my head around
Wicket - I'm struggling because I have no Swing background, and still try to
do everything like Struts / Servlet / JSP).
I've spent far too long on this already - good for learning, but frustrating
because I'm failing. Not blaming Wicket - this particular problem was
beyond me using Struts with DWR for the AJAX bits, so I ended up not using
AJAX and just refreshing the whole page on dropdown onchange events and
building the search box contents and selectins on the server. I suspect I
may have to go the same way if I want to use Wicket - or drop my requirement
for AJAX with synchonised search box widgets, search params and search
results.
I can feel a user interface redesign coming soon.
I seem to spend most of my time trying to work around Wicket rather than
with it - my problem, I know. But mostly it has been easy to bolt Wicket
onto my backend application in place of the existing Struts / JSP front end
- many things are much easier to code in Java than in JSP taglibs.
lars vonk wrote:
>
> We are building a somewhat similar application. The only difference is
> that we don't need to synch the search criteria with the search panel
> (the Ajax dropdowns in your case), since the search panel in our
> application will do a clean search when used from the results page.
>
> The code looks something like this, which I don't think is too messy:
>
> ResultPage extends WebPage {
> private SearchCriteria criteria
>
> // via bookmarked page
> ResultPage(PageParameters params) {
> searchCriteria = new SearchCriteria();
> setPageParametersOnSearchCriteria(searchCriteria);
> showResults(searchCriteria);
> }
>
> ResultPage(SearchCriteria criteria) {
>
> showResults(searchCriteria);
> }
> }
>
> Hopes this helps.
>
> Lars
>
> On Tue, Mar 4, 2008 at 2:42 PM, steviezz <st...@gmail.com> wrote:
>>
>> I am using Ajax to populate 3 related DropDownChoice widgets in a search
>> form
>> (area, country, region) - see my
>>
>> http://www.nabble.com/Combining-Ajax-and-non-Ajax-pages-tt15587166.html#a15587166
>> previous thread for more info.
>>
>> I am trying to maintain the search criteria in a model stored in the
>> session
>> so that the selected form state (used inside a panel on the site home
>> page
>> and reused in the search results page) reflects the displayed search
>> results
>> and survives navigation to and from the home page, page refreshes, back
>> button clicks, etc. I more or less have this working.
>>
>> But I now want the results page to be bookmarkable (including query
>> params).
>>
>> I'm currently trying to use my model object stored in the session just
>> to
>> maintain the state for the dropdowns, then submit the form to a mounted
>> bookmarkable page to show the results.
>>
>> I can then take the page params and pass to my backend to do the actual
>> search before displaying the results.
>>
>> Only problem I have now is that if someone comes in via a bookmarked
>> page
>> link, then the dropdown state will likely not be correctly initialised -
>> either no model in session (default search form widgets - I can live
>> with
>> this) or a previous session model reflecting a different set of criteria
>> than the query params and displayed results (I can't live with this).
>>
>> The rationale behind doing this whole thing is that I want my search
>> results
>> to be capable of being spidered from bookmarkable search results pages
>> (so
>> needs URL params rather than form post). But I do care about human
>> users
>> seeing incorrect state between the search form selections and the
>> displayed
>> results.
>>
>> So now I have to worry about resetting the session model when a
>> bookmarked
>> page is requested then updating the Ajax dropdowns. It's getting very
>> messy
>> and I feel I'm digging myself into a hole.
>>
>> So, is there an easy way to do this, or do I stop digging?
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Use-Ajax-for-loading-form-dropdowns%2C-but-query-params-for-search--tp15827399p15827399.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Use-Ajax-for-loading-form-dropdowns%2C-but-query-params-for-search--tp15827399p15862531.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Use Ajax for loading form dropdowns, but query params for search?
Posted by lars vonk <la...@gmail.com>.
We are building a somewhat similar application. The only difference is
that we don't need to synch the search criteria with the search panel
(the Ajax dropdowns in your case), since the search panel in our
application will do a clean search when used from the results page.
The code looks something like this, which I don't think is too messy:
ResultPage extends WebPage {
private SearchCriteria criteria
// via bookmarked page
ResultPage(PageParameters params) {
searchCriteria = new SearchCriteria();
setPageParametersOnSearchCriteria(searchCriteria);
showResults(searchCriteria);
}
ResultPage(SearchCriteria criteria) {
showResults(searchCriteria);
}
}
Hopes this helps.
Lars
On Tue, Mar 4, 2008 at 2:42 PM, steviezz <st...@gmail.com> wrote:
>
> I am using Ajax to populate 3 related DropDownChoice widgets in a search form
> (area, country, region) - see my
> http://www.nabble.com/Combining-Ajax-and-non-Ajax-pages-tt15587166.html#a15587166
> previous thread for more info.
>
> I am trying to maintain the search criteria in a model stored in the session
> so that the selected form state (used inside a panel on the site home page
> and reused in the search results page) reflects the displayed search results
> and survives navigation to and from the home page, page refreshes, back
> button clicks, etc. I more or less have this working.
>
> But I now want the results page to be bookmarkable (including query params).
>
> I'm currently trying to use my model object stored in the session just to
> maintain the state for the dropdowns, then submit the form to a mounted
> bookmarkable page to show the results.
>
> I can then take the page params and pass to my backend to do the actual
> search before displaying the results.
>
> Only problem I have now is that if someone comes in via a bookmarked page
> link, then the dropdown state will likely not be correctly initialised -
> either no model in session (default search form widgets - I can live with
> this) or a previous session model reflecting a different set of criteria
> than the query params and displayed results (I can't live with this).
>
> The rationale behind doing this whole thing is that I want my search results
> to be capable of being spidered from bookmarkable search results pages (so
> needs URL params rather than form post). But I do care about human users
> seeing incorrect state between the search form selections and the displayed
> results.
>
> So now I have to worry about resetting the session model when a bookmarked
> page is requested then updating the Ajax dropdowns. It's getting very messy
> and I feel I'm digging myself into a hole.
>
> So, is there an easy way to do this, or do I stop digging?
>
> --
> View this message in context: http://www.nabble.com/Use-Ajax-for-loading-form-dropdowns%2C-but-query-params-for-search--tp15827399p15827399.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org