Two Laptop Bag*
The moose likes JSF and the fly likes commnadLink under DataTable doesn't work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "commnadLink under DataTable doesn Watch "commnadLink under DataTable doesn New topic
Author

commnadLink under DataTable doesn't work

Amitkumar Fulambarkar
Greenhorn

Joined: Sep 17, 2008
Posts: 29
Hi,

I have gone through couple of posts on this issue. Few post suggest to use session scope as it doesn't work for the managed bean in request scope. However, I don't want to move my bean to session scope as part of some functionality get breaks after doing it.

Some posts also says that commandLink does work in datatable for them with the bean in request scope.

Is there any way fix this issue or any workaround to implement similar functionality.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

Request scope won't work. Period. Sorry if you don't like it, but request scope creates the context needed (dataTable tablemode), displays the page and then destroys the context. That context is required for JSF to resolve which row you clicked in when the click request comes back. But the click request is not the same request as the display request was, so you're out of luck.

Historically, the only standard solution was to promote the backing bean's lifespan to the next level up (session scope). In JSF2, however, a new JSF-specific scope was defined: View Scope. It's actually Session scope, but unlike "true" session scope, the View Scope objects are automatically deleted when you navigate to a different page, so they don't hang around cluttering up your server memory.


Customer surveys are for companies who didn't pay proper attention to begin with.
Amitkumar Fulambarkar
Greenhorn

Joined: Sep 17, 2008
Posts: 29
Thank you Tim. I will try with the View scope.

Thanks for your advice. I read couple of posts which says session scopes resolves this issue, however I don't want put all the info in session. I will try with viewScope.

Thanks
Amit
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

ViewScope is actually a special implementation of Session Scope that cleans up after itself.

It's not a standard J2EE scope and it didn't exist in JSF version 1. It was added for JSF 2 because a LOT of us didn't like the idea of a bunch of "dead" objects hanging around in session scope long after we'd left the page where they were needed!
Gabriel Vince
Greenhorn

Joined: Feb 05, 2009
Posts: 24
Hi,
Just a note - a request scope could work, but still you are right, the system needs to identify the row. I usually specify a parameter with the displayed entity id (f: param inside the command link).
There is a drawback, the target page needs to map external params to bean attribs (e.g. via f:meta), what doesn't work with all portals
Gabriel
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

Parameterized actions are not supported in JSF1, and they're not really what JSF is all about.

More seriously, however, while you can brute-force your way into such things, they're not as full-featured as the datamodel object that serves as container for - and manages the cursor of - the underlying table view.

View scope was in large part invented because in request scope, the datamodel gets destroyed and recreated on each view request/postback and when it does, it loses the context that was in effect when the table was last rendered. Postbacks are very important in JSF, because they allow a View to be edited with error displays, keeping the entered data until the user either manages to make it all valid or gives up and goes elsewhere. And to do postback, you need a longer lifespan than Request scope offers.

But, like I said, "longer" doesn't necessarily mean "forever". The datamodel isn't needed once a different page is displayed, so View scope was created to ensure that the model lived long enough to be useful and then went away automatically.
Amitkumar Fulambarkar
Greenhorn

Joined: Sep 17, 2008
Posts: 29
Thank you all for the detail information.

Unfortunately, I am still on JSF 1.1 so I cannot take the benefit of ViewScope

I also cannot change the scope of the bean to session, as it had broke few other things that I have already implemented. Don't know what to do now

Any work around?
Amitkumar Fulambarkar
Greenhorn

Joined: Sep 17, 2008
Posts: 29
It is resolved.

I kept the data in the session and then set the list property from the session data that I was iterating with DataTable. It made commandLink working.

So I can say the commandLink works in the datatable with managed bean in request scope.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: commnadLink under DataTable doesn't work
 
Similar Threads
[forEach / commandLink / ajax] Illogical functionality
Backing Method not Being Called
Dynamic columns at rich:scrollableDataTable
Problem with commandButton inside dataTable
collapsible inside a datatable. binding problem?