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 rowIndex Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "rowIndex" Watch "rowIndex" New topic
Author

rowIndex

Andrei Prodan
Greenhorn

Joined: Jul 07, 2012
Posts: 12
hello.. i'm trying to get in a scriplet the row index for each row in a datatable

with jsf tag works like a charm

but when i write like this

it will print only -1 for each row... what i'm doing wrong?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

What are you doing wrong? You're using scriptlets.

Scriptlets are not encouraged even on traditional JSPs. JSF, however, is a pretty pure implementation of Model/View/Controller, and the page definition should not attempt to behave like it is executable code - it is a template. Executable code belongs in the backing bean.


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

Joined: Jul 07, 2012
Posts: 12
Tim Holloway wrote:What are you doing wrong? You're using scriptlets.

Scriptlets are not encouraged even on traditional JSPs. JSF, however, is a pretty pure implementation of Model/View/Controller, and the page definition should not attempt to behave like it is executable code - it is a template. Executable code belongs in the backing bean.


ok.. so you can understand what i want to do: i'm making a forum, and each post should have an anchor point, so when the link will be "...index.jsp#5", the scroll will move to post number 5..
i have tried this line
but it sais "according to the tdl, the attribute id is not deferred value or deferred method, but the specify value contains a # expression"; any suggestions how should i do?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

Unless that's a legacy JSP you're linking to, you're trying to force-fit a non-JSF solution to JSF.

Label links are not common in JSF, partly because JSF URLs are not processed in the same way that traditional URLs are. While I'm pretty sure that there are ways using the JSF tags to generate a name anchor tag, I can't remember how, so I'll do it the hard way:


I had to code the "a" tag as "xa" because our message editor kept playing games with it. Substitute "a" for the real-world case.

Note that rowIndex is relative to 0. Also, this may not work reliably if you define rowModel as an array or collection. The rowIndex is a property of the JSF DataModel class, and while in theory, a bare collection/array will be automatically wrapped in an anonymous DataModel, I haven't actually seen formal documentation that guarantees it.
Andrei Prodan
Greenhorn

Joined: Jul 07, 2012
Posts: 12
so in your code, when i'll go to the link (for example) index.jsp#5, the scroll will go to that component "a" with the name=5 (to the 5th post)? because this is what i need in fact

anyway something is wrong, cause i get the error "#{...} not allowed in a template text body"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: rowIndex