4 Replies Latest reply on Oct 20, 2008 4:39 AM by x490812

    How to resolve EL expressions in code?

      I wish to do something like the following:



      String fullAddress ="#{AVM_REQUEST_RESPONSE.respParsedHousenumber} #{AVM_REQUEST_RESPONSE.respParsedDirectionprefix} #{AVM_REQUEST_RESPONSE.respParsedStreetname} #{AVM_REQUEST_RESPONSE.respParsedStreetsuffix}  #{AVM_REQUEST_RESPONSE.respParsedDirectionsuffix} #{AVM_REQUEST_RESPONSE.respParsedAptorunit}";



      But when I do it it the EL variables are not resolved and I get the above string as the value of the variable. How do I resolve the variables in code?

        • 1. Re: How to resolve EL expressions in code?

          Try something like this


          String fullAddress = Interpolator.instance().interpolate("#
          {AVM_REQUEST_RESPONSE.respParsedHousenumber} 
          #{AVM_REQUEST_RESPONSE.respParsedDirectionprefix} 
          #{AVM_REQUEST_RESPONSE.respParsedStreetname} 
          #{AVM_REQUEST_RESPONSE.respParsedStreetsuffix}  
          #{AVM_REQUEST_RESPONSE.respParsedDirectionsuffix} 
          #{AVM_REQUEST_RESPONSE.respParsedAptorunit}");



          I've linebreaked to make it mor readable.

          • 2. Re: How to resolve EL expressions in code?

            Can you think of any reason why the interpolator would not work ??? I run it, and get no errors or exceptions, but the value returned is null string. What I found was that the first time I call interpolate,  the getters are not called. the next time I call it, they are called and I get the correct values; It works the second time... Is this a bug? here is the code



                      avmReqResp.setRespParsedHousenumber(hn);
                      avmReqResp.setRespParsedDirectionprefix(dp);
                      avmReqResp.setRespParsedStreetname(sn);
                      avmReqResp.setRespParsedStreetsuffix(ss);
                      avmReqResp.setRespParsedAptorunit(pa);
                      avmReqResp.setRespParsedDirectionsuffix(pd);
                      String fullAddress = hn + " " + dp + " " +  sn + " " + ss + " " + pd + " " + pa;
                      fullAddress = fullAddress.replaceAll("  *", " ").trim();
                      String fullAddress2 = Interpolator.instance().interpolate("#{AVM_REQUEST_RESPONSE.respParsedHousenumber} #{AVM_REQUEST_RESPONSE.respParsedDirectionprefix} #{AVM_REQUEST_RESPONSE.respParsedStreetname} #{AVM_REQUEST_RESPONSE.respParsedStreetsuffix} #{AVM_REQUEST_RESPONSE.respParsedDirectionsuffix} #{AVM_REQUEST_RESPONSE.respParsedAptorunit}");
            


            • 3. Re: How to resolve EL expressions in code?

              The AVMREQUESTRESPONSE must be in a context where the interpolator may find it.


              Do this to see how things work, and then modify your code to match it:


              java.util.Date date = new java.util.Date();
              org.jboss.seam.contexts.Contexts.getEventContext().set("myOwnDate",date);
              String s = Interpolator.instance().interpolate("#{myOwnDate.time}");
              
              



              s will be the same as date.getTime (as a string)


              Comprende? :-)

              • 4. Re: How to resolve EL expressions in code?

                Thanks you  so much - the problem was that I as assigning values to the object then trying to interpolate the object within the same function; Apperently, seam does not outject until the end of the function. I determined this by setting the object into scope then interpolating.
                Thanks again