Binder partially

If i have and Entity with several properties and i want to bind it with a form but not with all properties. How can i do it?

Entity with three properties

@Entity public Class Person { // with some bean validation anottations private String p1; private String p2; private String p3; ... } Form with only two fields with the same names of the properties

public Form extends FormLayout{ private TextField p1; private TextField p2; ... } Then bind

BeanValidationBinder<Person> binder = BeanValidation<>(Person.class)

// binder.bindInstaceFields(form) ?

binder.forField(p1).bind("p1");
binder.forField(p2).bind("p2");

When i deployed Wildfly complain about a NullPointer but the project appear runs perfect in the browser.
I suppose that the nullpointer is about property p3.

One solution would be create a superClass the person with p1 or p2 properties. Is it another?

Hi,

Where is the null pointer coming from? Can you give a stack trace? I’m thinking this might be more of a bean validation issue than a Binder issue.

-Olli

Perhaps you are right because in my project i load some data of Entities with restriction but unfortunatelly o don’t know what is happening. The project doesn’t start because of nullpointer exception.

This is the stack trace


20:58:41,146 ERROR [org.jboss.as.controller.management-operation]
(DeploymentScanner-threads - 1) WFLYCTL0013: Operation (“deploy”) failed - address: ([(“deployment” => “pra3.war”)]
) - failure description: {“WFLYCTL0080: Failed services” => {"jboss.deployment.unit."pra3.war".




WeldStartService" => "Failed to start service
Caused by: org.jboss.weld.exceptions.DefinitionException: Exception List with 1 exceptions:





Exception 0 :
java.lang.NullPointerException
at sun.reflect.annotation.TypeAnnotationParser.mapTypeAnnotations(TypeAnnotationParser.java:356)
at sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedTypeBaseImpl.(AnnotatedTypeFactory.java:139)
at sun.reflect.annotation.AnnotatedTypeFactory.buildAnnotatedType(AnnotatedTypeFactory.java:65)
at sun.reflect.annotation.TypeAnnotationParser.buildAnnotatedType(TypeAnnotationParser.java:79)
at java.lang.reflect.Field.getAnnotatedType(Field.java:1170)
at org.hibernate.validator.internal.metadata.provider.TypeAnnotationAwareMetaDataProvider.findTypeAnnotationConstraintsForMember(TypeAnnotationAwareMetaDataProvider.java:65)
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.findPropertyMetaData(AnnotationMetaDataProvider.java:244)
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getFieldMetaData(AnnotationMetaDataProvider.java:227)
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.retrieveBeanConfiguration(AnnotationMetaDataProvider.java:137)
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getBeanConfiguration(AnnotationMetaDataProvider.java:125)
at org.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getBeanConfigurationForHierarchy(AnnotationMetaDataProvider.java:108)
at org.hibernate.validator.internal.metadata.BeanMetaDataManager.createBeanMetaData(BeanMetaDataManager.java:203)
at org.hibernate.validator.internal.metadata.BeanMetaDataManager.getOrCreateBeanMetaData(BeanMetaDataManager.java:231)
at org.hibernate.validator.internal.metadata.BeanMetaDataManager.getBeanMetaData(BeanMetaDataManager.java:178)
at org.hibernate.validator.internal.engine.ValidatorImpl.getConstraintsForClass(ValidatorImpl.java:326)
at org.hibernate.validator.internal.cdi.ValidationExtension.determineConstrainedCallables(ValidationExtension.java:241)
at org.hibernate.validator.internal.cdi.ValidationExtension.processAnnotatedType(ValidationExtension.java:228)
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.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:88)
at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:78)
at org.jboss.weld.injection.MethodInvocationStrategy$SimpleMethodInvocationStrategy.invoke(MethodInvocationStrategy.java:129)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:299)
at org.jboss.weld.event.ExtensionObserverMethodImpl.sendEvent(ExtensionObserverMethodImpl.java:124)
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:277)
at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:255)
at org.jboss.weld.bootstrap.events.ContainerLifecycleEvents.fireProcessAnnotatedType(ContainerLifecycleEvents.java:197)
at org.jboss.weld.bootstrap.events.ContainerLifecycleEvents.fireProcessAnnotatedType(ContainerLifecycleEvents.java:169)
at org.jboss.weld.bootstrap.BeanDeployer.processAnnotatedTypes(BeanDeployer.java:156)
at org.jboss.weld.bootstrap.BeanDeployment.createTypes(BeanDeployment.java:245)
at org.jboss.weld.bootstrap.WeldStartup.startInitialization(WeldStartup.java:407)
at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:76)
at org.jboss.as.weld.WeldStartService.start(WeldStartService.java:94)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:2032)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1955)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
"}}
20:58:41,240 INFO [org.jboss.as.server]
(DeploymentScanner-threads - 1) WFLYSRV0010: Deployed “pra3.war” (runtime-name : “pra3.war”)
20:58:41,240 INFO [org.jboss.as.controller]
(DeploymentScanner-threads - 1) WFLYCTL0183: Service status report
WFLYCTL0186: Services which failed to start: service jboss.deployment.unit.“pra3.war”.WeldStartService: Failed to start service



And my GitHub project






GitHub



OK i found it something

My dependencies now are:
deltaspike-core-api
deltaspike-core-impl
deltaspike-data-module-api
deltaspike-data-module-impl
cdi-api
vaadin-cdi
javaee-web-api



Caused by: org.jboss.weld.exceptions.DefinitionException: Exception List with 1 exceptions:
Exception 0 :
java.lang.NullPointerException

If i omitted cdi-api and @Email restriction runs ok

I thought that it was neccessary (bean validation)
validation-api
hibernate-validator

But if i put them in the POM i’ve got the next error:


Caused by: javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint ‘javax.validation.constraints.Email’ validating type ‘java.lang.String’. Check configuration for ‘email’

It seems that i need another dependency.
Any site to study better the plugin dependencies?

Maybe something like this:
http://www.baeldung.com/javax-validation

-Olli

Thanks Olli for the link.
After i read nothing change (well i understand a little why these dependencies)
i added:
validation-api (specification)
hibernate-validator (implementation)
hibernate-validator-annotator-processor

Still the runtime error



Caused by: javax.ejb.EJBException: javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint ‘javax.validation.constraints.Email’ validating type ‘java.lang.String’. Check configuration for ‘email’


I read the cause and it seems that the container doesn’t find the validator to @Email annotation.

In the webinar “JPA bets practice” with the code jpa-adressbook it doesn’t use any of these dependencies (only deltaspike and vaadin-cdi).

Looks like in
https://github.com/mstahv/jpa-addressbook

they are using this to validate an email address String:

@Pattern(regexp = ".+@.+\\.[a-z]
+", message = "Must be valid email")
private String email;

For me it helped to patch WildFly with hibernate validators. See the chapter “1.1.4. Updating Hibernate Validator in WildFly” of the following article: https://docs.jboss.org/hibernate/stable/validator/reference/en-US/html_single/#validator-gettingstarted-createproject