11 Replies Latest reply on Feb 18, 2008 4:06 PM by danielc.roth

    EL-resolve bundle.getString for an object

      I have a resource bundle with some properties like:

      hello=Hi #{user.firstname}

      On an xhtml page this resolves beautifully to 'Hi Daniel'.

      Getting the string from the resource bundle  'bundle.getString("hellp")', will not resolve for the #{user.firstname}, which is not surprising at all.

      Is there any way I can do something like
      User user = getUser();
      ELResolver.resolve(bundle.getString("hello"),user,anotherObject)

      which resolves the el expressions, given some objects, the same way the xhtml is resolved.

      Thanks!
        • 1. Re: EL-resolve bundle.getString for an object

          2nd try, not using hashguard(replaced by $ below) or equals-sign(repl. by -) (forum bug?)


          I have a resource bundle with some properties like:


          hello-Hi ${user.firstname}


          On an xhtml page this resolves beautifully to 'Hi Daniel'.


          Getting the string from the resource bundle  'bundle.getString(hello)', will not resolve for the '${user.firstname}', which is not surprising at all.


          Is there any way I can do something like
          User user - getUser();
          ELResolver.resolve(bundle.getString(hello),user,anotherObject)


          which resolves the el expressions, given some objects, the same way the xhtml is resolved.


          Thanks!

          • 2. Re: EL-resolve bundle.getString for an object
            msystems

            Have you tried SeamResourceBundle.getBundle().getString(hello) ?

            • 3. Re: EL-resolve bundle.getString for an object
              christian.bauer

              Daniel Roth wrote on Feb 06, 2008 02:55 PM:

              2nd try, not using hashguard(replaced by $ below) or equals-sign(repl. by -) (forum bug?)



              I need to know why you did this - really, before we go live with the forum.



              • Did you see the Help button?

              • Did you use the Help and then not understand it?

              • Did you see the preview of what you typed?

              • Did you see the stop typing and the preview updates automatically message?



              Basically, we really need to know if all of this will be enough of if people need a mandatory preview step, or a bigger red HELP ME WITH FORMATTING button.


              Thanks


              • 4. Re: EL-resolve bundle.getString for an object

                Christian: I don't really think I looked for an 'help' button, rather I tried writing <code> and actually thought it was kind of strange there wasn't any 'insert-code'-buttons etc.


                I saw the preview and the 'invalid markup' to the left but since this forum have an url like alpha....:9999 I just discarded that as a bug... sorry :-) Maybe some quick hints to the right of the textarea? 'Markup help' instead of 'Help'?



                Kenneth: the 'bundle' object mentioned above is a SeamResourceBundle injected via


                @In(value = "org.jboss.seam.core.resourceBundle")
                private SeamResourceBundle bundle;




                • 5. Re: EL-resolve bundle.getString for an object
                  msystems

                  Okay... I can tell you it works for me - i.e. resolves the EL expressions.

                  • 6. Re: EL-resolve bundle.getString for an object

                    Could you please elaborate on how you achieve this. It the target object Outjected? I have something like this:


                    messages.properties


                    hello=hi #{user.username}



                    SomeAction.java


                    @Out 
                    User user;
                    @In(value = "org.jboss.seam.core.resourceBundle")
                    private SeamResourceBundle bundle;
                    private String email;
                    
                    public void sendForgotMyEmail() {
                       user = someDao.getUserByEmail(email);
                       String message = bundle.getString(hello)',
                       
                    }
                    


                    I omitted get/set email/user. So the problem, just guessing, is that the user is not outjected until the end of the request and cannot be resolved for immediately after being fetched.


                    That's why I'd like to sort of force the bundle to use some specific objects, or rewrite the flow of this particular page.




                    • 7. Re: EL-resolve bundle.getString for an object
                      msystems

                      Daniel Roth wrote on Feb 08, 2008 09:48 AM:


                      Could you please elaborate on how you achieve this. It the target object Outjected? I have something like this:

                      messages.properties

                      hello=hi #{user.username}



                      SomeAction.java

                      @Out 
                      User user;
                      @In(value = "org.jboss.seam.core.resourceBundle")
                      private SeamResourceBundle bundle;
                      private String email;
                      
                      public void sendForgotMyEmail() {
                         user = someDao.getUserByEmail(email);
                         String message = bundle.getString(hello)',
                         
                      }
                      


                      I omitted get/set email/user. So the problem, just guessing, is that the user is not outjected until the end of the request and cannot be resolved for immediately after being fetched.

                      That's why I'd like to sort of force the bundle to use some specific objects, or rewrite the flow of this particular page.






                      That's correctly - the object doesn't exist in the Context, because it's first outjected when sendForgotMyEmail() finish.


                      You must force an outjection:


                      public void sendForgotMyEmail() {
                         user = someDao.getUserByEmail(email);
                         Contexts.getConversationContext().set("user", user);
                         String message = bundle.getString(hello)',
                         
                      }
                      



                      BTW: getConversationContext() -> you can also use getEventContext(), getSessionContext() etc.

                      • 8. Re: EL-resolve bundle.getString for an object

                        That's what I needed!


                        Thanks, Mange tak!

                        • 9. Re: EL-resolve bundle.getString for an object

                          So now I'd really like to do this without Outjection, exactly the way it's done in the documentation for FacesMessages and Log:



                          @Logger
                              private Log log;
                          
                              public void doThat() {
                                  String fname = "Daniel";
                                  String lname = "Roth";
                                  log.debug("Hello World, my name is #0 #1", fname, lname);
                                  
                                  FacesMessages.instance().add("Hello World, my name is #0 #1.", fname, lname);
                              }



                          but instead of creating a log entry / faces message, get it back as a string



                          String resolved = someMethod("Hello World, my name is #0 #1.", fname, lname);


                          • 10. Re: EL-resolve bundle.getString for an object
                            gavin.king

                            You seem to be making this amazingly more complex than it should be. I don't precisely understand what you are trying to do, but I imagine something like:



                            @In("#{messages.hello}")
                            String helloMessage;



                            would work.


                            Or at worst:


                            @In ResourceBundle resourceBundle;
                            @In Interpolator interpolator;
                            
                            ...



                            • 11. Re: EL-resolve bundle.getString for an object

                              Ah, the interpolator does the trick, thanks!


                              The example above is a dummy one. The actual system is a process system where you can do (just about) anything you can do with jBPM.
                              But in this system, any user can add/modify/etc flows and what should happen in any task etc. Often a mail (defined by an administrator) is sent with text containing info about the particular task. Thats where 'Hi #manager, ... your #task.info is ready...'