NullPointerException when trying to reload IndexedContainer with fresh data - vaadin

I'm trying to "reload" an IndexedContainer with new fresh data, but get a NPE.
I have a addItemsToContainer(List<Person> persons) method that I use to populate my container.
Let's say my Person list contains 100 person objects. When I first call addItemsToContainer(List<Person> persons), my container is populated and everything is fine.
However, the second time I call the method, I get a NullPointerException in setValue().
Now, it seems like removeAllItems() do remove all items, but all ItemId's are left in the container. This means that the second time I call the method, the first automatically generated ItemId is 101. Is this the reason I get the NPE? When debugging, I can see that I get the proper value back from person.getId().
My addItemsToContainer method
public void addItemsToContainer(List<Person> persons) {
removeAllItems();
for (Person person : persons) {
Object itemId = addItem();
getContainerProperty(itemId, "Id").setValue(person.getId()); // <-- NPE here
getContainerProperty(itemId, "Name").setValue(person.getName());
}
}
The stacktrace
(ExampleMainTableContainer.java:94 is the statement I marked in the addItemsToContainer method)
com.vaadin.server.ServerRpcManager$RpcInvocationException: Unable to invoke method click in com.vaadin.shared.ui.button.ButtonServerRpc
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:170)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118)
at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:214)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:111)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1371)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:168)
... 24 more
Caused by: com.vaadin.event.ListenerMethod$MethodException: Invocation of method buttonClick in com.example.myapp.web.view.ExampleView$1 failed.
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:528)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:167)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:969)
at com.vaadin.ui.Button.fireClick(Button.java:368)
at com.vaadin.ui.Button$1.click(Button.java:57)
... 29 more
Caused by: java.lang.NullPointerException
at com.example.myapp.web.view.ExampleMainTableContainer.addItemsToContainer(ExampleMainTableContainer.java:94)
at com.example.myapp.web.view.ExampleMainTable.addMainTableItems(ExampleMainTable.java:172)
at com.example.myapp.web.view.ExampleMainTable.experiment(ExampleMainTable.java:86)
at com.example.myapp.web.view.ExampleView$1.buttonClick(ExampleView.java:208)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
... 33 more

The method getContainerProperty(...) returned null, leading to the NPE.
This happened because I filtered my container prior to the second call to addItemsToContainer(...).
When I add a new item to my container, it gets added to allItemIds - the filteredItemIds is left empty. Now, when getContainerProperty(...) is called, it does a check if the container was filtered. If it was filtered, it returns filteredItemIds instead of allItemIds. This meant, of course, that this statement returned an empty list of objects, leading to ´getContainerProperty(...)´ returning null - which finally lead to the NPE.
The solution was to simply add removeAllContainerFilters(); before my ´getContainerProperty(...)´ calls.

Related

org.neo4j.ogm.context.GraphEntityMapper throwing IllegalArgumentException: Can not set Double field to java.math.BigDecimal

Upgraded existing API to use Neo4j 4.3.3 and neo4j-ogm-http-driver to 3.2.25. spring-boot-starter-data-neo4j is 2.3.4.Release. Now if I try to create/fetch a relationship with one of the attribute as Double using org.springframework.data.repository CrudRepository.save() and org.springframework.data.neo4j.repository Neo4jRepository.findById(), it throws below error:
Found relationship type: OWNS to map to RelationshipEntity: RelationshipEntityName
2021-08-21 00:25:14.780 ERROR 3556 --- [nio-8303-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Error mapping GraphModel; nested exception is org.neo4j.ogm.exception.core.MappingException: Error mapping GraphModel] with root cause
java.lang.IllegalArgumentException: Can not set java.lang.Double field RelationshipEntityName.percentage to java.math.BigDecimal
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.lang.reflect.Field.set(Field.java:764)
at org.neo4j.ogm.metadata.FieldInfo.lambda$write$0(FieldInfo.java:352)
at java.security.AccessController.doPrivileged(Native Method)
at org.neo4j.ogm.metadata.FieldInfo.write(FieldInfo.java:349)
at org.neo4j.ogm.metadata.FieldInfo.write(FieldInfo.java:383)
at org.neo4j.ogm.context.GraphEntityMapper.writeProperty(GraphEntityMapper.java:305)
at org.neo4j.ogm.context.GraphEntityMapper.setProperties(GraphEntityMapper.java:268)
at org.neo4j.ogm.context.GraphEntityMapper.createRelationshipEntity(GraphEntityMapper.java:409)
at org.neo4j.ogm.context.GraphEntityMapper.mapRelationshipEntity(GraphEntityMapper.java:354)
at org.neo4j.ogm.context.GraphEntityMapper.mapRelationships(GraphEntityMapper.java:330)
at org.neo4j.ogm.context.GraphEntityMapper.mapContentOf(GraphEntityMapper.java:158)
at org.neo4j.ogm.context.GraphEntityMapper.lambda$map$2(GraphEntityMapper.java:115)
at java.util.ArrayList.forEach(ArrayList.java:1257)
at org.neo4j.ogm.context.GraphEntityMapper.map(GraphEntityMapper.java:117)
at org.neo4j.ogm.context.GraphRowModelMapper.map(GraphRowModelMapper.java:60)
at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.lambda$executeAndMap$1(ExecuteQueriesDelegate.java:165)
at org.neo4j.ogm.session.Neo4jSession.doInTransaction(Neo4jSession.java:590)
at org.neo4j.ogm.session.Neo4jSession.doInTransaction(Neo4jSession.java:564)
at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.executeAndMap(ExecuteQueriesDelegate.java:150)
at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.query(ExecuteQueriesDelegate.java:117)
at org.neo4j.ogm.session.Neo4jSession.query(Neo4jSession.java:425)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282)
at org.springframework.data.neo4j.transaction.SharedSessionCreator$SharedSessionInvocationHandler.lambda$invoke$1(SharedSessionCreator.java:121)
at org.springframework.data.neo4j.transaction.SharedSessionCreator$SharedSessionInvocationHandler.invokeInTransaction(SharedSessionCreator.java:159)
at org.springframework.data.neo4j.transaction.SharedSessionCreator$SharedSessionInvocationHandler.invoke(SharedSessionCreator.java:123)
at com.sun.proxy.$Proxy88.query(Unknown Source)
at org.springframework.data.neo4j.repository.query.GraphQueryExecution$SingleEntityExecution.execute(GraphQueryExecution.java:64)
at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.doExecute(GraphRepositoryQuery.java:76)
at org.springframework.data.neo4j.repository.query.AbstractGraphRepositoryQuery.execute(AbstractGraphRepositoryQuery.java:57)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor$QueryMethodInvoker.invoke(QueryExecutorMethodInterceptor.java:195)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:152)
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:130)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:367)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy111.findByResource(Unknown Source)
I tried changing the attribute percentage to Number, that does not throw the exception but percentage doesn't get saved.
I do not want to upgrade spring-boot-starter-data-neo4j to any major version at this point.
Upgrading to Spring-Data-Neo4j 6.x will again be big migration effort.
I am stuck now.
I found out the exact place where the error was coming from was neo4j.ogm.core files, I tried various versions of the jar but nothing worked.
Finally I resolved the problem by writing a custom converter as the implicit converter was not able to convert between Double and BigDecimal.
public class PercentageConverter implements AttributeConverter<Double, BigDecimal> {
#Override
public BigDecimal toGraphProperty(Double value) {
if (value == null) {
return null;
}
return new BigDecimal(value);
}
#Override
public Double toEntityAttribute(BigDecimal value) {
return value.doubleValue();
}
}
and annotate the entity attribute to use this converter
#Convert(PercentageConverter.class)
This resolved my error and now I can do all CRUD operations successfully

Grails: How to reference Service itself and use it in Java?

A SomeService is defined and in a closure it is passed to a Java class:
package somepackage
class SomeService{
...
def process(){
...
//here, how to reference [thisService]? this keyword?
//I tried this keyword, but an exception occurs
JavaClass javaObject = new JavaClass(thisService, otherParams)
...
}
...
}
Exception is thrown when using this referring to SomeService:
Groovyc: java.lang.NoClassDefFoundError: somepackage/SomeService
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getDeclaredMethods(Class.java:1791)
at org.codehaus.groovy.vmplugin.v5.Java5.configureClassNode(Java5.java:318)
at org.codehaus.groovy.ast.ClassNode.lazyClassInit(ClassNode.java:263)
at org.codehaus.groovy.ast.ClassNode.getUnresolvedSuperClass(ClassNode.java:957)
at org.codehaus.groovy.ast.ClassNode.getUnresolvedSuperClass(ClassNode.java:952)
at org.codehaus.groovy.ast.ClassNode.getSuperClass(ClassNode.java:946)
at org.codehaus.groovy.ast.ClassNode.isDerivedFrom(ClassNode.java:889)
at org.codehaus.groovy.classgen.AsmClassGenerator.assignmentCastAndVisit(AsmClassGenerator.java:4049)
at org.codehaus.groovy.classgen.AsmClassGenerator.evaluateEqual(AsmClassGenerator.java:4002)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitDeclarationExpression(AsmClassGenerator.java:1468)
at org.codehaus.groovy.ast.expr.DeclarationExpression.visit(DeclarationExpression.java:53)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitAndAutoboxBoolean(AsmClassGenerator.java:4111)
at org.codehaus.groovy.classgen.AsmClassGenerator.evaluateExpression(AsmClassGenerator.java:1437)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitReturnStatement(AsmClassGenerator.java:1398)
at org.codehaus.groovy.ast.stmt.ReturnStatement.visit(ReturnStatement.java:47)
at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:35)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:165)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitBlockStatement(AsmClassGenerator.java:728)
at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:69)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:101)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:112)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitStdMethod(AsmClassGenerator.java:616)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitConstructorOrMethod(AsmClassGenerator.java:591)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:123)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitMethod(AsmClassGenerator.java:686)
at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1039)
at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:50)
at org.codehaus.groovy.classgen.AsmClassGenerator.visitClass(AsmClassGenerator.java:276)
at org.codehaus.groovy.control.CompilationUnit$12.call(CompilationUnit.java:748)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:942)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:519)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:497)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:474)
at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:54)
at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.java:80)
at org.jetbrains.groovy.compiler.rt.GroovycRunner.main(GroovycRunner.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:121)
Caused by: java.lang.ClassNotFoundException: entrust.EnTrustService
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 43 more
My question is: how to reference the service itself to other classes? if this is applicable, is this problem related to the calling class being Java class other than groovy class?
You can get a reference to someService bean from ApplicationContext as:
class SomeService{
def grailsApplication
def process(){
...
//here, how to reference [thisService]? this keyword?
//I tried this keyword, but an exception occurs
JavaClass javaObject =
new JavaClass(grailsApplication.mainContext.someService, otherParams)
...
}
}
Doing this, the control goes out of the proxy and fetches the bean from the context. This same principle is applied in transactions or any aspects (AOP) related transition from one method to other in the same service class. Here is an example.

vaadin7: calling navigator from a view renders a stackoverflow error

Given a Main UI which encapsulates a vaadin Navigator, i need to call it from a search view so as to display search results in another view:
1) Main Ui
Navigator nav = new Navigator(this, content)
nav.addView("/search", new SearchView())
...
So everything works fine (with other views), until i implement the search view:
private static final String VIEW_SEARCH= "search"
private static final String VIEW_RESULTS = "searchResults"
in the constructor:
public SearchView() {
UI.getCurrent().getNavigator().addView(VIEW_SEARCH, new SearchView())
UI.getCurrent().getNavigator().addView(VIEW_RESULTS, new SearchResultsView())
which renders a stack overflow error:
*********************************************************
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message transform method call failed at ../../../src/share/instrument/JPLISAgent.c line: 844
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message transform method call failed at ../../../src/share/instrument/JPLISAgent.c line: 844
2013-12-21 19:47:00,772 ERROR [DefaultErrorHandler] -
com.vaadin.server.ServerRpcManager$RpcInvocationException: Unable to invoke method click in com.vaadin.shared.ui.button.ButtonServerRpc
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:170)
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:118)
at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:207)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:111)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1382)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238)
at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.java:53)
at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:49)
at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:82)
at grails.plugin.springsecurity.web.filter.DebugFilter.invokeWithWrappedRequest(DebugFilter.java:102)
at grails.plugin.springsecurity.web.filter.DebugFilter.doFilter(DebugFilter.java:69)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.reflect.InvocationTargetException
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:168)
... 15 more
Caused by: com.vaadin.event.ListenerMethod$MethodException: Invocation of method buttonClick in com.webvibes.conquest.ui.KMUI$2 failed.
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:528)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:969)
at com.vaadin.ui.Button.fireClick(Button.java:368)
at com.vaadin.ui.Button$1.click(Button.java:57)
... 16 more
Caused by: java.lang.StackOverflowError
at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.webvibes.conquest.ui.SearchView.<init>(SearchView.groovy:43)
at com.webvibes.conquest.ui.SearchView.<init>(SearchView.groovy:43)
The goal here is pretty basic, the search view handles a Button which opens up a new view for the results with parameters:
KMUI.getCurrent().getNavigator().navigateTo(VIEW_RESULTS)
Thanks for any help.
* UPDATE:
Well, it seems that putting
UI.getCurrent().getNavigator().addView(VIEW_SEARCH, new SearchView())
UI.getCurrent().getNavigator().addView(VIEW_RESULTS, new SearchResultsView())
directly into the main UI does the job,
but, in that case i miss the results constructor to send the results... what is the best way to send results (HashMap) to the reults view:
No signature of method: com.vaadin.navigator.Navigator.navigateTo() is applicable for argument types: (java.lang.String, java.util.HashMap) values: [/searchResults, [total:0, hits:org.compass.core.impl.DefaultCompassDetachedHits#340f9d23, ...]]
Possible solutions: navigateTo(java.lang.String)
KMUI.getCurrent().getNavigator().navigateTo(VIEW_RESULTS, res)
You can use the session to pass parameter to another view.
Check this link for an example:
Setting and reading session attributes

Why property getter for ui:repeat called during restore view phase? [duplicate]

I'm working with jsf 2 and I'm getting some behaviour which I find hard to explain or understand.
I have several independent h:forms.
one of which looks like this:
<h:form>
<h:commandButton value="#{text.General_Wipe_Now}" action="#{bean.doThate}" >
<f:ajax execute="#form" render="#form" />
</h:commandButton>
<h:selectBooleanCheckbox value="#{bean.ignoreErrors}">Ignore Errors</h:selectBooleanCheckbox>
</h:form>
My question/issue is that whenever I press the aformentioned button, I see other, unrelated, bean member getters (that are parts of other forms) being called. (Through logging)
There is no business logic in any of the getters but I would like to understand the reason for this.
Through printing stacktrace I made sure that JSF is indeed the one calling them.
How would you suggest I follow JSF to understand why they are being called?
What could be the reason?
Thanks!
Ben.
UPDATE
Here is the stacktrace as printed by one of the getters that are running and are not supposed to .
As discussed in the comments, it will be extremely complex to include in this question all of the details that are related so I would rather get help with the tools to find the answer myself.
java.lang.Exception
at com.aCompanyName.applicationName.beans.aBean.getSomethingFromBean(CurrentDevice.java:382)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at com.sun.el.parser.AstValue.getValue(AstValue.java:116)
at com.sun.el.parser.AstValue.getValue(AstValue.java:163)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
at org.apache.myfaces.view.facelets.el.TagValueExpression.getValue(TagValueExpression.java:85)
at org.apache.myfaces.view.facelets.component.UIRepeat.getValue(UIRepeat.java:248)
at org.apache.myfaces.view.facelets.component.UIRepeat.getDataModel(UIRepeat.java:211)
at org.apache.myfaces.view.facelets.component.UIRepeat._validateAttributes(UIRepeat.java:530)
at org.apache.myfaces.view.facelets.component.UIRepeat.visitTree(UIRepeat.java:763)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:797)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:992)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:797)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:992)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:797)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:992)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:797)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:992)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:797)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:992)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:797)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:992)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:797)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:992)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:797)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:992)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:797)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:992)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:797)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:992)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:797)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:992)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:797)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:992)
at org.apache.myfaces.view.facelets.tag.ui.DebugPhaseListener._doTreeVisit(DebugPhaseListener.java:310)
at org.apache.myfaces.view.facelets.tag.ui.DebugPhaseListener.afterPhase(DebugPhaseListener.java:286)
at org.apache.myfaces.lifecycle.PhaseListenerManager.informPhaseListenersAfter(PhaseListenerManager.java:111)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:185)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.openejb.tomcat.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
UPDATE 2
Working on making a SSCCE, will update once I have one.
UPDATE 3
The problem seems to occur with <ui:repeat> value attribute.
This is a SSCCE code that exemplifies the problem:
<h:body>
<ui:repeat var="str" value="#{admin.SList}">
STRING: #{str}
</ui:repeat>
<h:form>
<h:commandButton value="pressie" action="#{admin.doThat}">
<f:ajax execute="#form"/>
</h:commandButton>
</h:form>
</h:body>
The Bean Code:
#PostConstruct
public void init()
{
slist.add("Testing");
slist.add("This");
slist.add("Thing");
}
private List<String> slist = new ArrayList<String>();
public List<String> getSList(){
logger.trace("Getting LIST");
return slist;
}
public void doThat(){
logger.trace("DoThat Was Run");
}
When pressing the button, this is output to the log:
2011-08-16 16:55:55,853 TRACE [http-80-2] (AdminBean.java:80) - Getting LIST
2011-08-16 16:55:55,865 TRACE [http-80-2] (AdminBean.java:85) - DoThat Was Run
Why is getting list run? Is it not redundant?
I don't use MyFaces, so I won't go in its specifics. But for what is worth, on Mojarra the getter is also called for <ui:repeat>. However, the stack is imo more clear as to what is happening. Here's the Thread#dumpStack() until FacesServlet#service():
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1249)
at mypackage.Bean.getList(Bean.java:21)
at sun.reflect.GeneratedMethodAccessor51.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstValue.getValue(AstValue.java:116)
at com.sun.el.parser.AstValue.getValue(AstValue.java:163)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at com.sun.faces.facelets.component.UIRepeat.getValue(UIRepeat.java:272)
at com.sun.faces.facelets.component.UIRepeat.getDataModel(UIRepeat.java:248)
at com.sun.faces.facelets.component.UIRepeat.setIndex(UIRepeat.java:442)
at com.sun.faces.facelets.component.UIRepeat.doVisitChildren(UIRepeat.java:661)
at com.sun.faces.facelets.component.UIRepeat.visitTree(UIRepeat.java:619)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at com.sun.faces.application.view.StateManagementStrategyImpl.restoreView(StateManagementStrategyImpl.java:240)
at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:188)
at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:452)
at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:148)
at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:303)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:189)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:113)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:409)
// Remnant omitted for brevity.
It is thus happening during the restore view phase when the state management needs to visit the entire component tree. The UIRepeat in turn needs to set the row index when its children are to be visited.
According to the UIRepeat#doVisitChildren() source the row index is set to -1. The final goal is to just visit its children in the tree, not to iterate over the model value nor to render anything. It just needs the DataModel in order to be able to set the row index. The value of the datamodel is the list for which you're seeing the getter being invoked. If anything is fine, this getter should be invoked only once during restore view phase. However, if it was invoked during for example render response phase as well, then you may be worrying about this because it would have been completely unnecessary.

Changing request to view scope results in java.io.NotSerializableException: javax.faces.model.ListDataModel

I get the below error, when setting the scope for the managedBean as ViewScoped. Below is the exception Im getting when trying to invoke the page
javax.faces.FacesException: java.io.NotSerializableException: javax.faces.model.ListDataModel
at com.sun.faces.renderkit.ResponseStateManagerImpl.getViewState(ResponseStateManagerImpl.java:137)
at javax.faces.application.StateManager.getViewState(StateManager.java:555)
at com.sun.faces.context.PartialViewContextImpl.renderState(PartialViewContextImpl.java:416)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:300)
at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:981)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:390)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.NotSerializableException: javax.faces.model.ListDataModel
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
Sep 26, 2012 4:01:13 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalStateException: CDATA tags may not nest
at com.sun.faces.renderkit.html_basic.HtmlResponseWriter.startCDATA(HtmlResponseWriter.java:630)
at javax.faces.context.ResponseWriterWrapper.startCDATA(ResponseWriterWrapper.java:172)
at javax.faces.context.PartialResponseWriter.startError(PartialResponseWriter.java:342)
at org.primefaces.context.PrimePartialResponseWriter.startError(PrimePartialResponseWriter.java:210)
at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:200)
at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:123)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
Any pointers or help on resolving the issue is much appericiated. Thanks in Advance.
java.io.NotSerializableException: javax.faces.model.ListDataModel
Your view scoped bean has apparently a ListDataModel property. This is indeed not serializable as its state is per definition dependent on the current HTTP request (which is usually not to be saved/shared anywhere --which would in turn require serialization).
A view scoped bean spans across multiple HTTP requests and is by an unique key stored the HTTP session. Some but not all servletcontainers stores sessions on harddisk instead of on memory and this requires all Java objects which are (in)directly stored in the session to implement Serializable, including view scoped beans and all of its properties.
You can fix this particular issue in 2 ways:
Mark the property transient, get hold of the wrapped list as another property, and use lazy loading in the getter.
private transient DataModel<Foo> model;
private List<Foo> list;
public DataModel<Foo> getModel() {
if (model == null) {
model = new ListDataModel<Foo>(list);
}
return model;
}
Don't use DataModel, but use an alternative instead. A common requirement for having DataModel was in JSF 1.x being able to obtain the current row. But since EL 2.2, you could just pass that as method argument. See also How can I pass selected row to commandLink inside dataTable?

Resources