1

我想知道在 JSF 中定义EntityManagerTypedQuery在应该从数据库中读取消息的捆绑类中是否有效?如果我创建一个@Statelessbean 的实例并使用它在 bundle 类中返回查询结果的函数会怎样?

更新:包括一些代码:

protected class DBControl extends Control{
@Override
public ResourceBundle newBundle
        (String baseName, Locale locale, String format, ClassLoader loader, boolean reload)
        throws IllegalAccessException, InstantiationException, IOException
{            
    return new ArticleResources(locale);
}       

protected class ArticleResources extends ListResourceBundle{
    private Locale locale;

    public ArticleResources (Locale locale){
        this.locale = locale;
    }            
    String language = locale.getLanguage();

    @Override
    protected Object[][] getContents(){                  
        TypedQuery<ArticleLcl> query = em.createNamedQuery("ArticleLcl.findForLocale", ArticleLcl.class);
        query.setParameter("lang", language);
        List<ArticleLcl> articles = query.getResultList();
        Object[][] allArticles = new Object[articles.size()][3];                
        int i = 0;
        for(Iterator<ArticleLcl> it = articles.iterator(); it.hasNext();){
            ArticleLcl article = it.next();
            allArticles[i] = new Object[]{article.getArticleId().getArticleId().toString(),article.getArticleTitle()};
            messages.put(article.getArticleId().getArticleId().toString(),article.getArticleTitle());                    
            i++;
        }
        return allArticles;
    }            
}

顺便说一句,这段代码不起作用,我的实体管理器为空。但我想知道我在做正确的事吗?

4

0 回答 0