我希望能够从JSF 2托管bean内部的消息包中检索字符串.这可以在将字符串用作FacesMessage抛出异常中的消息中的摘要或详细信息参数的情况下完成.
我想确保托管bean为用户的语言环境加载正确的消息包.我不清楚如何使用JSF API调用从托管bean执行此操作.
我的配置是:
注意:我确实看到了类似的问题,但这取决于我的配置中不可用的功能
编辑:我在原来的问题上犯了一个错误.我想要问的是"如何从托管bean中获取资源包字符串"?BalusC给了我正确的答案.我实际要问的解决方案非常相似:
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);
}
此外,这里还有一个链接到另一个问题,解释了"消息"包和"资源"包之间的区别.
是否可以使用jsf消息包覆盖默认的omnifaces验证消息?
我的消息包:
javax.faces.converter.DateTimeConverter.DATE={2}: ''{0}'' could not be understood as a date.
javax.faces.converter.DateTimeConverter.DATE_detail=Invalid date format.
javax.faces.validator.LengthValidator.MINIMUM=Minimum length of ''{0}'' is required.
org.omnifaces.component.validator.ValidateUnique=1. my validateUnique omnifaces msg, {0}
org.omnifaces.component.validator.ValidateUnique.DEFAULT_MESSAGE=2. my validateUnique omnifaces msg, {0}
我知道有一个'消息'属性,但将所有消息放在一个地方会很好.
提前谢谢了
在创建线程时,如何设置线程的创建者读取消息?
我有这部分代码
$composer = $this->get('fos_message.composer');
    $message  = $composer->newThread()
        ->setSender($this->getUser())
        ->setSubject('myThread')
        ->setBody($request->get('createThread')['my_thread']);
    $sender = $this->get('fos_message.sender');
    $sender->send($message);
但是当我在最后一行发送消息时,在数据库中,当发送方应设置为1时,is_read的值设置为0.因此,我需要将发送者设置为在发送消息时读取.
任何人?:)
我希望能够在我的消息包密钥中包含空格,因为如果您不必将空格转换为下划线,则更容易将现有文本转换为键.
春天的消息来源似乎并不喜欢这样.可能吗?
2011-03-30 15:45:56,519 ERROR [org.springframework.web.servlet.tags.MessageTag] - No message found under code 'Invalid username or password' for locale 'en_US'.
javax.servlet.jsp.JspTagException: No message found under code 'Invalid username or password' for locale 'en_US'.
    at org.springframework.web.servlet.tags.MessageTag.doStartTagInternal(MessageTag.java:183)
我知道论坛中的很多帖子都讨论过这个问题,但是我仍然无法自定义bean验证的消息.也许配置或文件位置中缺少一些小东西......
验证调用消息时,网页显示消息ID而不是消息文本.
例如,我在网页上看到{messages.myMessageId}
我有:
SRC/COM/MyApp的/视图/ validationvalidation_en.poperties
webuser_name_notnull = Name is required
faces-config.xml中
<message-bundle>
        com.myapp.view.validation
</message-bundle>
webuser.java
@NotNull(message = "{webuser_name_notnull}")
private String name;
非常感谢您的支持!
jsf ×2
java ×1
jsf-2 ×1
managed-bean ×1
omnifaces ×1
php ×1
spring ×1
symfony ×1
validation ×1