Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
748 views
in Technique[技术] by (71.8m points)

jsf 2 - JSF 2 dataTable row index without dataModel

I've been using ui:repeat to generate tables. With ui:repeat it's easy to get the rows numbered using the varStatus. I'm depending on the row id's from varStatus when calling the backing bean to handle list navigation, for example moving an item up or down in the list.

Now I'd like to create a composite component that builds a customizable table with all functionality needed for marking rows, moving them up/down etc. To do this, the ui:repeat won't work as I can't see a way of handling different number of columns; I need to specify headings in one place and the body in another (and I've not reached the knowledge point where I can create a custom component). Therefore I went on to datatable instead, as using that means specifying the headers as facets at the same place as the body content.

That worked well until I noticed that for some reason there were no varStatus anymore. I have put a lot of work into handling list presentation without any need for a datamodel and I do not want to start using that. Is there any way that I can get the current row number as it is displayed in the table, without using datamodel?

Also I'm using viewScope and if I've understood correctly that means I cannot bind the dataTable to the bean.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just bind the table to the view itself instead of to a bean.

<h:dataTable binding="#{table}" ...>

Then you can use #{table.rowIndex} where necessary. E.g.

<h:column>#{table.rowIndex + 1}</h:column>

Note that the code is as-is and that the EL variable name table is fully to your choice.

See also:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...