Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Referencing values from ValidationMessages.properties

  1. #1
    Member
    Join Date
    Sep 2011
    Posts
    63
    My Mood
    Confused
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Referencing values from ValidationMessages.properties

    I've got a ValidationMessages.properties file that I need to reference a value from a managed bean.

    This is the mb:

    public class ButtonBean implements Serializable {
     
        public void save(ActionEvent actionEvent) {
            addMessage(???????HOW DO I GET THIS VALUE FROM THE ValidationMessages.properties FILE???????);
        }
     
        public void update(ActionEvent actionEvent) {
            addMessage("Data updated");
        }
     
        public void delete(ActionEvent actionEvent) {
            addMessage("Data deleted");
        }
     
        public void addMessage(String summary) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, null);
            FacesContext.getCurrentInstance().addMessage(null, message);
        }
    }

    Getting the value in the JSF page is no probs but I can't figure out how to get it from inside the method. Anybody got any ideas?


  2. #2
    Member
    Join Date
    Sep 2011
    Posts
    63
    My Mood
    Confused
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Referencing values from ValidationMessages.properties

    Just to clarify I was trying to extract string from my resource bundle and insert it into the managed bean directly. The solution that I came up with is probably not the most elegant and any improvements would be very welcome.

    public static String getResourceBundleString(String resourceBundleName, String resourceBundleKey) throws MissingResourceException {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ResourceBundle bundle = facesContext.getApplication().getResourceBundle(facesContext, resourceBundleName);
        return bundle.getString(resourceBundleKey);
    }

    You can then reference the method with the name of your bundle as set in your faces-config.xml file and the name of the key for the specific string.

Similar Threads

  1. [SOLVED] Referencing to Method. Incompatible Types Error.
    By mwebb in forum Object Oriented Programming
    Replies: 12
    Last Post: February 5th, 2012, 03:50 PM
  2. [SOLVED] compare form values with database values
    By VaniRathna in forum Java Servlet
    Replies: 2
    Last Post: October 24th, 2011, 02:48 AM
  3. Character Values Inside of Number Values
    By bgroenks96 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 2nd, 2011, 08:27 PM
  4. my pointer's value is the same when referencing
    By jack_nutt in forum What's Wrong With My Code?
    Replies: 14
    Last Post: July 6th, 2011, 03:24 PM
  5. Excel Column Letter Referencing
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 21st, 2010, 03:47 PM