Announcement Announcement Module
Collapse
No announcement yet.
how to get labels in my velocity template for Email from properties file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to get labels in my velocity template for Email from properties file

    Hi
    i m using velocity template from Email sending.
    For static labels i wants to do internationalization.
    But how sud i get that "Key" "value" pair from ApplicationResources.properties
    file.
    i have set my properties file reference in Model object in serviceImpl...

    But how sud i get it....

    $Modelkey.properties file key ........Is It ???
    Is this the way ??

  • #2
    might help

    I remember using velocity and passing a resourceBundle messages into the Model, as well a Foo object foo
    Code:
    ${messages.getString(${foo.displayKey})}

    Comment


    • #3
      Hi
      Thanks for your reply...
      but certain things are not clear to me like :
      "messages.getString" is fixed format to get any Key from Bundle??
      Any below is my code that I am using to send data to velocity Template:-

      HTML Code:
      Map<String, Object> model = new HashMap<String, Object>();
      		model.put("reservation", reservation);
      		model.put("price", StringUtil.getEuroFromEuroCents(reservation
      				.getPrice()));
      		model.put("voucher", voucherNumber);
      		model.put("reservationNumber", RandomNumberGenerator
      				.formatNumberWithSeperator(reservation.getReservationNumber()
      						.toString(), '#'));
      		model.put("messagesource", this.messagesource);
      here message resource is my properties file object.It has got all key value pairs.

      Below is my code for Velocity template

      HTML Code:
      Dear Customer,
      		This is from my email id.
      		
              This is a confirmation message for your request for canceling reservation.
      
              Your Reservation: ${reservationNumber} from date: ${reservation.startDate} to date: ${reservation.endDate}
      
              for Hotel : ${reservation.hotel.name}, ${reservation.hotel.streetAddress}, ${reservation.hotel.city.nameLabel}, ${reservation.hotel.areaCode}
      
              which was requested on date ${reservation.createdDate}
      
              has been canceled successfully.
      
              The amount ${price} Euro has been refunded in form of voucher and your voucher number is: ${voucher}
      
              Regards,
      Now her "Dear Customer" Key is there in properties file ....

      Now my question is how sud i replace it ????

      is it like $messagesource.Hellocustomer ???I m not sure

      Comment


      • #4
        maybe this helps

        assuming that messageSource the one is from the package org.springframework.context the API suggests
        Code:
        ${messageSource.getMessage($keyHelloCustomer, $noArgs, $locale)}
        where in your Model the following keys are:
        • keyHelloCustomer= the key inside your properties file
        • noArgs = new Object[]{}
        • locale = the locale to use

        Comment


        • #5
          Hi
          thanks for reply....
          But i m confused whether i can use

          HTML Code:
          ${messageSource.getMessage($keyHelloCustomer, $noArgs, $locale)}
          in my .Vm file ???

          Are u sure that i can use this to get labels from properties file ...??
          an what if i am not passing locale information??
          shall i write null there ??
          like

          HTML Code:
          ${messageSource.getMessage($keyHelloCustomer, null, null)}
          I m confused ???

          Comment


          • #6
            Add the vars to your model, as suggested in an earlier post

            PHP Code:
            Map<StringObjectmodel = new HashMap<StringObject>();
            model.put("reservation"reservation);
            model.put("price"StringUtil.getEuroFromEuroCents(reservation.getPrice()));
            model.put("voucher"voucherNumber);
            model.put("reservationNumber"RandomNumberGenerator.formatNumberWithSeperator(reservation.getReservationNumber().toString(), '#'));
            model.put("messagesource"this.messagesource);

            // adding this e.g. should do the trick
            model.put("keyHelloCustomer""the_key_you_use_in_your_properties_file");
            model.put("noArgs", new Object[]{});
            model.put("locale"yourOwnPrivateMethodToDetermineWhichLocaleToUse()); 
            just try it out, this might help removing your confusion.
            (of course you will have to implement yourOwnPrivateMethodToDetermineWhichLocaleToUse() or fill in a constant value like Locale.EN)

            Comment


            • #7
              thanks it worked

              Comment


              • #8
                I am using the solution mentioned above, but i am getting an exception
                No message found under code 'null' for locale 'ar' , although i am sending the key like:
                model.put("my.key", "my.key");

                any ideas ?
                Last edited by sword101; Dec 2nd, 2010, 05:01 AM.

                Comment


                • #9
                  Solved by :
                  model.put("myKey", "my.key");
                  ${messageSource.getMessage($myKey, $noArgs, $locale)}

                  Comment


                  • #10
                    i have another problem is that when changing the locale to fr, and i have a property file called message_fr the message appear ????????????, i don't know why ?

                    Comment

                    Working...
                    X