IllegalArgumentException when using SpinnerItem in SmartGWT - java

I am trying to use a SpinnerItem as the editor type for a ListGridField
final ListGridField quantityGridField = new ListGridField("quantity", "Cantidad");
quantityGridField.setEditorType(SpinnerItem.class);
quantityGridField.setCanEdit(true);
But after I compile the project and deploy it this error comes up.
java.lang.IllegalArgumentException: No BeanFactory has been registered for: com.smartgwt.client.widgets.form.fields.SpinnerItem
This is the first time that I get this error and I have not found any related question here.

As it's described in javadoc to the method that you use (setEditorType(class)) you use Reflection mechanism of smartgwt. You can read about it here: http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/docs/Reflection.html .
According to this documentation you should register SpinnerItem(which is a subclass of FormItem) prior of using it:
Similarly, to register FormItem and all its subclasses found in the
classpath (including your custom subclasses), you can use the
BeanFactory.FormItemMetaFactory.
GWT.create(BeanFactory.FormItemMetaFactory.class);
So just try to insert this GWT.create line somewhere in your code before using it, so gwt compiler will be able to find your editor.

Related

How do you disable trusted.packages check for Spring-Kafka JsonDeserializer?

I have legacy Spring-Scala project. I have added new event type to one of the topics and now consumers throw exceptions
Caused by: java.lang.IllegalArgumentException: The class '...' is not in the trusted packages: [java.util, java.lang, ...].
It seems that a few classes are always added by Spring. I want to disable this feature but it seems that list of classes must be empty for the code to ignore it. But I don't see how that list would ever be empty if some java packages are added by Spring itself. Any suggestions?
I got this. There is a method called .addTrustedPackages and it handles "*" argument as one that clears the internal trustedPackages list. Neat design... >.<
So the following code works
val deserializer = new JsonDeserializer[...]()
deserializer.addTrustedPackages("*")

Eclipse Groovy DSLDs and static compilation

Is it possible to define Eclipse Groovy DSLD (DSL Definition) which can be statically compilable?
I tried to use DSLD example provided by Eclipse, so I created TestDsl.dsld:
contribute(currentType(subType('groovy.lang.GroovyObject'))) {
property (
name : 'newProp',
type : String,
provider : 'Sample DSL',
doc : 'This is a sample. You should see this in content assist for GroovyObjects: <pre>newProp</pre>')
}
Then I wrote a test class using previous property. This class should be compiled statically. Eclipse is showing new property as a valid one, but then it fails to compile.
Same result occurs using both #CompileStatic and #TypeChecked.
DSLDs introduce new methods and properties into content assist and type inferencing. This does not guarantee the methods or properties will be available at compile- or run-time. They operate more like hints than anything.
Quite often, DSLDs are used to fill a gap that exists between the static type checker and the dynamic execution state of your program. If you want something that is compatible with #TypeChecked or #CompileStatic, you may need to write a TypeChekingExtension instead of a DSLD contribution.

Reflections library returns empty list in Android

I'm attempting to retrieve a list of classes with a specific annotation in Android. I'm trying to use the Reflections library to do so. But no matter what I do, Reflections returns an empty set. Finally, I tried using Reflections.getAllTypes(), which should return all classes in a package, and it gives me the message "Couldn't find subtypes of Object. Make sure SubTypesScanner initialized to include Object class - new SubTypesScanner(false)" I have verified that I am doing so, so I looked in the code for that method and it returns that error if there are no classes in the package.
Here's an example of the code where I'm getting the error:
Reflections reflections = new Reflections(this.getClass().getPackage().getName(),
new SubTypesScanner(false));
Set<String> classes = reflections.getAllTypes(); // Throws runtime error
This should, at the very least, return the class that it is called from. I've also tried using an empty string for the package, and the answer here. Any ideas what could be causing this?
I met the same problem. Since Reflections use java assist to resolve .class file in .jar file, which isn't exist in android application, so it is not possible to use Reflections. However we could use other tool to resolve .dex and it would work

Create a constructor which use another class

I try to create a template object of task using existing task object. When i use a special constructor I get the error:
incompatible types: Task cannot be converted to TaskTemplate
Here is the code I'm using the create the TaskTemplate:
TaskTemplate bean = new TaskTemplate(newTask);
Here is the constructor I'm calling:
public TaskTemplate(Task task) {
this.setTitle(task.getTitle());
this.setDate(task.getDate());
}
But when I set all properties in the place where object is created everything is ok.
TaskTemplate bean = new TaskTemplate();
bean.setTitle(newTask.getTitle());
bean.setDate(newTask.getDate());
Why does it happen?
How can I create a constructor which will get a task and create a template?
It is highly likely that you need to rebuild your project.
This kind of problem can happen when the compiled class the calling code is using is out of date with the source code you are viewing, causing great consternation when recent changes (such as creating a new constructor) do not seem to exist from the perspective of the calling code.
Most IDEs automatically rebuild as you code: Check that your IDE is configured to build automatically. If you aren't using an IDE, consider using one.

POI for XPages - using xwpfdocument

To help solve another problem I have, I'm testing the following code in the postGenerationProcess event of the POI Word widget:
var jce:writeXWPFDocument = new writeXWPFDocument();
var newString3 = jce.doSomething3(xwpfdocument);
print("newString3 = " + newString3);
doSomething3 is defined in a Java class contained in the .nsf.
public class writeXWPFDocument {
public String doSomething3(XWPFDocument xwpfdocument) {
return "DO SOMETHING - xwpfdocument";
}}
When I run this code, I get the error:
Java method 'doSomething3(org.apache.poi.xwpf.usermodel.XWPFDocument)'
on java class 'AZGPackage.writeXWPFDocument' not found
What could be causing this error?
#Knut Hermann - this is a test which relates to the other problem you have been helping me with.
Edit to make the correct answer easier to find:
I have used poi in a few applications. I've encountered similar problems twice: First, usually when I accidentally import a class with the same name from the wrong package (like lotus.local.domino.Database instead of lotus.domino.Database). The other time I encountered this (and the only time the package name was identical) was when I had poi in a plug-in that I had added to the build path and also had it installed by a poi extension library I had built. If you can't cast an object as itself, there is an issue with the ClassLoader, and I don't know what would cause that other than a class being listed twice.
SSJS seems to pass a different object type to the function. Try to change the class of the parameter to Object and for testing return the class name.
In a production code you could check with instanceof if the parameter has the right data type.
In General: consider using a facade pattern, so you keep your complex Java classes away from SSJS

Categories

Resources