简体   繁体   中英

How do I enable choosing a row of a h:dataTable using JSF 2.0?

I'm starting a small project, using JSF 2.0. I'm having problems right in the start, in the CRUD of the first model implemented.

What I want to do is pretty simple:

The page has some filters to search, and using ajax, it populates ah:dataTable with the results. The user should now select the line with the result he wants to see/edit. But I just can't find a way to make the line selectable.

This is my table:

<h:dataTable var="aluno" value="#{alunoController.resultado}" >
  <h:column>
     #{aluno.id}
  </h:column>
  <h:column>
     #{aluno.nome}
  </h:column>
  <h:column>
     <!-- radiobutton, commandLink/Action goes gere -->
  </h:column>
</h:dataTable>

First I tried having a radiobutton on each line, then I learned that I cant have a radiogroup inside a table.

Then I tried having a radio group inside the first cell of each line, and handling selecion with a little bit of javascript. Somehow, the databinding doesn't work, and I cant get the selected model back in my ManagedBean.

So I tried having a commandButton/Link, which sends the model via parameter.... not. It just refresh the page.

The I tried using query parameters, sending the id of that row and getting the model from de database again, but I cant find a way to tell wich method should be called in the ManagedBean.

So I came here for my very first time, looking for suggestions. What should I do? Am I missing some information?

Tell me if you need more information.

I just don't want to believe what I want to do is too advanced.

Sorry for the bad english.

I would recommend to you to use PrimeFaces components.

Allowing you to choose single rows. See Show Case

The JSF 2.0 way is to put managed bean in view scope. You can do that using @ViewScoped .

@ManagedBean
@ViewScoped
public class Bean {}

This way the bean will be preserved for the subsequent request and retained when the target view of the subsequent request is the same.

See also:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM