GWT column sort handler ,how to get column's value which has been selected - gwt

I have a celltable in GWT and want to implement sorting functionality on it , from database(Criteria)
for that i just want to know how to get the value of the column which has been clicked for sorting
here is my code
ctJobs.addColumnSortHandler(new ColumnSortEvent.Handler() {
public void onColumnSort(ColumnSortEvent event) {
event.getColumn();
event.getColumn().getValue("what do we need to write here ???");
from event.getColumn() , i am getting column in the form of object
com.google.gwt.cell.client.ClickableTextCell#188a12e
I want to know the the column's name / value
for that i am trying event.getcolumn().getvalue("??");
but what is the parameter for that, or is there any other way of getting column's name which has been clicked.
Thanks

Are you using a ListDataProvider or an AsyncDataProvider for your cell table?
In case of an AsyncDataProvider the sorting must be done on the server side, so there is no need to add a ColumnSortHandler.
Please see the GWT docs.
To get the name of the column clicked for sorting see this question.

When creating the table columns, set the dataStoreName of the column.
column.setDataStoreName("columnX");
Next, when in the AsyncDataProvider get the sort history of the clicked headers like the following
final AsyncDataProvider<SQLRow> dataProvider = new AsyncDataProvider<SQLRow>(){
#Override
protected void onRangeChanged(HasData<SQLRow> display) {
for (int i=0;i<sortList.size();i++) {
sortList.get(i).getColumn().getDataStoreName();
}
}
}

Related

How to read revised data from a TextInputCell in a CellTable in GWT?

Each row in the CellTable is a TextInputCell. And I use a ListDataProvider to populate the table at the beginning. However, after I did some changes on the data in the TextInputCell. I tried to read the revised data using the data provider. However, the data in the data provider remains unchanged.
What's the problem here? And how to read the revised data out of the CellTable?
You need to add a FieldUpdater to your cell:
myColumn.setFieldUpdater(new FieldUpdater<MyObject, String>() {
#Override
public void update(int index, MyObject myObject, String value) {
myObject.setSomeValue(value);
}
});
The same approach applies to all types of cells.

Is it possible to refresh stale elements?

I have a search page that contains a table that gets populated with search results after the user presses the search button. The page object wraps the rows of the search results table in a custom HtmlElement class.
I'm getting a stale element exception when accessing the results table - as you'd expect because it was just refreshed by an ajax request.
I've worked around it by returning a new instance of the page object after performing the search but I'd rather just recreate the search results field. Is there any way to do this?
Example:
#FindBy(css = "[data-viewid='Table1'] .dojoxGridRow")
List<ActivityPerformanceRow> results;
// ...
public void search() {
search.click()
waitForAjaxToComplete();
// If it was a standard WebElement list I'd do something like this:
results = driver.findElements(By.cssSelector(
"[data-viewid='Table1'] .dojoxGridRow"));
}
After a bit of playing around I came up with this solution - it works well but doesn't deal with HtmlElement name property. Given I don't use it that I'm aware of I'm ignoring it for now...
public <T extends HtmlElement> List<T> findElements(Class<T> elementClass, By by) {
List<T> elements = new LinkedList<T>();
for (WebElement element : driver.findElements(by)) {
elements.add(HtmlElementLoader.createHtmlElement(elementClass, element, null));
}
return elements;
}

How to get the column name in nattable?

I had create an example like Editor Example, while the difference is that my demo can hide column. While when I hidden some column, I can not the collect selected column index, I changed my mind, I want to get the selected column's header name. How to get it?
Following is the handler to handle the selected column
But I don't know how to get the column name
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof CellSelectionEvent) {
CellSelectionEvent cellEvent = (CellSelectionEvent) event;
int columnIndex = natTable.getColumnIndexByPosition(cellEvent.getColumnPosition());
SelectionLayer selectionLayer = cellEvent.getSelectionLayer();
........
}
You need the reference to the ColumnHeaderLayer and get the data value. E.g. ColumnHeaderLayer#getDataValueByPosition(int, int)

Form fields are reset on validation error

I have a rather complex form in the way that the number of form fields is flexibel. In short, the model object is a TLabel (TranslationLabel) that contains a Map of values (translations). Language here is an enum so the idea is that the number of fields (text areas) for which a translation is given depends on the values in this enum.
This is my form (simplified):
public class TranslationEditForm extends Form {
private final static List<Language> LANGUAGES = newArrayList(Language.values());
public TranslationEditForm(String id, final TranslationLabelView label) {
super(id, new CompoundPropertyModel<TranslationLabelView>(label));
ListView<Language> textAreas = new ListView<Language>("translationRepeater", LANGUAGES) {
#Override
protected void populateItem(final ListItem<Language> itemLang) {
//loop through the languages and create 1 textarea per language
itemLang.add(new Label("language", itemLang.getModelObject().toString()));
Model<String> textModel = new Model<String>() {
#Override
public String getObject() {
//return the value for current language
return label.getValue(itemLang.getModelObject());
}
#Override
public void setObject(String object) {
//set the value for current language
label.getTranslations().put(itemLang.getModelObject(), object);
}
};
itemLang.add(new TextArea<String>("value", textModel).setRequired(true));
}
};
//add the repeater containing a textarea per language to the form
this.add(textAreas);
}
}
Now, it works fine, 1 text area is created per language and its value is also set nicely; even more when changed the model gets updated as intended.
If you submit the form after emptying a text area (so originally there was a value) then of course there is a validation error (required). Normal (wicket) behaviour would be that the invalid field is still empty but for some reason the original value is reset and I don't understand why.
If I override onError like this:
#Override
protected void onError() {
this.updateFormComponentModels();
}
then it is fine, the value of the field is set to the submitted value (empty) instead of the original value.
Any idea what is causing this? What is wicket failing to do because the way I've set up the form (because with a simple form/model this is working fine as are the wicket examples)?
Posted as answer, so the question can be marked as solved:
ListView does recreate all its items at render time. This means that the validation will be broken. Have a look at API doc of the ListView
Calling setReuseItems() on the ListView solves this.
Regards,
Bert

Is there any way to retrieve a RichFaces TreeNodeImpl from a NodeSelectedEvent?

I extended the RichFaces TreeNodeImpl to store another piece of data that I would need when that row was selected. When I select a node in my rich tree, I execute code in my NodeSelectListener. In my listener, I want to look at the TreeNodeImpl from which the tree was built, but I don't know how to get the TreeNodeImpl from the NodeSelectedEvent parameter.
Is there any way to get the TreeNodeImpl object from the NodeSelectedEvent?
Thanks in advance.
Shane
You can get that in select listener like this:
public void processSelection(final NodeSelectedEvent event) {
final UITree tree = (UITree) event.getComponent();
TreeNodeImpl rowData = (TreeNodeImpl) tree.getRowData();
}