Use message bundle in Java class with Seam

前端 未结 4 584
萌比男神i
萌比男神i 2020-12-17 06:31

I want to use my message bundle (messages_fr.properties) in a Java class with seam.

In a jsf file, all work fine like this:

#{msg.newCustom

相关标签:
4条回答
  • 2020-12-17 07:09

    I usually inject the resource bundle, or the resource into the class and use it from there. Example:

    @In("#{messages['name']}")
    private String name
    

    Or,

    @In
    private Map<String, String> messages;
    

    wich injects the resourceBundle as a Map. (make sure the it's named messages in this case).

    0 讨论(0)
  • 2020-12-17 07:14

    It's working with your solution:

    @In
    private Map<String, String> messages;
    

    Just place the messages.properties in WEB-INF/classes/

    0 讨论(0)
  • 2020-12-17 07:16

    String msg = org.jboss.seam.international.Messages.instance().get("key") worked for me!

    I had the same problem using an entity bean.

    0 讨论(0)
  • 2020-12-17 07:31

    There are a number of ways you can do it.

    StatusMessages.instance().addFromResourceBundle("msg.newCustomer);
    //This will add the msg.newCustomer message to the view
    
    String msg = org.jboss.seam.international.Messages.instance().get("msg.newCustomer);
    //This will put the msg.newCustomer message in variable msg
    
    0 讨论(0)
提交回复
热议问题