Serenity grid not translating lookupeditor - serenity-platform

I am new to serenety and followed the serenity guide to create a lookupeditor on a field. This works fine in the form editor but not in the grid. The grid does not translate the numerica value to text. Here is my code:
[FuncionariosRow]
[DisplayName("Cargo"), ForeignKey("[Ipss].FuncionariosCargos", "Codigo"), LeftJoin("f")]
[LookupEditor(typeof(FuncionariosCargosRow), InplaceAdd = true)]
public Int32? Cargo
{
get { return Fields.Cargo[this]; }
set { Fields.Cargo[this] = value; }
}
[FuncionariosCargosRow]
...
[JsonConverter(typeof(JsonRowConverter))]
[LookupScript("IpssDB.FuncionariosCargos")]
public sealed class FuncionariosCargosRow : Row, IIdRow, INameRow
{
...
}

In the form, you have int field with lookup editor which shows lookup text values and send int values behind. When you add lookupeditor on row field, its act as default editor type for forms. you can override it from XyzForm.cs
In the grid you dont have an editor type. so you see int values directly. If int value has join, you can use joined text field instead id.

Related

How to write an APEX #test for a picklist method?

I was searching for answears but I couldn't find it. It might be a beginner question, anyhow I am stuck.
What I am trying to write is a test in Apex. Basically the Apex code gets field names from one specific object. Each fieldname will be shown in a picklist, one after the other (that part is a LWC JS and HTML file).
So, only want to test the Apex for the moment.
I don't know how to check that a list contains 2 parameters, and those parameters are object and field. Then the values are correctly returned, and I don't know how to continue.
Here's the Apex class with the method, which I want to test.
public without sharing class LeadController {
public static List <String> getMultiPicklistValues(String objectType, String selectedField) {
List<String> plValues = new List<String>();
Schema.SObjectType convertToObj = Schema.getGlobalDescribe().get(objectType);
Schema.DescribeSObjectResult objDescribe = convertToObj.getDescribe();
Schema.DescribeFieldResult objFieldInfo = objDescribe.fields.getMap().get(selectedField).getDescribe();
List<Schema.PicklistEntry> picklistvalues = objFieldInfo.getPicklistValues();
for(Schema.PicklistEntry plv: picklistvalues) {
plValues.add(plv.getValue());
}
plValues.sort();
return plValues;
}
}
I welcome any answers.
Thank you!
This might be a decent start, just change the class name back to yours.
#isTest
public class Stack73155432Test {
#isTest
public static void testHappyFlow(){
List<String> picklistValues = Stack73155432.getMultiPicklistValues('Lead', 'LeadSource');
// these are just examples
System.assert(!picklistValues.isEmpty(), 'Should return something');
System.assert(picklistValues.size() > 5, 'At least 5 values? I dunno, whatever is right for your org');
System.assert(picklistValues[0] < picklistValues[1], 'Should be sorted alphabetically');
System.assert(picklistValues.contains('Web'), 'Or whatever values you have in the org');
}
#isTest
public static void testErrorFlow(){
// this is actually not too useful. You might want to catch this in your main code and throw AuraHandledExceptions?
try{
Stack73155432.getMultiPicklistValues('Account', 'AsdfNoSuchField');
System.assert(false, 'This should have thrown');
} catch(NullPointerException npe){
System.assert(npe.getMessage().startsWith('Attempt to de-reference a null object'), npe.getMessage());
}
}
}

How to create a simple HTML table in Vaadin Flow 14

I would like to create a simple HTML table in Vaadin flow, but the component is not present anymore (used to be available as com.vaadin.ui.Table). The table is meant to show the detailed properties (key-value pairs) of an item selected in a Grid.
What Vaadin Flow component can I use to implement this? And why was the table removed in Vaadin Flow in the first place?
Table was actually removed already in Vaadin8. https://vaadin.com/blog/-/blogs/mission-rip-table-migrate-to-grid-intro
For implementing a table in Flow there are a couple choices.
One is to use the Element API and one is to create Components for table.
For the element API version it could be something like:
Element table = new Element("table");
For(item : item rows to add) {
Element tr = new Element("tr");
table.appendChild(tr);
For(int i = 0; i < dataColumns; i++) {
Element td = new Element("td");
// could perhaps append a span with text context.
td.setText(item text for column i);
tr.appendChild(td);
}
}
For the Component approach the basic case would then perhaps be to implement the 3 elements as something like:
#Tag("table")
public class Table extends Component implements HasComponents {
public Row addRow() {
Row row = new Row();
add(row);
return row;
}
public Row getRow(int row) {
final Optional<Component> rowOptional = getElement().getChild(row)
.getComponent();
if(rowOptional.isPresent())
return (Row) rowOptional.get();
return null;
}
}
#Tag("tr")
public class Row extends Component {
public void add(Cell cell) {
getElement().appendChild(cell.getElement());
}
public int getRow() {
return getElement().getParent().indexOfChild(getElement());
}
}
#Tag("td")
public class Cell extends Component {
public int getCol() {
return getElement().getParent().indexOfChild(getElement());
}
public int getRow() {
return ((Row) getParent().get()).getRow();
}
public void setText(String text) {
getElement().setText(text);
}
}
There can be multiple use cases for Table component. There are couple of alternative's in Vaadin's Directory of community components.
Table showing list of data (similar to Grid, but more light weight approach)
https://vaadin.com/directory/component/beantable
Table as layout component, which supports row-span, col-span etc. and you populate each cell individually.
https://vaadin.com/directory/component/html-table
As these usecases are quite different , they are better catered by different Java API, although the HTML DOM structure they produce is very similar. Neither of these add-ons attempt to reproduce API of the Vaadin 7 Table component.
There is also a recipe in Cookbook, how to generate Table in TemplateRenderer of the Grid details row.
https://cookbook.vaadin.com/grid-details-table

can't find all field of a pdf (acroform)

Considering this pdf
With this code I except retrieve all field but I get half of them:
pdfOriginal.getDocumentCatalog().getAcroForm().getFields().forEach(field -> {
System.out.println(field.getValueAsString());
});
What is wrong here ? It seems all annotations are not in aocroform reference, what is the correct way to add form field annotation into acroform object?
Update 1
The wierd thing here if I tried to set field's value which is not referenced/found in getAcroForm.getFields() like this :
doc.getDocumentCatalog().getAcroForm().getField("fieldNotInGetFields").setValue("a");
This works
Update 2
It seems using doc.getDocumentCatalog().getAcroForm().getFieldTree() retrieve all fields. I don't understand why doc.getDocumentCatalog().getAcroForm().getFields() not ?
What is the correct way retrieve all fields of a pdf acroform.getFieldTree() or acroform.getFields() (I need retrieve them to set them partialValue)
From the java doc on method public List<PDField> getFields() we can read:
A field might have children that are fields (non-terminal field) or does not have children which are fields (terminal fields).
In my case some fields contain non-terminal field so to print them all we need check if we are in a PDNonTerminalField like :
document.getDocumentCatalog().getAcroForm().getFields().forEach(f -> {
listFields(f);
});
// loop over PDNonTerminalField otherwise print field value
public static void listFields(PDField f){
if(f instanceof PDNonTerminalField) {
((PDNonTerminalField) f).getChildren().forEach(ntf-> {
listFields(ntf);
});
}else {
System.out.println(f.getValueAsString());
}
}

Javafx: updating cell using choicebox in the GUI doesn't work

I have a problem in a Tableview created using javafx. I have set the edititable="true" on the fxml file of the tabel, then in the controller I execute
#FXML
private TableColumn<ARule,Object> rankCol;
rankCol.setCellValueFactory(new PropertyValueFactory<ARule, Object>("label")); rankCol.setCellFactory(ChoiceBoxTableCell.forTableColumn(Main.getlabelSample()));
rankCol.setOnEditCommit(e -> {System.out.println("something happens!");});
To create in the column rank, a choicebox to change te value of the property.
The ARule has a property field and the getter and setters:
private SimpleObjectProperty label;
public SimpleObjectProperty labelProperty() {
return label;
}
public void setLabel(Object label) {
this.label.set(label);
}
public Object getLabel(){
return this.label.getValue();
}
The function Main.getlabelSample() retrun this object filled with Strings or Integer
private static final ObservableList<Object> labelSample = FXCollections.observableArrayList();
The problem is that in the interface I can edit the column and it displays the correct value in the labelSample list, the problem is that it doesn't change the value of the ARule object, this is highlighted by the missing call of the setOnEditCommit handler. The value on the GUI is the new one selected but the value saved on the items in the table is the old one.
I have also a separated button to change the value of that column on the selected row and if I trigger that, the values changes for "real" (both on the GUI and on the model).
What could be the error in the code?
The default edit commit behavior of the column is set as the onEditCommit property. If you call
rankCol.setOnEditCommit(...);
then you set this property to something else, i.e. you remove the default behavior.
If you want to add additional behavior to the default, use addEventHandler(...) instead of setOnEditCommit(...):
rankCol.addEventHandler(TableColumn.editCommitEvent(), e -> {
System.out.println("Something happens");
});
Find the answer the line of code:
rankCol.setOnEditCommit(e -> {System.out.println("something happens!");});
for some reason overwrite the default behaviour of updating the cell changing the code into
rankCol.setOnEditCommit(e -> {
e.getTableView().getItems().get(e.getTablePosition().getRow()).setLabel(e.getNewValue());
System.out.println("Something happens!");});
Resolved the problem. At the moment I don't know why this is happening.

GXT TextField or TextArea not decode html entites

i use grid cell renderer... and form bindig...
grid cell renderer valus is good
form bindig value is bad (
i tested: ff9 and last chrome
this bug ? or browser error ? or something else ?
sorry i little speak english.... (i use gtranslate)
error picture => http://test.eggproject.hu/gxt/textfieldentitesbugg.PNG
about json(gxt model)
{"ID":1,"user_email":"xxxx#xxxx.com","display_name":"XXX YYYY","user_cegnev":"","user_jogosultsag":"administrator","user_kedvezmeny":0,"user_city":0,"user_irsz":-1,"user_district":3,"user_street":241,"user_hazszam":"2813","user_emelet":"10","user_ajto":"588","user_kapucsengo":"58","user_comment":"óüöú\u0151\u0171áí","first_name":"Harangozo","last_name":"Gabor","user_telephone":"06111111","user_street2":""}
user_comment error displaying just textarea or textfield why ?
This is due to the components each section is using. A grid is essentially a tag which means any HTML encoded data loaded into this table is rendered correctly. Conversely A TextBox is a tag which only displays exactly what can be seen.
A solution is a custom field binding which processes the data in and out.
public class HTMLParserBinding extends FieldBinding {
protected Field<?> field;`
public HTMLParserBinding( Field<?> field, String property ) {
super(field, property);
this.field = field;
}
protected Object onConvertFieldValue( Object value ) {
if (value == null) {
return null;
}
return Format.htmlDecode(value.toString());
}
protected Object onConvertModelValue( Object value ) {
if( value == null ) {
return null;
}
return Format.htmlEncode(value.toString());
}
}