aspose file tools*
The moose likes JSF and the fly likes Displaying Data Without DataTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Displaying Data Without DataTable" Watch "Displaying Data Without DataTable" New topic
Author

Displaying Data Without DataTable

Wai Meng Ng
Greenhorn

Joined: Feb 17, 2003
Posts: 22
Hello All,

I am a relative newbie to JSF. I have successfully retrieved a List of records and displayed it using the dataTable. However, I have become unstuck when I tried to retrieve a single object (the same as the ones in the List being displayed by the dataTable); but instead just display it using the outputText tag.

The data is being retrieved properly as I did a verbose to the Logs in the backing bean to confirm this, but somehow the data is not shown at the JSP.

This is my backing bean's method



This is a snippet of my JSP:



The JSP has a mixture of display elements and some inputText somewhere further down the page. I am not using the dataTable as I do not want to be constrained by the "tabular" look.

I checked out the internet and most examples show data only being displayed using dataTable, is it true that this is the only way to display retrieved data from the backing beans?

Many thanks in advance for your advice.


Cheers,
Wai Meng
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

I don't like to use the term "JSP" for JSF View definitions. Yes, that was an option in JSF 1, but it was never totally accurate. Just because you could define a JSF View definition in a "JSP" file didn't mean that the file was actually processed as a JSP - it was processed by JSF.

Datatables are designed to show tabular data, which is to say the kind of stuff you'd get by iterating rows of and displaying columns.

If you just want a rectangular layout, the dataTable isn't what you need. There's a different JSF tag for that, which is the h:panelGrid tag. It doesn't require a loop variable, because it doesn't loop, it just arranges the elements within it into a grid of however many columns you indicated as an attribute on the panelGrid element.



I actually usually do a 3-column entry form and put an "h:message for=" element in the third column so that field error messages display next to the fields that are in error.


Customer surveys are for companies who didn't pay proper attention to begin with.
Wai Meng Ng
Greenhorn

Joined: Feb 17, 2003
Posts: 22
Thanks for the advice Tim. So does it mean that the methoud I use (using dataTable) will actually not cause the values to be rendered and this is the expected behaviour? For single record to be displayed, only your recommended approach works?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

You are correct. If there are no rows in the datamodel, no rows will render in the datatable (except for constants like headers/footers).
Wai Meng Ng
Greenhorn

Joined: Feb 17, 2003
Posts: 22
Tim Holloway wrote:You are correct. If there are no rows in the datamodel, no rows will render in the datatable (except for constants like headers/footers).


Hi Tim,

Strange that the values are not returning after i retrieved them. In the Apache Logs excerpt, it shows that the values are indeed retrieved (see bold):


11:16:09,992 INFO SecurityFilter:? - requestUri = /wm.pet/faces/listTransaction.
11:16:09,995 INFO SecurityFilter:? - authorization succeeded
11:16:10,047 INFO TransactionBean:? -

WM: transactionId-> 5
11:16:10,050 INFO TransactionBean:? -
WM: transactionAction-> closeAction
Hibernate: select transactio0_.id as id0_, transactio0_.USERNAME as USERNAME0_, t
11:16:10,064 INFO TransactionBean:? -
WM: transaction Counter Name-> Tester
11:16:10,066 INFO TransactionBean:? -
WM: transaction Units-> 1000
11:16:10,069 INFO TransactionBean:? -
WM: transaction Selling Date-> 2011-08-03 00:00:00.0
11:16:10,078 INFO TransactionBean:? -
WM: transactionBean Counter Name-> Tester
11:16:10,084 INFO TransactionBean:? -
WM: transactionBean Units-> 1000
11:16:10,091 INFO TransactionBean:? -
WM: transaction Selling Date-> Wed Aug 03 00:00:00 SGT 2011
11:16:10,100 INFO TransactionBean:? - Product with id of 5is retrieved successfu
Aug 5, 2011 11:16:10 AM org.apache.myfaces.config.annotation.Tomcat7AnnotationLif
INFO: Creating instance of wm.pet.view.bean.TransactionBean


but from the view source from Firefox, it shows that the values are not shown as per using your suggestion compared to the value that is retrieved from the logs (above):



One more strange thing is that the entire table generated from the panelGrid although shown in ths view source, is not rendered on the web page. The page returns a blank. Is there something amiss? The current TransactionBean is in request scope, I tried putting it into session scope but to no avail. I was wondering is there some issue with the way the attributes values in the TransactionBean are populated in its loadEditAction() method that does not allow the values to get persisted to the web page? Are there some declarations that I need to do at the start of the JSF page like what we do in JSP to get the TransactionBean instance containing the values?

PS: I need to explain abit more about the navigation that eventually leads to this page. This page is traveresed from a previous page containing a dataTable rendered set of TransactionBeans. Upon clicking a 'Close' link on that respective row, my intention is to traverse to a new page with certain fields that are already populated (e.g. buying price and buying date) during the retrieving of the listing of TransactionBeans to be used in the dataTable. With the empty attributes like the 'selling price' and 'selling date' to be filled in by the user. When I did more trying out, I actually noticed that the particular row's TransactionBean has the values still populated from its earlier without needing to do another database retrieval (via logs in the loadEditAction() method). I assumed that since it was in request scope, that the values would be gone once I clicked on the 'Close' link and the request goes back to the server. Apparently not as the values are still there (like the Counter Name and Units etc.) even without needing to do another database retrieval. Would this be the cause of these values not being passed to the subsequent page as the indirection would not allow the values to span multiple pages, which is the one that is currently giving me the problems?

I guess in a nutshell my question is" "why are the values being correctly shown in the logs but not being able to be displayed on the web page?"

Thanks again!!
Wai Meng Ng
Greenhorn

Joined: Feb 17, 2003
Posts: 22
For reference, here is the TransactionBean Class



and here is the JSF Page



Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

I'm afraid that's too much detail for me to read. But Request scope has only a very limited utility in JSF, because JSF uses a postback mechanism that will re-recreate a new, empty backing bean on each new view request (page update). So whenever data vanishes, the first thing to do is promote the backing beans to session (or View) scope and see if they stay vanished or not.
Wai Meng Ng
Greenhorn

Joined: Feb 17, 2003
Posts: 22
Tim Holloway wrote:I'm afraid that's too much detail for me to read. But Request scope has only a very limited utility in JSF, because JSF uses a postback mechanism that will re-recreate a new, empty backing bean on each new view request (page update). So whenever data vanishes, the first thing to do is promote the backing beans to session (or View) scope and see if they stay vanished or not.

Hi Tim,

My apologies for the information overload. I tried putting the backing bean into session scope but to no avail. In short let me put the sequence of flow below:

1.Click Link -> 2.Calls TransactionListBean's method -> 2.(List of TransactionBeans populated) -> 4. JSF with dataTable display -> 5. Clicks on 'Close' Link on a particular row-> 6. Calls TransactionBean's method -> 7. (TransactionBean populated) -> 8. JSF showing the details

The problem happens at step 7 and step 8. It seems from the logs step 6 shows the values retrieved. Somehow during the "transit" to the JSF (step 8) the values are not set. Did i do anything wrong?

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying Data Without DataTable