• Post Reply Bookmark Topic Watch Topic
  • New Topic

[forEach / commandLink / ajax] Illogical functionality

 
Raul Vila
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting crazy with this two pieces of code:





The first one works properly, but with the second the function "editarTramo" is never reached.
I check the values of idTramo's and idCoeficiente's and are the same (and same Type: Integer).

Anyone have any clue?
Thanks a lot
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Raul!

JSTL does not work well with JSF. For one thing, JSTL is designed to work on JSPs, which compile into java Servlet classes (executable code), whereas the current generation JSF View Definition Language compiles into a data structure (component tree), not executable code. That's a consequence of the fact that JSF page definitions are the Views of JSF's Model/View/Controller implementation. In JSF, most executable code goes in the Model (Controllers are generally pre-supplied).

The equivalent to an iterative function on a View is a table or repeated UI sub-template. For a table, the JSF "h:dataTable" tag is the recommended way to present things. For sub-views that don't organize neatly into rows in a table, the Facelets "ui:repeat" tag can be used.
 
Raul Vila
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim, thank you for your time.

I had to say that I tried the ui:repeat (changing the render param to :masterform:viewElem).
I will try h:datatable and come back, thanks again!
 
Raul Vila
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried with ui:repeat and h:datable.

One more thing; your (great) explanation about JSTL could be the reason if the first code sample doesn't work... but it works (that's the illogical behavior).

Thanks again!!
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raul Vila wrote:I've tried with ui:repeat and h:datable.

One more thing; your (great) explanation about JSTL could be the reason if the first code sample doesn't work... but it works (that's the illogical behavior).

Thanks again!!


It works, but not well. Which is why we discourage it. There's really nothing in JSTL that JSF doesn't have a native JSF-aware equivalent for.
 
Raul Vila
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This are no good tests... (see below)

I am really close to ask for psychiatric help...

This is the code I have right now:




I have tried to use each one alone without the other (to be sure there aren't interfering between them).
And as you can see I put the action in a different Bean (of course I have tried in the same too).

The MANUAL case works! The others don't.


Thanks again!
 
Raul Vila
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This are no good tests... (see below)
New tests:

MANUAL-MANUAL: Works!
MANUAL-[0]: Works!
UI:REPEAT Bad Array: Works!
UI:REPEAT Good Array: FAIL!
UI:REPEAT Good Array - MANUAL(2): FAIL!


 
Raul Vila
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done a little advance!

It works if I read the list directly from database. Until now I had reading it by Lazy OneToMany relationship.

Can anyone explain me what is wrong with using a lazy-load one-to-many list in a ui:repeat?

THANKS A LOT!
 
Raul Vila
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One step forward one step back

Now I always read the data directly from database (I am not sure this is relevent) and there are my tests:
CASE 1: Works! (Of course, this is a non functional test)
CASE 2: FAIL!
CASE 3: FAIL! (In this case I read the id from the current element inside de Bean)

 
Raul Vila
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally I have decided to use @ViewScoped with AJAX calls.
Ir works great.

Only be carefull with the "execute" param in the tag <j:ajax>
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like your backing bean was request-scoped.

Request scope doesn't work well in JSF. A particular problem is that the dataModel object that backs JSF dataTable objects contains cursor tracking information in addition to the user data being modelled, and in Request scope, that data is destroyed and recreated from scratch on the page postback. "From scratch" means that the values were reset.

Originally, this could be overcome using Session scope (and it still can be). But Session scope is a little too durable for stuff that we only care about for the lifetime of one page, so ViewScope was added in JSF2.
 
Raul Vila
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but I don't know yet how to use ViewScoped without Ajax.
I have done some tests and I needed the <f:param> and the FacesContext(...)getRequestParameterMap to read parameters.

Some idea about how to use ViewScoped without Ajax?

Thanks (again and again)
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ViewScope works just fine on non-AJAX pages. All View Scope is is a special form of Session Scope where instead of being "forever", the View Scope backing bean(s) are deleted when you navigate to a different View (page).

Validation is an integral part of JSF. So when you display a page (View), the inputs are posted back and validated. If validation fails, the same View is redisplayed (usually with error messages). That continues until all validations pass and an action succeeds in navigating to a new page. When that happens, the ViewScope objects get deleted.

AJAX is just a variation of that where you only deal with part of the View instead of the whole thing.
 
Raul Vila
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry... I expressed myself poorly. When I said "non Ajax" I wanted to say "with different views": one for the List, one for the viewDetails, one for the Edit...

The problem when I tried this approach was that the ViewScoped Bean died and re-created when changing the view. Maybe I was doing something wrong...
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on what you mean by "View". In JSF terms, one displayed web page (usually corresponding to an xhtml file plus includes) is one View. Partial pages are sub-views. Updating sub-views shouldn't destroy the ViewScope object, nor should (full-page) updates to the current View. But if you leave that View and go to a different View, then the current View's ViewScoped objects all get destroyed, since that's the very definition of View Scope. If you need to hold data that's shared among multiple Views, put it in Session Scope. Or Application Scope if all app users will be sharing it (just remember to be thread-safe!).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!