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 Selected Row in primefaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Selected Row in primefaces" Watch "Selected Row in primefaces" New topic
Author

Selected Row in primefaces

Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
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

Joined: Feb 18, 2010
Posts: 13

<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

Joined: Dec 02, 2000
Posts: 362
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

Joined: Feb 18, 2010
Posts: 13

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

Joined: Dec 02, 2000
Posts: 362
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

Joined: Feb 18, 2010
Posts: 13

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

Joined: Dec 02, 2000
Posts: 362




This is my bean method and the corresponding command link within the data table
yun hu
Greenhorn

Joined: Feb 18, 2010
Posts: 13

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

Joined: Dec 02, 2000
Posts: 362
But how will you get the selected row in Primefaces 2.1 data table?
yun hu
Greenhorn

Joined: Feb 18, 2010
Posts: 13

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
 
 
subject: Selected Row in primefaces