9 Replies Latest reply on Jun 13, 2013 9:11 AM by William Lovett

    Expression Language (EL) Entity Lookup Mystery

    William Lovett Newbie

      Ladies and Gents,

       

      Using EAP 6.1, which I beleive is equivalent to AS 7.2.0.  I'm converting a project from Weblogic to JBoss and am having an interesting time using Expression Language (EL).

       

      The html page looks like so.  Of subject is the #{Dashboard.lastReviewText} line.

       <tr:table value="#{ValueHolder.projectUsers}" var="userProject">
            <tr:column id="c10">
                <tr:panelHorizontalLayout inlineStyle="#{userProject.project.lastReviewStyle}">
                     <tr:outputText value="#{Dashboard.lastReviewText}"/>
                </tr:panelHorizontalLayout>
              </tr:column>
      </tr:table>
      

       

      The problem is that I am trying to access the table's var "userProject" in a backing bean.  To do this, weblogic accepts the following:

       

      Dashboard.java backing bean

       public String getLastReviewText() {
           Project project = (Project)EL.get("#{userProject.project}"); // there are quotes in that get("...").  They're being erased somehow in the forum
           String text = project.getLastReviewText();
           return text + " success";
      }
      

       

      The problem is that JBoss returns null for the Project project = ... line.  It doesn't see the EL expression.  To retrieve anything, I have to say #{requestScope.userProject}.  Oddly enough, #{requestScope.userProject.project} returns a null.  It's like JBoss does not see the relationship between userProject and userProject.project.

       

      However , you can see in the table, that inlineStyle="#{userProject.project.lastReviewStyle}" works just fine.  Does the variable "lose scope" so to speak when the code moves to the backing bean?  Is this something I need to setup in my persistence.xml?  Is it just a JBoss limitation that I'm going to have to code around? 

       

      I'm stumped.  Any ideas?

       

      Thanks in advance,

      Will

        • 1. Re: Expression Language (EL) Entity Lookup Mystery
          Nicklas Karlsson Master

          I think userProject only exists as a temporary variable for the lifetime of that components rendering.

          • 2. Re: Expression Language (EL) Entity Lookup Mystery
            William Lovett Newbie

            Nicklas, thank you for your reply.

             

            If that is true, I am getting the variable while the component is being rendered.

             

            In other words, let's say I put another column in the table.

             

            <tr:table value="#{ValueHolder.projectUsers}" var="userProject">
                  <tr:column id="c10">
                      <tr:panelHorizontalLayout inlineStyle="#{userProject.project.lastReviewStyle}">
                           <tr:outputText value="#{Dashboard.lastReviewText}"/>
                      </tr:panelHorizontalLayout>
                    </tr:column>

                  <tr:column id="c2">

                      <tr:panelHorizontalLayout inlineStyle="#{userProject.project.someMoreInfoStyle}">

                           <tr:outputText value="#{Dashboard.someMoreText}"/>

                      </tr:panelHorizontalLayout>

                    </tr:column>

            </tr:table>

             

            When "#{Dashboard.lastReviewText}" is called, the variable should still be "alive" so to speak because the component is not yet finished rendering, but it is not.  I should note that this EL expression / backing bean combo works fine in Weblogic.

            • 3. Re: Expression Language (EL) Entity Lookup Mystery
              Nicklas Karlsson Master

              One would think so, if the EL context is the same. It could of course be an EL implementation issue. Are they CDI or JSF managed beans?

              • 4. Re: Expression Language (EL) Entity Lookup Mystery
                William Lovett Newbie

                They are JSF managed beans.  I'm thinking it's an EL implementation issue.  Some other people are working on a different way of porting the program over (with their own problems), but this isn't one of them.  They can get #{userProject.project} to work in a backing bean.

                 

                At any rate, I've come across a stumbling block with ADF skinning.  Turns out 10g implements this much differently than 11, and there's no good way to merge the two using JSF 2+.  So I'm trying to implement JSF 1.1 instead so I can pull in the 10g skinning.  We'll see if the skinning issue is fixed that way.

                • 5. Re: Expression Language (EL) Entity Lookup Mystery
                  William Lovett Newbie

                  Well, slight progress, but I'm basically back at square one.  I've implemented the 10g tags and am using <web-app version="2.4"> in my web.xml so my program looks correct now.  I'm also able to get #{userProject} in a backing bean (yay!), but I'm not able to get #{userProject.project}.  That returns null.  Here's the code:

                   

                  Projectuser pu = (Projectuser) EL.get("#{userProject}");

                  Project project = pu.getProject();   // returns null;

                  String color = project.getLastReviewColor();  // causes a NPE

                   

                  Is this something that needs to be configured in my persistence.xml?

                   

                  It does not matter whether I bundle JSF 1.1 with my WAR or if I let the default Mojarra JSF run.  It get the same error either way.

                   

                  Any ideas?  I'm open to just about any of them.

                   

                  ** Edit: **

                   

                  Changing the fetch type to "fetch=FetchType.EAGER" in my ProjectUser entity does not help

                  • 6. Re: Expression Language (EL) Entity Lookup Mystery
                    William Lovett Newbie

                    It appears that querying ProjectUsers does not return a reference to the Project table.

                     

                    In my backing bean, I have a beforePhase(PhaseEvent event) function.  This function queries the ProjectUser entity and populates a List which is used by the .jspx's table.  It appears the items returned from this query do not contain references to Project entities for some reason.

                     

                    Why?  My code in the ProjectUser entity is like so

                     

                    @ManyToOne(fetch=FetchType.LAZY)

                    @JoinColumn(name = "PROJECT_ID", referencedColumnName = "PROJECT_ID")

                    private Project project;

                     

                    Is this something I need to explicity set in my persistence.xml?  Right now I only list the class names and eclipselink targer-server and target-database.

                     

                    <provider>org.eclipse.persistence.jap.PersistenceProvider</provider>

                    <jta-data-source> ... </...>

                         <class>com.sample.ProjectUser</class>

                         <class>com.sample.Project</class>

                         <properties>

                              <property name="eclipselink.targer-server" value="JBoss"/>

                               ...

                    • 7. Re: Expression Language (EL) Entity Lookup Mystery
                      Stephen Coy Master

                      The ProjectUser query that populates the List should "join fetch" any related objects that it is expecting to use while rendering.

                      • 8. Re: Expression Language (EL) Entity Lookup Mystery
                        Nicklas Karlsson Master

                        So #{userProject} is the EL-reference in the iteration that points to a UserProject and userProject.project.lasReviewStyle can be used in the dataTable but not when accessed from backing bean code? What is the true class (some proxy?) of the UserProject you get from backing bean access? If stuff works in the dataTable, the JPA relations must be set up OK, right?

                        • 9. Re: Expression Language (EL) Entity Lookup Mystery
                          William Lovett Newbie

                          Guys, thanks for both of your replies.

                           

                          Turns out the (test) database's foreign keys are messed up.  I'm not quite sure how THAT happened, but I did some manual changes and can pull back records no problem now.

                           

                          I was starting to go bonkers there.  Thanks again for the help.  Both of you have replied on a number of my posts and I really appreciate it.