Skip to main content

Posts

7. JSF: Including additional files in Maven (local jars, JNDI datasources, properties, resource bundles ..)

This is briefly exposed in an earlier post , but I think it is important to return to this aspect. I am using Eclipse Oxygen and working with Maven projects. 1. Web configuration files 1. Files beans.xml and faces-config.xml should be placed in:            src/main/webapp/WEB-INF/ beans.xml     src/main/webapp/WEB-INF/ faces-config.xml 2. Some aspects of file web.xml can be replaced or implemented in a java class annotated with  @WebListener that implements ServletContextListener interface. BalusC explains in detail this issue. But if you need to use this file (not all capabilities of web.xml can be easily replaced programmatically as explains Piotr ), you can locate it in the same folder as beans.xml and faces-config.xml files     src/main/webapp/WEB-INF/ web.xml 2. JPA persistence.xml 1. File persistence.xml should be placed in META-INF in the resources folder.     src/main/reso...

6. JSF: Weld CDI and Reflection. Using reflection on injected objects.

0. Introduction Weld and Reflection are not good friends. When you inject a bean into another, Weld CDI makes a proxy of the injected object. So when you want to obtain information using Reflection, you cannot see the original injected object. BalusC gives us the clue to introspect a Weld proxy bean. He uses BeanInfo Interface from the Java Beans API . By means of this Bean API, we can retrieve the original object from the proxy object. It is stored in the attribute  targetInstance . Once we have this original object, we can use reflection.  Note: To use Weld with Tomcat, we must include this dependency in the pom.xml file <!-- https: //mvnrepository.com/artifact/org.jboss.weld.servlet/weld-servlet-shaded --> < dependency > < groupId > org . jboss . weld . servlet </ groupId > < artifactId > weld - servlet - shaded </ artifactId > < version > 3.0 . 5 . Final </ version > </ dependency > ...

5. JSF Validating Inputs part 2/2

0. Introduction I am an old poor beginner and I am very pleased with the help of Java gurus like Marty Hall and his coreservlet page . So while learning his invaluable lessons, I try to give an example. I will cover 3 aspects: Validating by means of Action Controller of a managed bean  Using custom validator method with validator attribute  Validation through Bean Validation JSR 380 1. Validation using a managed bean action controller In order to display messages, these steps may be needed: A xhtml tag <h:message for="control_to_validate_id"> But it is preferred a <h:messages ..> to put messages at the top of the form Add messages to display by means of java code: FacesMessage errorMessage = new FacesMessage("This an error .."); errorMessage.setSeverity(FacesMessages.SERVERITY_ERROR);  FacesContext.getCurrentInstance().addMessage( null , errorMessage); The severity can be: SEVERETY_ERROR (for errors) SEVERETY_INFO (...

4. JSF: Validating Inputs. Part 1/2

0. Introduction As Marty Hall indicates, there are several resources for validating inputs: 1. required="true" requiredMessage="…" for fields that should be filled. 2. converterMessage="..." for no-string fields that require a conversion. 3. f:validateBlah tags, validatorMessage  for values in a range or that matches a regular expression. 4. h:message, h:messages for values displayin messages. 5. Validating manually by means of the action controller. 6. h:input Blah validator="#{somebean.somemethod}" using a custom validator. 7. Using Apache MyFaces for URL and other stuff validation.( problematic!!! ) 1. A simple form with different validations Here is a simple form using the first 6 validators. I ts name is:    test-05-validation-page.xhtml 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56...