• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Selected Row in primefaces

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 13
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




This is my bean method and the corresponding command link within the data table
 
yun hu
Greenhorn
Posts: 13
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But how will you get the selected row in Primefaces 2.1 data table?
 
yun hu
Greenhorn
Posts: 13
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic