0

I use Google App Engine 1.9.51. In Eclipse I create 4 projects for multi-services: - One Ear (GoalsCompletion) - One common jave project (GoalsCompletion_common) - 2 Web app (GoalsCompletion_default and GoalsComletion_task) as shown in screen capture below.

enter image description here

In web app (e.g GoalsCompletion_default), - I have few jsf files refer to the manage bean defined in common project (ie. GoalsCompletion_common). - I also have jave files refer to the interface defined in common project.

I included common project as dependency for web app deployment as below:

enter image description here

The problems I'm facing is in web app, when I call the getter for manage bean defied in common project, nothing return.

For example

in web.xml

<context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>#{userSession.theme}</param-value>

in jsf page

Current Theme: #{userSession.theme}

If I move the UserSession Manage bean from common project to web app, value return.

GAE didn't complain class not found, no error just return empty value, so it seem like something wrong in my configuration for deployment. Any help?

songjing
  • 545
  • 4
  • 22
  • Workaround is I add those manage beans from common project to faces-config.xml in each web app. And it work. So seem like web app will not scan the generated jar file from other project. Not sure is that is the only solution or have better way... – songjing Apr 28 '17 at 13:20
  • Read about 'web-fragments'... – Kukeltje Apr 28 '17 at 13:23
  • you can use `EJB`-s to access managed beans in other apps. Or `JAX-RS`. – The Bitman Apr 28 '17 at 15:02
  • GAE don't support J2EE. And that common project is just a java project with code that I plan to reuse by other 2 web app. That why it is pack as jar file and include in other web app projects. So either my app server is GAE or not, that is no way to share with EJB -s or JAX-RS because it is not an ordinary web app. – songjing Apr 28 '17 at 16:40
  • 1
    You need to have the faces-config.xml in common project in order to scan the managed beans. Please see http://stackoverflow.com/questions/7663818/how-to-reference-jsf-managed-beans-which-are-provided-in-a-jar-file – OTM Apr 28 '17 at 19:59
  • Thanks mate, defined the message bean in faces-config.xml for common project (jar output) is working. – songjing Apr 29 '17 at 08:49

2 Answers2

0

After few time try and error...

Actually in web app project, if included common project as dependency for it's Web Deployment Assembly, I will not need to have faces-config.xml in common project /WEB-INF folder.

In this case I can just use the annotations instead of xml to config beans.

The reason this mention is not working early is because every time when I make a changes on common project's pom.xml (e.g include new dependency or change the dependency version), Eclipse will remove my setting Web Deployment Assembly.

So I just need to make sure the common project is exist in other web project's Web Deployment Assembly section before deployment / run the server. And if not, I need add in again.

Not sure is that a way to make the setting permanence

songjing
  • 545
  • 4
  • 22
-1

Thanks to OTM's suggestion on above post...

Ya, a simple solution is just to defined the managed bean inside faces-config.xml and place under \META-INF in common project.

example of faces-config.xml:

<?xml version="1.0"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
    version="2.2">

    <managed-bean>
        <managed-bean-name>beanName</managed-bean-name>
        <managed-bean-class>package.BeanName</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
songjing
  • 545
  • 4
  • 22
  • Using xml to config beans is very pre-historic. Using annotations is more modern, and when you use jsf 2.2 it is even suggested to start using CDI instead of jsf-managed beans – Kukeltje May 02 '17 at 10:39
  • Hi mate... Ya, I'm using 2.2.10. May I know what you means of using CDI? – songjing May 02 '17 at 14:03
  • There is this thing called google... https://www.google.com/search?q=cdi%2Bjsf but using stackoverflow search would work to. Then there is http://stackoverflow.com/questions/4347374/backing-beans-managedbean-or-cdi-beans-named – Kukeltje May 02 '17 at 14:12