PrettyFaces, CDI and the case of the missing ?cid=xxx…

Splash Forums PrettyFaces Users PrettyFaces, CDI and the case of the missing ?cid=xxx…

Tagged: 

This topic contains 43 replies, has 3 voices, and was last updated by  Christian Kaltepoth 9 years, 10 months ago.

Viewing 15 posts - 1 through 15 (of 44 total)
  • Author
    Posts
  • #18149

    Tony Herstell
    Participant

    Hi,

    I have seeing a particular problem with CDI conversations that I see using prettyfaces.

    The problem is explained:

    Initially on Primefaces Forum:

    http://forum.primefaces.org/viewtopic.php?f=3&t=17995&sid=1fd3f4708f4c76e3fdeb4e8af9354716&p=55791#p55791

    and then on the Weld form

    http://docs.jboss.org/weld/reference/1.0.0/en-US/html/scopescontexts.html#d0e1777

    The project is vanilla CDI and prettyfaces (actually extended out from the Jboss7 quickstart example code).

    I am happy to send the project if required as its in its infancy or give access to bitbucket repository.

    Thanks in advance for your input.

    Using: JBoss7 ( (CDI-Weld), Primefaces (3.0.1) and Prettyfaces (3.3.2)… and that’s about it so far!

    #22067

    Hi,

    thank you very much for your post. Yes, I also saw some posts on the PrettyFaces forums regarding this. So there really seems to be something wrong here.

    It would be absolutely fantastic to get an example application that reproduces this behavior. Could you perhaps upload the project somewhere or send it to me via email (christian (at) kaltepoth [dot] de)? It would be great if you could include a small textual description of what exactly doesn’t work and what would be the correct behavior.

    Thank you very much

    Christian

    #22068

    Tony Herstell
    Participant

    Hi Christian,

    Please email me a personal email for me to send you ‘stuff’.

    tony.herstell@gmail.com

    Thx.

    #22069

    Tony Herstell
    Participant

    Once you synch then the only thing you need to set up is the PU and the Database schema I guess.

    This is the simplest way of setting up the system with MySQL I have found and details the setup with MySQL and JBoss7:

    This is in the file persistence.xml under META-INF in the project…

    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
    http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

    <!-- JBoss7 JBoss7 JBoss7 JBoss7 JBoss7 JBoss7 JBoss7 JBoss7 JBoss7 JBoss7 JBoss7 JBoss7 JBoss7 JBoss7
    Download MySQLConnector (was mysql-connector-java-5.1.18.zip in my case)
    Add a new directory: modules/com/mysql/main
    put the MySQLConnector in the new directory: modules/com/mysql/main
    Create a new file in directory: modules/com/mysql/main called module.xml and add in this code:

    <?xml version="1.0" encoding="UTF-8"?>

    <module xmlns="urn:jboss:module:1.0" name="com.mysql">
    <resources>
    <resource-root path="mysql-connector-java-5.1.18-bin.jar"/>
    </resources>
    <dependencies>
    <module name="javax.api"/>
    </dependencies>
    </module>

    Edit the file in the existing directory : /standalone/configuration called standalone.xml and add in this code inside the <drivers> tags:

    <driver name="mysql" module="com.mysql"/>

    now add in this code inside the <datasource> tags:

    <datasource jndi-name="java:/datasources/entermyeventsDatasource" pool-name="my_pool" enabled="true" jta="true" use-java-context="true" use-ccm="true">
    <connection-url>
    jdbc:mysql://localhost:3306/entermyevents
    </connection-url>
    <driver>
    mysql
    </driver>
    <security>
    <user-name>
    entermyevents
    </user-name>
    <password>
    xxxxxxxxxxx
    </password>
    </security>
    <statement>
    <prepared-statement-cache-size>
    100
    </prepared-statement-cache-size>
    <share-prepared-statements/>
    </statement>
    </datasource>

    Run up server and look for something like:
    04:45:09,525 INFO [org.jboss.jpa] (MSC service thread 1-3) JBAS011402: Starting Persistence Unit Service 'entermyevents.war#entermyeventsDatasource'

    -->

    <persistence-unit name="entermyeventsDatasource">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:/datasources/entermyeventsDatasource</jta-data-source>
    <properties>
    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
    <property name="hibernate.hbm2ddl.auto" value="update" /> <!-- create-drop update -->
    <property name="hibernate.show_sql" value="true" />
    <property name="hibernate.format_sql" value="true" />
    <!-- These are the default for JBoss EJB3, but not for HEM: -->
    <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
    <property name="hibernate.transaction.manager_lookup_class"
    value="org.hibernate.transaction.JBossTransactionManagerLookup" />
    <property name="jboss.entity.manager.factory.jndi.name"
    value="java:/essistantEntityManagerFactories" />
    </properties>
    </persistence-unit>

    </persistence>

    I guess you probably don’t need this but just want to ensure I provide as much info as possible…

    Tony

    #22070

    Tony Herstell
    Participant

    Once you get the project and get it running.

    Go to “manage users” and then click [Done]

    You will get a stack trace as [Done] is trying to close a conversation that does not exist.

    04:53:21,799 INFO  [com.entermyevents.userManagement.UserManagementController] (http--127.0.0.1-8080-3) +++CONVERSATION END for conversation:null
    04:53:21,802 INFO [org.jboss.as.ejb3] (http--127.0.0.1-8080-3) JBAS014101: Failed to find {[0, 60, 48, -124, 1, -102, 72, 53, -100, -48, 98, 47, 55, -32, 14, -27]} in cache
    04:53:21,803 ERROR [org.jboss.ejb3.invocation] (http--127.0.0.1-8080-3) JBAS014134: EJB Invocation failed on component UserManagementController for method public java.lang.String com.entermyevents.userManagement.UserManagementController.finished(): javax.ejb.EJBException: org.jboss.weld.exceptions.IllegalStateException: WELD-000215 Attempt to call end() on a transient conversation
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:166) [jboss-as-ejb3-7.1.0.CR1b.jar:7.1.0.CR1b]

    You can see the Conversation was started in the logs.

    I can manually “fix” this by looking in the logs for the conversation starting log.info:

    04:49:51,576 INFO  [com.entermyevents.userManagement.UserManagementController] (http--127.0.0.1-8080-1) +++CONVERSATION START
    04:49:51,577 INFO [com.entermyevents.userManagement.UserManagementController] (http--127.0.0.1-8080-1) conversation:1

    and append onto the URL the test:

    ?cid=1

    and re-fresh the page.

    Now I can mess around on the page and all is well as the conversation is maintained… finally hitting [Done] will close the conversation without a stack trace.

    It seems that between CDI and PrettyFaces the initial

    ?cid=xxx

    is being stripped off.

    Hopefully it’s a simple fix to stop this being stripped.

    #22071

    Tony Herstell
    Participant

    There is a file (import.sql) in the classpath (/entermyevents/src/import.sql) that i use to pre-populate some data.

    This is not really important for this problem but if you do furkle about and try to add a new user you will find a problem in that the primary key has already been used up.

    This is a new “feature” of hibernate that didn’t used to happen in Seam 2 and is nothing to do with this problem.

    #22072

    Tony Herstell
    Participant

    Ah!

    Your email was in the original message.

    Tip: Don’t read emails at 0430!

    project on way…

    #22073

    Dear Tony,

    thanks for sharing this detailed information for your project. I’ll have a look at it as soon as possible. I think I’ll find some time tomorrow. I’ll let you know if I find anything that may cause this issue.

    Best regards

    Christian

    #22074

    Hey Tony,

    I haven’t looked at your app, but one of the issues with the CID is that you need to manually add it for some types of JSF navigation.

    There is code in PrettyFaces which is specifically designed to make sure that the CID, and other parameters added to redirect URLs, are preserved, but it sounds like there is something wrong with this.

    @Christian, want help?

    ~Lincoln

    #22075

    Tony Herstell
    Participant

    Hi Lincoln,

    It is passed round fine… As LONG is there to start with!

    If I land on a page with a conversation running then it simply is not added to the end of the URL to start with (or is stripped).

    I have a button mapped to an “init” method and I start the conversation in this method.. then I return via a PrettyFaces “rule”… I think this rule is not checking to see if there is a conversation for this page.

    What do you think.

    #22076

    Tony Herstell
    Participant

    To be very clear about this.

    The page has NOT been rendered before… the init method STARTS a conversation and then “launches” the very first render of the page.

    #22077

    Hey Tony,

    I just want to keep you informed that I’m working on this. I can reproduce the issue you are describing. It really weird. The problem is that I don’t know how Weld adds the cid parameter to the URL. It seems like the HttpServletResponse is not wrapped, so it is reasonable that the cid is not added as this is typically one in such a wrapper.

    We are first calling ExternalContext.getResponse().encodeRedirectUrl() and then ExternalContext.redirect().

    Christian

    #22078

    IMHO this class in Weld should be responsible for appending the cid parameter:

    https://github.com/weld/core/blob/master/impl/src/main/java/org/jboss/weld/servlet/ConversationPropagationFilter.java

    #22079

    BTW: Mojarra only calls HttpServletResponse.sendRedirect() in case of non-AJAX requests. For AJAX requests it adds some script to the response that performs the redirect using JavaScript. In this case the Weld filter won’t work. But as I wrote before is seems like this filter isn’t active in AS7 as the response isn’t wrapped.

    This is very difficult to debug.

    #22080

    Hey Christian,

    Take a look at the ExternalContextWrapperImpl that comes with JSF. I believe that is where teh CID is added. Either there or the NavigationHandlerImpl.

    I am trying to find time to look in to this issue :/ Hopefully later today.

    ~Lincoln

Viewing 15 posts - 1 through 15 (of 44 total)

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.