Closed GoogleCodeExporter closed 8 years ago
helping the developer through email...closing this issue here
Original comment by jeff.johnston.mn@gmail.com
on 9 Mar 2011 at 7:24
Hi Jeff, I'm really curious how this was solved as I'm running into a similar
problem.
I have a list of records, upon clicking a row, a GET request is performed to
show the detail view of that record, but when I navigate away from that detail
view I want to arrive on the same page where I left off. The
'stateAttr="restore"' and the URL parameter (which I add when nvaigating away
from the detail view) 'restore=true', don't seem to do the trick.
Is't it possible to show the solution here? Thanks in advance.
Original comment by rpbran...@gmail.com
on 13 Apr 2011 at 2:29
Strange. What version of JMesa are you on? Are your table id's unique in the
app?
http://code.google.com/p/jmesa/wiki/State
The issue with this post was something else...
Original comment by jeff.johnston.mn@gmail.com
on 13 Apr 2011 at 8:53
Do you mean that the row that you left is not highlighted, or is it that the
State feature itself is not working?
Original comment by jeff.johnston.mn@gmail.com
on 14 Apr 2011 at 5:01
Hi Jeff, we're using the latest 3.0.4 release and use unqiue id's. Yes what I
mean is that with the tutorial code, the state feature isn't working unless
additional code is added.
I finally got it working with some extra code that I don't see appearing in
your tutorials.
In the BasicPresidentController I see a single method handling the GET and POST
requests. What I don't
see there is that you retrieve the page number from the state and feeding it to
the service to retrieve
the page that you actually want to view. It seems you're always retrieving the
same set of presidents
from the database (all of them) and let JMesa take a subset from that. In a
case where you use paging,
you typically deal with lot's of records that you don't want to be retrieved
from the database.
Anyway, this is the setup based on SpringMVC with annotations:
What happens is that not all our requests are POSTs, the scenario is this:
1. User arrives on list view via a GET request, since no state is available the
user is shown the first page
2. User jumps to page X via a POST request and is still shown the list view
3. User clicks on a row and arrives on a detail page via a GET request
4. User performs some action/or cancel and should arrive back on page X
In the list view JSP:
<jmesa:springTableModel id="client_table" items="${clients}" var="bean"
limit="${limit}" stateAttr="restore">
<jmesa:htmlTable>
<jmesa:htmlRow filterable="false" uniqueProperty="id">
<jmesa:htmlColumn property="name" sortable="false" headerClass="header-name" titleKey="jmesa.table.client.name"/>
<jmesa:htmlColumn property="description" sortable="false" headerClass="header-description" titleKey="jmesa.table.client.description"/>
<jmesa:htmlColumn property="" sortable="false" filterable="false" headerClass="header-delete" styleClass="cell-delete" title=" "/>
</jmesa:htmlRow>
</jmesa:htmlTable>
</jmesa:springTableModel>
In the controller:
@RequestMapping(value = "/admin/listClients.htm", method = RequestMethod.GET)
public ModelAndView listClients(final HttpServletRequest request,
@ModelAttribute(CRUD_COMMAND) final ClientCommand command) {
ModelAndView modelAndView = new ModelAndView("clientListView");
TableFacade tableFacade = new TableFacade("tclients", request);
tableFacade.setStateAttr("restore");
Limit limit = tableFacade.getLimit();
int pageNumber = 1;
if (limit.hasRowSelect()) {
pageNumber = limit.getRowSelect().getPage();
}
Page page = getPageNavigationAwareService().retrievePage(pageNumber, 10);
tableFacade.setItems(page.getResults());
limit.setRowSelect(new RowSelect(page.getPageNumber(), page.getSize(), page.getTotalRecords()));
modelAndView.addObject("items", page.getResults());
modelAndView.addObject("limit", limit);
return modelAndView;
}
/*
* In the method below, note the request parameter in the signature. If we click on one of the page numbers or next/previous/first/last
* we get that value as a request parameter but it it not available in the tablefacade.limit.rowselect.page since the rowselect is null.
* So, we pickup the request parameter ourselves to feed it to our back-end so that it knows which page to retrieve.
*/
@RequestMapping(value = "/admin/listClients.htm", method = RequestMethod.POST)
public ModelAndView navigateClients(final HttpServletRequest request,
@ModelAttribute(CRUD_COMMAND) final ClientCommand command,
@RequestParam(value = "tclients_p_", required = false) final Integer pageId) {
ModelAndView modelAndView = new ModelAndView("clientListView");
TableFacade tableFacade = new TableFacade("tclients", request);
tableFacade.setStateAttr("restore");
// START CODE ADDED BY ME
State state = tableFacade.getState(); // Retrieving the Limit directly from the facade returns a Limit object with a null rowSelect
Limit limit = state.retrieveLimit();
int pageNumber = pageId;
if (limit != null && limit.hasRowSelect()) {
pageNumber = limit.getRowSelect().getPage();
} else {
limit = new Limit("tclients");
state.persistLimit(limit);
}
Page page = getPageNavigationAwareService().retrievePage(pageNumber, 10); // Note that we always load a specific page
limit.setRowSelect(new RowSelect(page.getPageNumber(), page.getSize(), page.getTotalRecords()));
// END CODE ADDED BY ME
modelAndView.addObject("items", page.getResults());
modelAndView.addObject("limit", limit);
return modelAndView;
}
Original comment by rpbran...@gmail.com
on 15 Apr 2011 at 9:22
Because you are using the 3.0 release this could be much more simple. Did you
see the new PageItems interface? It will abstract out all the low level work
with the facade that you are doing.
http://code.google.com/p/jmesa/wiki/LimitTutorialV3
When using the tag library you would use the TableModelUtils.getItems() and
then not set the Limit on the the tag...take out the limit="${limit}". The
utils method will pass that for you.
If you do want to go to a specific page you could set the
Limit.getRowSelect().setPage() first in the PageItems.getItems() method. This
would recalculate the RowSelect for you based on the new page.
The only thing I do not see in your example is where you get the max rows from.
You need the max rows to get a proper RowSelect, which is why the PageItems
asks for it explicitly.
You should also set the autoFilterAndSort to false on the tag as you are doing
the filtering and sorting yourself.
Hope that helps! The new TableModel stuff was created to abstract out the
details of working with the facade so I would always use that...unless you are
doing something so custom that you need the lower level object.
Original comment by jeff.johnston.mn@gmail.com
on 15 Apr 2011 at 3:14
Ok thanks Jeff!
Original comment by rpbran...@gmail.com
on 20 Apr 2011 at 11:28
Hi ,
I am new to jmesa .
I have created table using jmesa tag libray .Now the requirement is to do the
pagination. i.e is to pull only the required records from the database. Please
help me with the examples.
Regards,
Resh
Original comment by reshmabh...@gmail.com
on 2 Feb 2012 at 4:36
Original issue reported on code.google.com by
zach.ro...@gmail.com
on 1 Mar 2011 at 8:58