File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Use of DataModle in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Use of DataModle in JSF" Watch "Use of DataModle in JSF" New topic
Author

Use of DataModle in JSF

Varadhan Sesharaman
Greenhorn

Joined: Apr 21, 2011
Posts: 18

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

Joined: Jul 05, 2008
Posts: 159

I don't see any need for DataModel when you use List in JSF. Read about DataModel here. webpage

No pain, No gain.
OCJP 1.6
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 12513

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.


One of the most odious afflictions that Business has inflicted on the modern English language is "pro-active". Most of the time it's simply redundantly used in place of the simple old word "active". And a good deal of the rest of the time it means "You're not overworked enough yet, so go out and find more!"
Varadhan Sesharaman
Greenhorn

Joined: Apr 21, 2011
Posts: 18

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
Saloon Keeper

Joined: Jun 25, 2001
Posts: 12513

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.
 
 
subject: Use of DataModle in JSF
 
Threads others viewed
Which Eclipse realise to develop JSF?
JavaServer Faces in Action: Reader question
resource bundle
jsf panelGrid
confirm of h:commandLink
IntelliJ Java IDE