I get a no such property error when trying to access the final properties of one class from inside a service class.
In a service I have the following code.
class ShiftService{
...
def getEvents(shift){
//if I try to access static final get error
def type=shiftEvent.START;
//NO SUCH PROPERTY shiftEvent for ShiftService
}
...
}
//currently in same ShiftService.groovy file
class shiftEvent{
static final String START="shiftStart";
static final String END="shiftEnd";
static final String DAY_BOUNDARY="dayBoundary";
static final String CHECKIN="individualCheckin";
static final String CHECKOUT="individualCheckout";
static final String NIGHT_START="individualNightStart";
static final String NIGHT_END="individualNightEnd";
...
}
Related
The standard that I see in repos is
class A extends StatelessWidget {
final String title;
...
What would be the reason to use
class A extends StatelessWidget {
final String _title;
...
On using public variable, you don't see error while assigning values to the named optional parameters like:
class AnyClass extends StatelessWidget {
final String title;
AnyClass({this.title}); // no error
}
But if you use private variable, like:
class AnyClass extends StatelessWidget {
final String _title;
AnyClass({this._title}); // Error: named optional parameters can't start with an underscore
}
Reason for the error:
Named/optional arguments with constructor shorthand leaks impl details, see more
I am using avro-maven-plugin 1.8.1 to generate java code from schema,and all the fields are public and deprecated,like this:
public class data_elements extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord {
private static final long serialVersionUID = 2829359487251568000L;
public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("......");
public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
#Deprecated public java.lang.CharSequence timestamp;
#Deprecated public double value;
#Deprecated public java.lang.CharSequence op;
...
}
It makes confused and uncomfortable, does anyone know why it is like that?
If you pass in the fieldVisibility=private parameter then the #Deprecated should disappear and your fields will be private.
I have one List box and I would like to set code type of it.
I create new AbstractCodeType :
public class MyCodeType extends AbstractCodeType<String, String> {
private static final long serialVersionUID = 6808664924551155395L;
public static final String ID = null;
#Override
public String getId() {
return ID;
}
#Order(10.0)
public static class UnknownCode extends AbstractCode<String> {
private static final long serialVersionUID = -1307260056726644943L;
public static final String ID = "Unknown";
#Override
protected String getConfiguredText() {
return TEXTS.get("Unknown");
}
#Override
public String getId() {
return ID;
}
}
}
and I set this code type in list box :
#Override
protected Class<? extends ICodeType<?, String>> getConfiguredCodeType() {
return MyCodeType.class;
}
But doesn't work. It return empty box.
While I was debugging I noticed that in AbstractListBox.class in initConfig method it call this code type and set code type in m_lookupCall inside setCodeTypeClass. Then inside execLoadTableData, it get call but this call return empty array when called call.getDataByAll().
I suspect that converting between code type and Lookup call does not work properly.
EDIT
I try to debug where is the problem and if follow the path :
initConfig() -> CodeLookupCall.newInstanceByService(m_codeTypeClass); (line 581)
and if you look inside CodeLookupCall ;
getDataByAll() in line 221 `resolveCodes(v)` -> BEANS.opt(m_codeTypeClass) -> bean.getInstance() -> m_producer.produce(this) -> return (T) getCache().get(createCacheKey(type));
This is in class CodeService.class in line 97 :
Class<T> type is right class and createCacheKey(type) return not null object but then getCache().get(...) return null. From this point on everything is null (what is reasonable regarding that getCodeType return null.)
This is what I found out while debugging, if it helps someone to figure out what is wrong.
It looks like your codetype class is not found by the bean manager. CodeService only finds CodeTypes in its classpath (accessible in the server).
-> You might need to move your class to the shared project.
You can find examples for code types in the contacts demo application:
https://github.com/BSI-Business-Systems-Integration-AG/org.eclipse.scout.docs/tree/releases/5.2.x/code/contacts
I tested your code snippet with Eclipse Scout Neon M4 and I could reproduce your described error.
However, it seems that this bug has been fixed with Scout Neon M5. So I suggest that you upgrade to the latest milestone version, which is recommended anyway.
I'm working on crawler4j using groovy and grails.
I have a BasicCrawler.groovy class in src/groovy and the domain class Crawler.groovy and a controller called CrawlerController.groovy.
I have few properties in BasicCrawler.groovy class like url, parentUrl, domain etc.
I want to persist these values to the database by passing these values to the domain class while crawling is happening.
I tried doing this in my BasicCrawler class under src/groovy
class BasicCrawler extends WebCrawler {
Crawler obj = new Crawler()
//crawling code
#Override
void visit(Page page) {
//crawling code
obj.url = page.getWebURL().getURL()
obj.parentUrl = page.getWebURL().getParentUrl()
}
#Override
protected void handlePageStatusCode(WebURL webUrl, int statusCode, String statusDescription) {
//crawling code
obj.httpstatus = "not found"
}
}
And my domain class is as follows:
class Crawler extends BasicCrawler {
String url
String parentUrl
String httpstatus
static constraints = {}
}
But I got the following error:
ERROR crawler.WebCrawler - Exception while running the visit method. Message: 'No such property: url for class: mypackage.BasicCrawler
Possible solutions: obj' at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
After this I tried another approach. In my src/groovy/BasicCrawler.groovy class, I declared the url and parentUrl properties on the top and then used databinding (I might be wrong since I am just a beginner):
class BasicCrawler extends WebCrawler {
String url
String parentUrl
#Override
boolean shouldVisit(WebURL url) { //code
}
#Override
void visit(Page page) { //code
}
#Override
protected void handlePageStatusCode(WebURL webUrl, int statusCode, String statusDescription) {
//code}
}
def bindingMap = [url: url , parentUrl: parentUrl]
def Crawler = new Crawler(bindingMap)
}
And my Crawler.groovy domain class is as follows:
class Crawler {
String url
String parentUrl
static constraints = {}
}
Now, it doesn't show any error but the values are not being persisted in the database. I am using mongodb for the backend.
I think this example is a bit contrived but here is a way you might solve this problem in current situation:
class BasicCrawler extends WebCrawler {
#Override
void visit(Page page) {
Crawler obj = new Crawler()
obj.url = page.getWebURL().getURL()
obj.parentUrl = page.getWebURL().getParentUrl()
obj.save()
}
#Override
protected void handlePageStatusCode(WebURL webUrl, int statusCode, String statusDescription) {
Crawler obj = Crawler.findByUrl(webUrl)
obj.httpstatus = "not found"
obj.save()
}
}
Key here is not using a member instance variable and using the URL to 'refetch' and update original site 'visited' since I'm assuming that will be a unique constraint on each row.
We got a Jetty/Jersey application. We are converting it to use Guice for DI. The problem: We need more than one instance of a Singleton classes. The catch: The number of instances is determined dynamically from a configuration file. Therefore we cant use annotations for different instances.
final InjectedClass instance = injector.getInstance(InjectedClass.class);
This is the standard syntax of the injector. I need something like
final String key = getKey();
final InjectedClass instance = injector.getInstance(InjectedClass.class, key);
There is a way to get an instance from a Guice Key.class
final InjectedClass instance = injector.getInstance(Key.get(InjectedClass.class, <Annotation>);
but the problem is that I need some dynamic annotation, not predefined one.
You could try to use Provider, or #Provides method that would have map of all instances already created. When the number of instances is reached number defained in config file, you wont create any new instances, instead you return old instance from map.
For example something like this could help you.
public class MyObjectProvider implements Provider<MyObject> {
private final Injector inj;
private int counter;
private final int maxNum = 5;
private List<MyObject> myObjPool = new ArrayList<MyObject>();
#Inject
public MyObjectProvider(Injector inj) {
this.connection = connection;
}
public MyObject get() {
counter = counter+1%maxNum;
if(myObjPool.size()=<maxNum) {
MyObject myobj = inj.getInstance(MyObject.class);
myObjPool.add(myobj);
return myobj;
} else {
return myObjPool.get(counter);
}
}
}
P.S.
I wrote this from my head so maybe it does not compile, this is just an idea.
You can solve this by creating a factory. In my example I have used the guice extension called multibindings
interface InjectedClassFactory {
public InjectedClass get(String key);
}
class InjectedClass {}
class InjectedClassFactoryImpl implements InjectedClassFactory{
private final Map<String, InjectedClass> instances;
#Inject
InjectedClassFactoryImpl(Map<String, InjectedClass> instances) {
this.instances = instances;
}
#Override
public InjectedClass get(String key) {
return instances.get(key);
}
}
class MyModule extends AbstractModule {
#Override
protected void configure() {
MapBinder<String, InjectedClass> mapBinder =
MapBinder.newMapBinder(binder(), String.class, InjectedClass.class);
//read you config file and retrieve the keys
mapBinder.addBinding("key1").to(InjectedClass.class).in(Singleton.class);
mapBinder.addBinding("key2").to(InjectedClass.class).in(Singleton.class);
}
}