On Mon, Nov 9, 2009 at 6:21 AM, <[email protected]> wrote:
> Hi all,
>
> I browsed a lot of wicket example and searched through many articles,
> but never found this classical web application example : I would have on
> the same page a form with some criteria, a search button and a result
> list : I enter some data, hit search and get the results under my
> criteria, just like google does.
>
> No problem for me to define all these parts using wicket components, but
> I don't know how to manage the workflow, and especially what code
> should I put in my form's onSubmit method.
you dont need to put any code in your onsubmit...
class mysearchpage extends webpage {
private searchcriteria criteria=new searchcriteria();
public mysearchpage() {
add(new searchcriteriaform("form", new propertymodel(this,
"searchcriteria")));
^ form object connected to the criteria field of this page via a
property model
add(new listview("results", new propertymodel(this,
"searchresults")) {...});
^ listview that will display results retrieved from the
getSearchresults() method on this page
}
public list getSearchresults() {
// get whatever results based on the criteria field
}
}
so in short, form pushes your criteria into the criteria field,
listview uses the criteria field to build the resultset. yes, its that
simple :)
-igor
>
> Here is a sample code :
>
> public class TestPage extends WebPage {
> public TestPage() {
> super();
> createComponents();
> }
>
> �...@suppresswarnings("serial")
> protected void createComponents() {
> final WebMarkupContainer datacontainer = new
> WebMarkupContainer("data");
>
> Form<SearchParameterBean> searchForm = new
> Form<SearchParameterBean>("searchForm",
> new
> CompoundPropertyModel<SearchParameterBean>(new SearchParameterBean())) {
> �...@override
> protected void onSubmit() {
> SearchParameterBean searchParam =
> (SearchParameterBean) getModelObject();
> // get contract list in a
> LoadableDetachableModel, but can't give it to ListView
> IModel<List<ResultParameter>>
> contractListModel = new LoadableDetachableModel<List<ResultParameter>>()
> {
> �...@override
> protected List<ResultParameter>
> load() {
> List<ResultParameter>
> contractList = manageContract.getContracts();
> return contractList;
> }
> };
> // This is working, but I must have an
> inner class and final WebMarkupContainer datacontainer
> // What to do if I want to create a
> class ConsultForm extends Form<SearchParameterBean>
> datacontainer.setVisible(true);
>
> }
> };
> searchForm.add(new TextField<String>("Id"));
> add(searchForm);
>
> datacontainer.setVersioned(false);
> datacontainer.setVisible(false);
> add(datacontainer);
>
> // here I do not have access to my contractListModel
> PageableListView<ResultParameter> listView = new
> PageableListView<ResultParameter>("contracts", contractListModel, 10){
> �...@override
> public void
> populateItem(ListItem<ResultParameter> listItem) {
> ResultParameter contract =
> listItem.getModelObject();
> Label name = new Label("Name",
> contract.getName());
> listItem.add(name);
> }
> };
> datacontainer.add(listView);
> }
>
>
> The questions I have are :
> - How to pass model between the onSubmit() message which defines it, and
> the FormView which shows itin the page ?
> - Do I have to define a setResponsePage() in my onSubmit() ? If I do so,
> I must go to another page, and then I lost the user's choosen criteria
> - What is the best practice to build such an application ?
> - Is there somewhere an example with criteria and results on the same
> page ?
>
> Thank you very much,
> Bernard
>
> *********************************
> This message and any attachments (the "message") are confidential and
> intended solely for the addressees.
> Any unauthorised use or dissemination is prohibited.
> Messages are susceptible to alteration.
> France Telecom Group shall not be liable for the message if altered, changed
> or falsified.
> If you are not the intended addressee of this message, please cancel it
> immediately and inform the sender.
> ********************************
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]