Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Use of DataModle in JSF  RSS feed

 
Varadhan Sesharaman
Ranch Hand
Posts: 30
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys

Can anyone explain what the usage of DataModle in JSF.
And is there any way not to use the DataModle while using List in JSF

Thanks
 
Kumaravadivel Subramani
Ranch Hand
Posts: 171
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see any need for DataModel when you use List in JSF. Read about DataModel here. webpage
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The DataModel classes are used to serve as the Model sub-component of a dataTable MVC triad. It contains metadata used to ensure that the application knows where in the dataTable action is occurring. Specifically, its getRowData and getRowIndex methods allow an action method to know what row a request is being made for.

One of the most common mistakes that JSF beginners make is putting the DataModel object in Request scope. When you do that, the original DataModel is destroyed when the page has completed rendering. Clicking on a commandLink or commandButton for a row in the rendered table will then fail, because a new, uninitialized DataModel will be created when the action fires.

I've seen indications that in JSF2 it's possible to forgo the dataModel and reference a collection directly, but I don't think I ever saw it explicitly documented. In any event, the dataModel still exists, it's just created automatically. But since there's no application definition, you can't get hold of it when you need it, so I recommend creating the dataModel explicitly.

I often subclass DataModel for various reasons. One of the most common things I do with such subclasses is add properties to hold column total values.
 
Varadhan Sesharaman
Ranch Hand
Posts: 30
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kumaravadivel and Tim.

I got a clear idea now.

But we must use DataModel for list in JSF 1.2.
And there is also posibility not to use the DataModel in JSF 2.0.

Is it correct?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Varadhan Sesharaman wrote:Thanks Kumaravadivel and Tim.

I got a clear idea now.

But we must use DataModel for list in JSF 1.2.
And there is also posibility not to use the DataModel in JSF 2.0.

Is it correct?


Like I said, I've seen indications that sometimes you can reference collections directly in JSF2, but I don't think that the JSF2 spec specifically allows it. In any event, a DataModel is still being built, but you wouldn't be able to access it, and you need that DataModel if you want to figure out which row of a table an action was fired from. So you are better off building the DataModel yourself.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!