I posted this on
java's forum but I figured I should widen my exposure as I haven't had anybody write back yet. Please forgive me if this is overly simplistic, but I can't find an answer.
Both posts were from me. The basic issue is having a relatively simple table list, assumed to be from a database. The user should be able to click on a link and go to a detail page. I currently implement this with the age old "somePage.jsp?id=123" logic. I'm trying to do the
JSF equivalent and running into very obvious issues.
I think there might be a paradigm mismatch, as if you were working with a desktop app, you would have to hit some type of refresh button to repopulate your list of table entries. In jsf, you can keep your entries in a session variable and only change that list when the user explicity requests the refresh. That makes sense to a programmer, but that's not really what one would expect on the web. When the page reloads, there's an expectation that what you're looking at is what's current. This also doesn't solve the back button problem.
Anyway, the posts...
****************** First Post ******************
I've been working with JSF for about a week, and I think there's something I'm really missing with the datamodel/table structure. I want to build a simple table that displays a list of items, and allows the user to click on one to (generally) see detail on that item. This is a basic ui
pattern in web development.
Generally I do this by appending an id value(s) of some type(s) to the query
string, and using that in the target url to pull up and display data.
I've been working from the O'reilly jsf book. The example in there provides the following accessor for table entries in its chapter 10 example...
/**
* Returns a DataModel with Report instances matching the
* filtering criteria, sorted according to the current
* sort column and order.
*/
public DataModel getSortedReportsModel() {
if (reportsModel == null) {
reportsModel = new ListDataModel();
}
List reports = getReports();
sortReports(reports);
reportsModel.setWrappedData(reports);
return reportsModel;
}
The basic idea here is that the
jsp page uses this as its data source for the table of elements to choose from...
<f:view>
<h:form>
<h

ataTable value="#{reportHandler.sortedReportsModel}" var="report">
<h:column>
<f:facet name="header">
<h:commandLink action="#{reportHandler.sortByTitle}"
immediate="true">
<h

utputText value="Title" />
</h:commandLink>
</f:facet>
<h:commandLink action="#{reportHandler.select}" immediate="true">
<h

utputText value="#{report.title}" />
</h:commandLink>
</h:column>
<h:column>
[more code...]
My questions are as follows:
1. What happens if somebody adds an entry between the time the user first gets the list and when they click on a link? The entries are linked by index and not id, so this could pose a problem.
2. What happens if, for example, the user gets the list, then sorts by a different value, then clicks back and clicks a link? On the server it would still use the list position, but with the new sorting, to decide which element to pick.
Does there exist some DataModel extension or renderer that could allow list selection by value rather than by index? Again, I've been doing jsf for about a week, so I'm not sure if that's a stupid question.
I'm assuming that I'm either doing this wrong or there is an easy way to get this to work as I think it should, and have a more natural flow. I'm just missing something.
Thanks in advance,
-Kevin
****************** End First Post ******************
****************** Second Post ******************
I got the example from the O'reilly book running and tried my little problem example. It had the same issue as my application as far as selecting list elements.
Now, the only reasons I'm picking on this example are that:
a) Its pretty public, as you can buy the book and/or download the example at
http://www.hansbergsten.com/downloadjsf.jsp b) Considering the book I'm using and the author, this is how one "should" be implementing this.
Anway, if you install this app, and go to the index page, click on expense report app final version in "Chapter 12". Enter say 3 report entries, with various dates. Then open a different window, preferably in a different browser to prevent session tampering (but I don't think this is required). Click on "Report List Area, stage 3". You'll see your 3 entries. Go back to the other browser, and add another entry.
Make sure this date is the newest of the group. Alt+Tab back to the other browser with the table list. Click on the
first. You would expect to see the entry you clicked on, but you will see the newest entry.
This is clearly not how this should be implemented. What's the recommended way to handle this?
****************** End Second Post ******************