Hi,
I have a UCSearch.jsp page (usecase search) which has a set of filter criteria and a
search button. The filter criteria includes a drop down list box and few text boxes.
Following is my maverick.xml file...
<command name="UCSearch">
<controller class="steps.uc.web.ctl.UCSearchController" />
<view name="success" path="/uc/UCSearch.jsp" />
</command>
<command name="UCSearchResults">
<controller class="steps.uc.web.ctl.UCSearchResultsController" />
<view name="success" path="/uc/UCSearch.jsp" />
</command>
The controllers extends from FormBeanUser controller. When the page 1st loads up
(UCSearch.m) the UCSearchController instantiates a SearchModel class which includes
all the getter and setters for the UCSearch.jsp page including the results (empty
collection). The controller sets the collection for the drop down filter criteria, and
eventually calls the ctx.setModel (). The page loads up fine, but when I do the
search (UCSearchResults.m), what needs to be done in the makeFormBean() of the
UCSearchResultsController? if I try to return new SearchModel(), I loose the values
populated in the dropdownlist. The ctx.getModel() method returns a null.
The workaround I did was put the SearchModel in the session in the perform() method of
UCSearchController() and retrieve it back from the session in the makeFormBean() of
the UCSearchResultsController, this way I was able to retain the values of the drop
down and also the new search filters selected were populated in the model, which I
then used in the perform() to do the actual search.
Is this the right way to do it? how would I persist the dropdown list otherwise? why
do the cctx.getModel() returns null in the second controller when I had explicitly set
the model in the first controller. Isn't it that the model should exists in the
context.
Thanks,
Deo
Additional info...
UCSearchController...
protected String perform(Object formBean, ControllerContext ctx) throws Exception
{
SearchModel sm = (SearchModel) formBean;
Increment ic = new Increment();
sm.setSearchIncrements(ic.findAll());
ctx.setModel(sm);
ctx.getRequest().getSession().setAttribute("SEARCH_MODEL", sm);
return SUCCESS;
}
UCSearchResultsController...
protected Object makeFormBean(ControllerContext cctx) {
SearchModel sm = (SearchModel)
cctx.getRequest().getSession().getAttribute("SEARCH_MODEL");
if (sm == null)
{
return new SearchModel();
}
else
{
return sm;
}
}
protected String perform(Object formBean, ControllerContext ctx) throws Exception {
try
{
SearchModel sm1 = (SearchModel) ctx.getModel();
UseCase useCase = new UseCase();
List ucList = useCase.findUsecase(sm.getSearchName(), sm.getSearchNumber(),
Integer.parseInt(sm.getSearchIncrementId()));
sm.setUseCases(ucList);
if (ucList.size() > 0)
{
sm.setDisplayResults(true);
}
else
{
sm.setDisplayResults(false);
}
}
catch (Exception e)
{
System.out.println(e);
}
return SUCCESS;
}
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
[INVALID FOOTER]