When building a celltable using a TableBuilder, I encounter a problem to set a unique class name to sub rows. (gwt 2.5RC)
the code that builds the rows looks something like this:
#Override
public void buildRowImpl(AdGroupProxy mainAdGroup, int absRowIndex) {
super.buildRowImpl(mainAdGroup, absRowIndex);
for (AdGroupProxy adGroup : mainAdGroup.getChildren()) {
super.buildRowImpl(adGroup, ++absRowIndex);
}
}
Every <tr> been generated inside the loop is a subrow.
The <tr>'s are generated with the attribute __gwt_subrow=1,__gwt_subrow=2 ...
however, due to the issue of GWT isn't supporting CSS3 I cannot use the following selector to select the sub rows:
.dataGridOddRow:not([__gwt_subrow="0"])
I don't want neither to implement the method buildRowImpl myself.
Any suggestions of how to set a class name to sub rows only?
Related
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;
}
in my current project I have to render items in a CellTable received via a RPC call. The columns must be created dynamically and the column types are unknown at compile time.
From the server side, I send a list of the following class to define a row in the table:
public class TableRowDTO implements IsSerializable {
private List<IsTableItemDTO> tableItemDTOs;
public TableRowDTO() {
tableItemDTOs = new ArrayList<IsTableItemDTO>();
}
// getters & setters ...
}
Where each row will contain an item implementing IsTableItemDTO which is a marker interface:
public interface IsTableItemDTO extends IsSerializable {}
Implementing classes depict the actual controls/information to be shown in cells like:
public class TableDateTimeDTO extends IsTableItemDTO {
private Date valueDate;
// ... other fields not necessary for the table
}
Or also:
public class TableCheckBoxDTO extends AbstractTableItemDTO {
private boolean checked;
// ... other fields not necessary for the table
}
And also:
TablePasswordDTO extends AbstractTableItemDTO {
private String valueText;
// ... other fields not necessary for the table
}
Therefore, what I want to do for example in the case I receive a List with {TableCheckBoxDTO, TableDateTimeDTO, TablePasswordDTO} is to render a CellTable with the corresponding widgets.
I've seen this and this, but I don't see how to apply any of the examples to my case especially because I cannot use thigs like Column as I don't have my ContactInfo before hand.
Thanks
You can use the marker interface IsTableItemDTO together with instanceof() and dynamic casts to have a generic Column/Cell.
There are 2 ways:
Create a Composite Cell and add all possible cell types and then display based on what specific sub-type your isTableItemDTO is.
Create a custom cell and render the input (checkbox, text) based on the specific type of your marker interface
I used Jet table (https://code.google.com/p/gwt-jet/) in one of my earlier projects. I believe it has the features you are looking for.
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
I'm a newcomer to java and the play framework (I'm using play 1.2.2 with a local MySQL5 database). I'm trying to query a couple of tables in a database and display the table join results on a web page.
This is what I have in the various bits:
Controller :-
public static void index() {
List<Mutation> mutation_list= Mutation.getDisorderGene();
render(mutation_list);
}
Model :-
public class Mutation extends Model {
public static List<Mutation> getDisorderGene() {
EntityManager entityManager = play.db.jpa.JPA.em();
List<Mutation> muts = entityManager.createNativeQuery("select disorder_name, gene_name from Disorder,Mutation where Disorder.id = Mutation.disorder_id order by disorder_name, gene_name").getResultList();
return muts;
}
View :-
#{list items:mutation_list, as:'mutation'}
<tr>
<td>${mutation.disorder_name}</td>
<td>${mutation.gene_name}</td>
</tr>
#{/list}
And this is the error message I get!
Template execution error
Execution error occured in template /app/views/Stu/index.html.
Exception raised was MissingPropertyException : Exception evaluating
property 'disorder_name' for java.util.Arrays$ArrayList, Reason:
groovy.lang.MissingPropertyException: No such property: disorder_name
for class: java.lang.String.
I'm unsure where the problem lies. Is it with the JPA table join query or is something wrong in the view.
Are there any changes in the view I can make to display the columns?
Many thanks.
A native query that selects multiple columns by default returns them as Object[], thus your getDisorderGene() should return a List<Object[]>, and your template should look as follows:
#{list items:mutation_list, as:'mutation'}
<tr>
<td>${mutation[0]}</td>
<td>${mutation[1]}</td>
</tr>
#{/list}
What if you put the as clausule...
select disorder_name as NameMyPropertyModelClass, gene_name as NameMyPropertyModelClass
from Disorder,Mutation
where Disorder.id = Mutation.disorder_id order by disorder_name, gene_name
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();
}
}
}