[jboss-user] [JBoss Seam] - Re: Seam 1.1 beta1&2 (dis?)injecting issue

pbrewer_uk do-not-reply at jboss.com
Mon Nov 13 13:53:15 EST 2006


Thanks for the prompt response. Perhaps what I'm doing is a little unusual. I've created a simple way to update resource bundle messages that is intended to be a stop-gap until java 6 sorts out ResourceBundles.

My application also has a login component that takes a username and password. But the username textbox is pre-populated with a prompt for a user name, and it gets that from the reloadable resource.

So when the loginAction is created, it needs to access/ create the reloadable resource. See the code extracts below.

I'll checkout cvs head and give it a go. Did you still want a test-case for this issue? Let me know if you need any more info.

Cheers, Pete.

LoginAction.java extract:

  | @Stateful
  | @Scope(CONVERSATION)
  | @Name ( "login" )
  | @TransactionAttribute(NOT_SUPPORTED)
  | @Intercept(ALWAYS)
  | public class LoginAction implements Login, Serializable {
  | 
  |   private static final long serialVersionUID = -3794420136503008665L;
  | 
  |   private static final Logger LOG = Logger.getLogger( LoginAction.class );
  | 
  |   public static final String LOGIN_USER_KEY = "loggedInUser";
  |   public static final String LOGIN_USER_ID_KEY = "loggedInUserId";
  | 
  |   @PersistenceContext(type=EXTENDED)
  |   private EntityManager em;
  | 
  |   @In(create=true, required=false, value=LOGIN_USER_KEY)
  |   private User loggedInUser ;
  | 
  |   @In (create=true)
  |   private Context sessionContext;
  | 
  |   @In(create = true)
  |   private transient FacesMessages facesMessages;
  | 
  |   @In ( create = true )
  |   private Actor actor;
  | 
  |   private String username ;
  |   private String password ;
  |   private String newPassword = "" ;
  |   private String repeatPassword ="" ;
  | 
  |   public LoginAction() {
  |     resetInfo() ;
  |   }
  |   
  |   private void resetInfo() {
  |     // default to the username prompt...
  |     setUserName( Utils.getBundleMessage("username") );
  |     setPassword( "" );    
  |     setNewPassword("") ;
  |     setRepeatPassword("") ;
  |   }
  |   ...
  | 
Utils.java extract:

  | ...
  |   public static String getBundleMessage(String messageId) {
  | 
  |     FacesContext facesContext = FacesContext.getCurrentInstance();
  |     String bundleName = facesContext.getApplication().getMessageBundle();
  |     Locale locale = facesContext.getViewRoot().getLocale();
  | 
  |     String message = "?" + messageId + "?";
  |     if ( bundleName != null ) {
  |       try {
  |         message = getResourceBundle(bundleName, locale).getProperty(messageId) ;
  | 
  |         if ( params != null ) {
  |           MessageFormat mf = new MessageFormat( message, locale );
  |           message = mf.format( params ).toString();
  |         }
  | 
  |       } catch (MissingResourceException e ) {
  |         LOG.debug("Cannot find message for bundle " + bundleName + " message Id = " + messageId);
  |       }
  |     }
  |     return message;
  |   }
  | 
  |   public static Properties getResourceBundle(String bundleName, Locale locale) {
  |     return ReloadableResource.instance().getResourceBundle(bundleName, locale) ;
  |   }
  | ...
  | 

ReloadableResource.java extract:

  | ...
  |   public static ReloadableResource instance() {
  |     if (Contexts.isSessionContextActive()) {
  |       return (ReloadableResource) Component.getInstance( "reloadableResource", true ) ;
  |     } else {
  |       LOG.debug("ResourceBundle is being accessed outside of web context.") ;
  |       return new ReloadableResource() ;
  |     }
  |   }  
  | ...
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3985575#3985575

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3985575



More information about the jboss-user mailing list