Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Selected Row in primefaces

 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a primefaces datatable and when I click on a row, I need to display the value of one of the field in a text box. How do I do this? All the examples in the showcase displays a widget , but I want to display the value in a text box

Thanks in advance
 
yun hu
Greenhorn
Posts: 13
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<p:dataTable var="mu" value="#{musicBean.defaultDataModel}" paginator="true" rows="20"
rowSelectListener="#{musicBean.onRowSelect}" lazy="true" id="musicInfo" selectionMode="single"
onRowSelectComplete="dlgMusic.show()" onRowSelectUpdate="display">
......

<p:dialog header="Music" widgetVar="dlgMusic" width="500" height="300" modal="true">
<h:panelGrid cellpadding="5" width="100%" id="display">
<h:inputText id="category" value="#{musicBean.music.categoryNames}" />
</h:panelGrid>
</p:dialog>

When row selected, display diaglog 'dlgMusic'. I hope this is helpul for you.
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yun,
Thanks for your reply. I don't want to display a dialog box, but populate the text field with one of the values in the selected row. Can this be done?
 
yun hu
Greenhorn
Posts: 13
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do that.

<p:dataTable var="mu" value="#{musicBean.defaultDataModel}" paginator="true" rows="20"
rowSelectListener="#{musicBean.onRowSelect}" lazy="true" id="musicInfo" selectionMode="single" onRowSelectUpdate="your field">
......

<h:inputText id="your field" value="#{musicBean.music.musicName}" />

in ManagedBean :
public void onRowSelect(SelectEvent event){
music = (Music)event.getObject();
}


 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your input, but I don't see the attribute onRowSelectUpdate in Primefaces 2.1 datatable. Is there any alternate way to do this in 2.1 other than upgrading it to 2.2?

I have another question. I have a datatable with the delete commandlink in the first column. When I click on the delete icon, the data table has to refresh with the current values. The problem i am having is that the list from the bean contains the updated values, but the datatable is not refreshed. Any suggestions you have?
 
yun hu
Greenhorn
Posts: 13
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using primefaces-2.2.RC2.

About the problem for dataTable, can you show me the code for your delete ActionListener.
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




This is my bean method and the corresponding command link within the data table
 
yun hu
Greenhorn
Posts: 13
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have different way for delete from dataTable. Your way i didnt try. Can you get correct 'id' from param.

My way is one table only one delete button. When they select one row then get the row object and then click delete button.

public void deleteAction(ActionEvent event) {
if (music == null)
return;

service.delete(music);
musicList.remove(music);
}
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But how will you get the selected row in Primefaces 2.1 data table?
 
yun hu
Greenhorn
Posts: 13
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, i didnt test in primefaces 2.1, i cant tell you how.

But before i did like this

public String deleteAction() throws Exception {
employee = (Employee) dataModel.getRowData();
baseService.deleteEmpl(employee);
return "/pages/common/base/emplList.xhtml";
}

I dont suggest you to do
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic