SmartGwt ListGrid.setAlwaysShowEditors(true) issue - java

We have basic ListGrid where one of the fields is editable and editor for this field always should be displayed, here is creation code
ListGrid listPanel = new ListGrid();
listPanel.setDataFetchMode(FetchMode.PAGED);
listPanel.setDataSource(datasource);
listPanel.setAutoFetchData(true);
listPanel.setAlwaysShowEditors(true);
listPanel.setCanEdit(true);
listPanel.setAutoSaveEdits(false);
listPanel.setSaveByCell(false);
listPanel.setEditOnFocus(true);
listPanel.setEditEvent(ListGridEditEvent.CLICK);
editable field is created here
ListGridField manualScoreColumn = new ListGridField("score", "Score");
manualScoreColumn.setType(ListGridFieldType.INTEGER);
manualScoreColumn.setCanEdit(true);
manualScoreColumn.setValidateOnChange(true);
manualScoreColumn.setValidators(new IntegerRangeValidator());
problem is when data in ListGrid is filtred using
listPanel.setCriteria(criteria);
we get such exeption
12:42:31.204:RDQ2:WARN:Log:TypeError: _5 is null
ListGrid._clearingInactiveEditorHTML() # adminApp/sc/modules/ISC_Grids.js:1530
GridBody.redraw(_1=>false) # adminApp/sc/modules/ISC_Grids.js:889
[c]Canvas.clearRedrawQueue() # adminApp/sc/modules/ISC_Core.js:3300
[c]Class.fireCallback(_1=>{Obj}, _2=>undef, _3=>[object Array], _4=>{Obj}, _5=>true)
# adminApp/sc/modules/ISC_Core.js:299
Timer._fireTimeout("$ir2251") # adminApp/sc/modules/ISC_Core.js:1269
unnamed() # adminApp/sc/modules/ISC_Core.js:1264
unnamed() #
I've found similar question here and here but no solution was proposed.
Are there any workarounds ? Thanks.

Make sure you have set ListGridField to ListGrid
listPanel.setFields(manualScoreColumn);
Another way to set editor of your choice to ListGridField is to use setEditorType method
ListGrid listPanel = new ListGrid();
listPanel.setCanEdit(true);
listPanel.setAutoSaveEdits(false);
//You can use any formitem instead of date item,Say TextItem,SelectItem etc
DateItem dateItem = new DateItem();
ListGridField dateListGridField= new ListGridField("date", "Date");
dateListGridField.setEditorType(dateItem);
listPanel.setFields(dateListGridField);

Related

Error while trying to sort grid component in vaadin flow

I am getting this error when I try to sort the grid programmatically:
grid.sort(List.of(
new GridSortOrder<>(grid.getColumnByKey("Νο"), SortDirection.ASCENDING),
new GridSortOrder<>(grid.getColumnByKey("επίθετο"), SortDirection.ASCENDING)
));
The error:
Cannot invoke "com.vaadin.flow.component.grid.Grid$Column.getInternalId()" because the return value of "com.vaadin.flow.component.grid.GridSortOrder.getSorted()" is null
Is it because I use Greek characters in Grid columns? Do you know any solution or workaround?
In order to call grid.getColumnByKey() you need to set the key for each column. This works okay:
final String COL1 = "Νο";
final String COL2 = "επίθετο";
Grid<SomeBean> grid = new Grid<>();
grid.addColumn(SomeBean::getId).setHeader("Column 1").setKey(COL1);
grid.addColumn(SomeBean::getName).setHeader("Column 2").setKey(COL2);
grid.sort(List.of(
new GridSortOrder<>(grid.getColumnByKey(COL1), SortDirection.ASCENDING),
new GridSortOrder<>(grid.getColumnByKey(COL2), SortDirection.ASCENDING)
));

SlectedItem dropdown not showing values

I am working on smartGwt project i have developed simple slectedItem dropdown. This dropdown does not showing any vaules for slection this is multiple selction dropdown. below is my code
final Window winModal = new Window();
winModal.setWidth(700);
winModal.setHeight(400);
winModal.setAutoSize(true);
winModal.setTitle("Schedule");
winModal.setShowMinimizeButton(false);
winModal.setIsModal(true);
winModal.setShowModalMask(true);
winModal.centerInPage();
DynamicForm form = new DynamicForm();
form.setHeight100();
form.setWidth100();
form.setPadding(5);
form.setLayoutAlign(VerticalAlignment.BOTTOM);
SelectItem selectItemMultiplePickList = new SelectItem();
selectItemMultiplePickList.setTitle("Select Multiple");
selectItemMultiplePickList.setMultiple(true);
selectItemMultiplePickList.setMultipleAppearance(MultipleAppearance.PICKLIST);
selectItemMultiplePickList.setValueMap("Cat", "Dog", "Giraffe", "Goat", "Marmoset", "Mouse");
form.setFields(selectItemMultiplePickList);
winModal.addItem(form);
winModal.show();
my dropdown widget is showing but not showing any values inside dropdown
anyhelp
Thanks in advance
It's kinda hacky but a quick way to use a select without a datasource is to set the special values:
https://www.smartclient.com/smartgwtee-release/javadoc/com/smartgwt/client/widgets/form/fields/SelectItem.html#setSpecialValues-java.util.LinkedHashMap-

HTML code in Dynamic jasper

I tried to add an HTML styled text to my dynamic jasper report
JRDesignBand band = new JRDesignBand();
band.setHeight(20); // Set band height
JasperDesign jasperDesign = new JasperDesign();
JRDesignTextField textField = new JRDesignTextField();
textField.setX(0); // x position of text field.
textField.setY(0); // y position of text field.
textField.setWidth(860); // set width of text field.
textField.setHeight(20); // set height of text field.
JRDesignExpression jrExpression = new JRDesignExpression(); // new instanse of expression. We need create new instance always when need to set expression.
jrExpression.setText("<p>text space</p>"); // Added String before field in expression.
textField.setExpression(jrExpression);
textField.setMarkup("html");
band.addElement(textField);
((JRDesignSection) jasperDesign.getDetailSection()).addBand(band);
JasperDesignViewer.viewReportDesign(jasperDesign);
But the text still has HTML tags.
As far as I know, the html tags allowed are very limited and for basic text formatting.
<b>bold</b>
<i>italic</i>
<u>underlined</u>
And thats it.
There is a discussion here about "html" and "styled" markup having issues when exporting to PDF http://community.jaspersoft.com/questions/521757/html-markup-pdf

Wicket change label/textfield value

I am trying to learn Wicket. One of the problems I encounter, is changing the values of components like a label.
This is how I declare the label:
Label message = new Label("message", new Model<String>(""));
message .setOutputMarkupId(true);
add(message );
The only solution I can find:
Label newMessage= new Label(message.getId(), "MESSAGE");
newMessage.setOutputMarkupId(true);
message.replaceWith(newMessage);
target.add(newMessage);
Is there a better/easier way to edit the value of a Wicket label and display this new value to the user?
Thanks!
I think you did not understand what Models are. Your example could be rewritten as follows
Model<String> strMdl = Model.of("My old message");
Label msg = new Label("label", strMdl);
msg.setOutputMarkupId(true);
add(msg);
In your ajax event
strMdl.setObject("My new message");
target.add(msg);

How to print a jasper report in 3 exemplar with little changes?

I've created a jasper report with iReport and I can print it perfectly.
I need to print 3 examples of it (original example, client example, department example) with very few changes, for example changing a label in the report.
I pass PRINT_FOR as parameter to iReport.
Does any body know how to approach this goal?
HashMap parameters = new HashMap();
String option = "C:\\option.jasper";
JRDataSource beanDataSource = reportMapper.getDataSource();
JasperPrint jasperPrint = JasperFillManager.fillReport(option, parameters, beanDataSource);
JasperPrintManager.printPage(jasperPrint, 0, true))
A first thought is just make a general report template and have some "hooks" in which you can insert the differences for each version; you can send the "differences" via the parameters from Java.
Instead of using a Static Text field you can use a Text Field that allows you to use and expression to determine the text output. In this case you would check to see if the PRINT_FOR parameter is equal to the client or department and if not use the original value. You expression would look something like this:
($P{PRINT_FOR}.equals("DEPARTMENT") ? "Department Label" : ($P{PRINT_FOR}.equals("CLIENT") ? "Client Label" : "Original Label"))
Where Department Label is outputted when PRINT_FOR is equal to DEPARMTNENT, Client Label is outputted when PRINT_FOR is equal to Client, and Original Label is outputted if it is not equal to either of the above.
Also worth noting is that in the code snippet about you never set the value for the PRINT_FOR parameter in your java code and you are not using a generic HashMap. It should look something closer to:
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("PRINT_FOR", "CLIENT");
UPDATE: Based on your comment, you basically want to do export all 3 reports as one at the same time. This can be accomplised by using the JRPrintServiceExporter. Basically create the three JasperPrint Objects, and put them in a list. Then use the exporter to print them out. Something like:
//add all three JasperPrints to the list below
List<JasperPrint> jasperPrints = new ArrayList<JasperPrint>();
...
//create an exporter
JRExporter exporter = new JRPrintServiceExporter();
//add the JasperPrints to the exporter via the JASPER_PRINT_LIST param
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrints);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
//this one makes it so that the settings choosen in the first dialog will be applied to the
//other documents in the list also
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG_ONLY_ONCE, Boolean.TRUE);
exporter.exportReport();
When you use your own JRBeanCollectionDataSource, you must create for each JasperPrint their respective JRBeanCollectionDataSource
JRBeanCollectionDataSource dsCliente = new JRBeanCollectionDataSource(listaDetalle);
JasperPrint jasperPrintCliente = JasperFillManager.fillReport("plantillaDoc.jasper", paramsHojaCliente, dsCliente);
listaJasperPrint.add(jasperPrintCliente);
JRBeanCollectionDataSource dsCaja1 = new JRBeanCollectionDataSource(listaDetalle);
JasperPrint jasperPrintCaja1 = JasperFillManager.fillReport("plantillaDoc.jasper", paramsHojaCaja, dsCaja1);
listaJasperPrint.add(jasperPrintCaja1);

Categories