dcsimg
About the use of Netbeans 5.5.1 Visual Web with the component ui:table, I want to get back the object choosed by user on UI...
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   leandro_moreira
Posted On:   Wednesday, September 26, 2007 11:48 AM

Well I'll try explain all... My enviroment IDE version: 5.5.1 kind of project: Visual Web I created one POJO called User (+Long id,+String name,+String user,+String pwd), and after I created one Page1.java in this page I add some controls from basic pallete: 1 - button (query) 2 - button (select) 3 - table 4 - staticText (staLabel) So I put one ObjectListDataProvider (and get,set) on page. private ObjectListDataProvider objectListDataProvider = new ObjectListDataProvider(); public ObjectListDataProvider getObjectListDataProvider() { return objectListDataProvider; } public void setObjectListDataProvider(ObjectListDataProvider objec   More>>
			Well I'll try explain all...
			

My enviroment
IDE version: 5.5.1
kind of project: Visual Web


I created one POJO called User (+Long id,+String name,+String user,+String pwd), and after I created one Page1.java in this page I add some controls from basic pallete:
1 - button (query)
2 - button (select)
3 - table
4 - staticText (staLabel)

So I put one ObjectListDataProvider (and get,set) on page.

private ObjectListDataProvider objectListDataProvider = new ObjectListDataProvider();
public ObjectListDataProvider getObjectListDataProvider() {
return objectListDataProvider;
}
public void setObjectListDataProvider(ObjectListDataProvider objectListDataProvider) {
this.objectListDataProvider = objectListDataProvider;
}

In this same moment I add an object List list = new ArrayList (); to page too.
Well on design view I click on table component and left-button of mouse and choose Table Layout:
So I change the way to get Data: (first combo box) I choose objectListDataProvider.
Add four colluns
1 - none text on header or Expression Value (EL) and choose the component radio button
2 - Header Text: Name, static Text, EL #{currentRow.value['id']}
3 - Header Text: Name, static Text, EL #{currentRow.value['name']}
4 - Header Text: Name, static Text, EL #{currentRow.value['user']}

On Button query I put the follow code:

public String button1_action() {

//the constructor acept id, user, password
list.add(new User(1l,"paul99","12345678910"));
list.add(new User(2l,"johnfrusciante","12345678910"));
list.add(new User(3l,"jkill9","12345678910"));
objectListDataProvider.setList(lista);

return null;
}

Well I start the application (F6) so I clicked on button query and the table realy is showed...

but I can choose more than one radio button... And I search on Internet (netbeans Wiki) and found

a good article
http://blogs.sun.com/winston/entry/single_selectable_row_table_component
And I add (just it) to page1 this code below

private TableSelectPhaseListener tablePhaseListener = new TableSelectPhaseListener();

public void setSelected(Object object) {
RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
if (rowKey != null) {
tablePhaseListener.setSelected(rowKey, object);
}
}

public Object getSelected(){
RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
return tablePhaseListener.getSelected(rowKey);

}

public Object getSelectedValue() {
RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
return (rowKey != null) ? rowKey.getRowId() : null;

}

public boolean getSelectedState() {
RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
return tablePhaseListener.isSelected(rowKey);
}

Now I can choose just one radio button... all right, but I still want to know how get back the

object that the User choose...
So searching I found this another document:
http://wiki.netbeans.org/wiki/view/VwpFAQdetectradiobutton
Reading I think is just it (code to button Select)

public String edit(){
RowKey rowkey = tableRowGroup.getRowKey();
User user = (User) dataProvider.getValue(rowKey);
//I created one atribute on sessionbean
getSessionBean1().setUser(user);
}

But still does not work.

Debugging the the part of select (the only that don't works) I have noted that rowkey is null...
So what I need to do to know what object was selected by user?

If forget something or you don't understand my problem I can tell in another way...

Some intersting things: ever time I submit my page (click on button on same page that return

null) my table is clear (dont keep the state like the anothers jsf component)...

Thanks so much and sorry for my poor english
   <<Less
About | Sitemap | Contact