1 Reply Latest reply on Jul 10, 2006 11:18 AM by Scott Huffman

    Need help with -ds.xml/datasource/Seam and Jndi

    Scott Huffman Newbie

      I've used struts in the past and have a new project that I'd like to do with Seam.

      I'm not incorporating hibernate due to my inexperience with it and want to know how to inject a DataSource that's defined in ??-ds.xml in the deploy directory. There are circumstances where I need to access data in multiple databases from the same application so I have more than one defined here.

      Assume I have the following defined in the ds.xml file

      <local-tx-datasource>
       <jndi-name>myDatasource</jndi-name>
       ....
      </local-tx-datasource>
      

      My pojo looks similar to this
      public class LoginAction implements Login {
      
       // What will get my datasource injected here?
       // I've tried countless variations.
       @In or @In(value="myDatasource") or ???
       private DataSource myDatasource;
      
       @In(create=true)
       private User user; // Session scope
      
       public LoginAction() { }
      
       public String challenge() {
       String rtn;
       if(!user.isAuthenticated()) {
       // authentication logic here/ query the database to check role/access
       // if not authenticated set rtn = "invalid"
       // otherwise store user role/access in user object in session scope
       // User object should reside in session scope for interrogation on next request.
       }
      
       return rtn;
       }
      }
      

      pages.xml looks like this to force authentication on every request
      <pages>
       <page view-id="*" action="#{loginAction.challenge}"/>
      </pages>
      

      What @In annotation will work here for myDatasource?

      I'm sure this is very simple but please, someone hold my hand. :-)