Skip to main content

Posts

Showing posts from December, 2017

10. JSF How to access my resources files?

Sometimes it is really difficult to access any resources form different Java applications. So let's see some scenarios: 1. Executable jar application in a NO WEB environment. Take into account that this is not a JSF application !!! It is desired to have a property file outside the "jar file" so that we can change properties when needed. For instance, we will place the properties file in the same folder that the "jar file" lies. To access the folder where the jar is, the trick is to access the folder where the compiled classed are placed and scale 3 folders . (Oh! rather strange, if anybody knows a better idea.., he will be welcome). Here is a simple code. The name of the class containing the code is ThisClass, and we have created a Property class that feeds with a file in the same folder that the" jar file" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 /** * Gets the folder where resides the executable

9. JSF: Solving common problems

1. Target Unreachable, identifier [bean] resolved to null When you reference a bean in a xhtml file with "#{bean.method}" and get this error, you should verify that: The bean implements Serializable . The references (javax.servlet-api.4.0.0, javax.faces.2.3.3,  javax.el.api.3.0.1, org.primefaces.6.1) have been selected in your pom.xml You have created the files bean.xml and faces-config.xml in the webapp/WEB-INF folder You have used the correct annotations from CDI  (javax.inject.Named and javax.enterprise.context.SessionScoped, ...) and not ManagedBean or jsf2.2 scopes. 2. Bean declaring a passivating scope must be passivation capable This error causes server not starting and fills up the console with long chained exceptions. It is very annoying. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 SEVERE: A child container failed during start java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start co

8. JSF: Using JPA, connection pool, JNDI Datasources

0. Introduction I have been googling and found 2 important posts on this matter, they both use Apache DBCP with JPA Hibernate Boraji.com  :  No persistence.xml is used. All programmatically. Memorynotfound.com  : With persistence.xml JavaHelps : Simplifies the process of using JPA with Hibernate However, I want to define the data sources in Tomcat as JNI resource. 1. Create a simple web Maven project The detailed steps to do this is in this post . Basically : a. Project - New Maven project ( check " Create a simple project (skip archetype selection)" and " Use default Workspace location ") - Next . b. Select " WebJPA " for Group Id, Artifact Id and Name. Select Packaging to " war ". Optionally provide a Description, Finish. c. A Maven pom.xml has been created. d. A properties section is inclosed for detailing java compiler version, encoding, web.xml omitting. e. A dependencies section for enclosing the needed jars.