/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package smartplus; import com.sun.data.provider.impl.CachedRowSetDataProvider; import com.sun.rave.web.ui.appbase.AbstractPageBean; import com.sun.sql.rowset.CachedRowSetXImpl; import com.sun.webui.jsf.component.Button; import com.sun.webui.jsf.component.Calendar; import com.sun.webui.jsf.component.DropDown; import com.sun.webui.jsf.component.Hyperlink; import com.sun.webui.jsf.component.Label; import com.sun.webui.jsf.component.StaticText; import com.sun.webui.jsf.model.SingleSelectOptionsList; import javax.faces.FacesException; import javax.faces.convert.LongConverter; import bd.*; import java.util.Date; import org.hibernate.*; import java.sql.*; /** *
Page bean that corresponds to a similarly named JSP page. This * class contains component definitions (and initialization code) for * all components that you have defined on this page, as well as * lifecycle methods and event handlers where you may add behavior * to respond to incoming events.
* * @version ajout_cours.java * @version Created on 18 août 2010, 15:39:06 * @author RBT */ public class ajout_cours extends AbstractPageBean { //Automatically managed component initialization. WARNING: * This method is automatically generated, so any user-specified code inserted * here is subject to being replaced.
*/ private void _init() throws Exception { moduleDataProvider.setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{SessionBean1.moduleRowSet}")); moduleRowSet.setDataSourceName("java:comp/env/jdbc/smartplus_MySQL"); moduleRowSet.setCommand("SELECT * FROM module"); moduleRowSet.setTableName("module"); moduleDataProvider2.setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{ajout_cours.moduleRowSet}")); enseignantRowSet.setDataSourceName("java:comp/env/jdbc/smartplus_MySQL"); enseignantRowSet.setCommand("SELECT * FROM enseignant"); enseignantRowSet.setTableName("enseignant"); enseignantDataProvider1.setCachedRowSet((javax.sql.rowset.CachedRowSet) getValue("#{ajout_cours.enseignantRowSet}")); } private Button ok1 = new Button(); public Button getOk1() { return ok1; } public void setOk1(Button b) { this.ok1 = b; } private Button annuler1 = new Button(); public Button getAnnuler1() { return annuler1; } public void setAnnuler1(Button b) { this.annuler1 = b; } private Label bjr = new Label(); public Label getBjr() { return bjr; } public void setBjr(Label l) { this.bjr = l; } private StaticText log = new StaticText(); public StaticText getLog() { return log; } public void setLog(StaticText st) { this.log = st; } private Hyperlink dcnx = new Hyperlink(); public Hyperlink getDcnx() { return dcnx; } public void setDcnx(Hyperlink h) { this.dcnx = h; } private DropDown mod = new DropDown(); public DropDown getMod() { return mod; } public void setMod(DropDown dd) { this.mod = dd; } private CachedRowSetDataProvider moduleDataProvider = new CachedRowSetDataProvider(); public CachedRowSetDataProvider getModuleDataProvider() { return moduleDataProvider; } public void setModuleDataProvider(CachedRowSetDataProvider crsdp) { this.moduleDataProvider = crsdp; } private LongConverter modConverter = new LongConverter(); public LongConverter getModConverter() { return modConverter; } public void setModConverter(LongConverter lc) { this.modConverter = lc; } private CachedRowSetDataProvider moduleDataProvider1 = new CachedRowSetDataProvider(); public CachedRowSetDataProvider getModuleDataProvider1() { return moduleDataProvider1; } public void setModuleDataProvider1(CachedRowSetDataProvider crsdp) { this.moduleDataProvider1 = crsdp; } private CachedRowSetXImpl moduleRowSet = new CachedRowSetXImpl(); public CachedRowSetXImpl getModuleRowSet() { return moduleRowSet; } public void setModuleRowSet(CachedRowSetXImpl crsxi) { this.moduleRowSet = crsxi; } private CachedRowSetDataProvider moduleDataProvider2 = new CachedRowSetDataProvider(); public CachedRowSetDataProvider getModuleDataProvider2() { return moduleDataProvider2; } public void setModuleDataProvider2(CachedRowSetDataProvider crsdp) { this.moduleDataProvider2 = crsdp; } private DropDown module = new DropDown(); public DropDown getModule() { return module; } public void setModule(DropDown dd) { this.module = dd; } private Button annuler = new Button(); public Button getAnnuler() { return annuler; } public void setAnnuler(Button b) { this.annuler = b; } private Button ok = new Button(); public Button getOk() { return ok; } public void setOk(Button b) { this.ok = b; } private CachedRowSetDataProvider enseignantDataProvider = new CachedRowSetDataProvider(); public CachedRowSetDataProvider getEnseignantDataProvider() { return enseignantDataProvider; } public void setEnseignantDataProvider(CachedRowSetDataProvider crsdp) { this.enseignantDataProvider = crsdp; } private CachedRowSetXImpl enseignantRowSet = new CachedRowSetXImpl(); public CachedRowSetXImpl getEnseignantRowSet() { return enseignantRowSet; } public void setEnseignantRowSet(CachedRowSetXImpl crsxi) { this.enseignantRowSet = crsxi; } private CachedRowSetDataProvider enseignantDataProvider1 = new CachedRowSetDataProvider(); public CachedRowSetDataProvider getEnseignantDataProvider1() { return enseignantDataProvider1; } public void setEnseignantDataProvider1(CachedRowSetDataProvider crsdp) { this.enseignantDataProvider1 = crsdp; } private DropDown ens = new DropDown(); public DropDown getEns() { return ens; } public void setEns(DropDown dd) { this.ens = dd; } private Calendar date = new Calendar(); public Calendar getDate() { return date; } public void setDate(Calendar c) { this.date = c; } private LongConverter moduleConverter = new LongConverter(); public LongConverter getModuleConverter() { return moduleConverter; } public void setModuleConverter(LongConverter lc) { this.moduleConverter = lc; } private LongConverter ensConverter = new LongConverter(); public LongConverter getEnsConverter() { return ensConverter; } public void setEnsConverter(LongConverter lc) { this.ensConverter = lc; } //Construct a new Page bean instance.
*/ public ajout_cours() { } /** *Callback method that is called whenever a page is navigated to, * either directly via a URL, or indirectly via page navigation. * Customize this method to acquire resources that will be needed * for event handlers and lifecycle methods, whether or not this * page is performing post back processing.
* *Note that, if the current request is a postback, the property * values of the components do not represent any * values submitted with this request. Instead, they represent the * property values that were saved for this view when it was rendered.
*/ @Override public void init() { // Perform initializations inherited from our superclass super.init(); // Perform application initialization that must complete // *before* managed components are initialized // TODO - add your own initialiation code here //Callback method that is called after the component tree has been * restored, but before any event processing takes place. This method * will only be called on a postback request that * is processing a form submit. Customize this method to allocate * resources that will be required in your event handlers.
*/ @Override public void preprocess() { } /** *Callback method that is called just before rendering takes place. * This method will only be called for the page that * will actually be rendered (and not, for example, on a page that * handled a postback and then navigated to a different page). Customize * this method to allocate resources that will be required for rendering * this page.
*/ @Override public void prerender() { String l=this.getApplicationBean1().getlogin(); log.setText(l); /* if(l.equals("")){ module.setDisabled(true); ens.setDisabled(true); ok.setDisabled(true); annuler.setDisabled(true); this.dcnx.setVisible(false); this.log.setText("vous n'êtes pas connecté"); bjr.setVisible(false); }*/ } /** *Callback method that is called after rendering is completed for
* this request, if init()
was called (regardless of whether
* or not this was the page that was actually rendered). Customize this
* method to release resources acquired in the init()
,
* preprocess()
, or prerender()
methods (or
* acquired during execution of an event handler).
Return a reference to the scoped data bean.
* * @return reference to the scoped data bean */ protected ApplicationBean1 getApplicationBean1() { return (ApplicationBean1) getBean("ApplicationBean1"); } /** *Return a reference to the scoped data bean.
* * @return reference to the scoped data bean */ protected SessionBean1 getSessionBean1() { return (SessionBean1) getBean("SessionBean1"); } /** *Return a reference to the scoped data bean.
* * @return reference to the scoped data bean */ protected RequestBean1 getRequestBean1() { return (RequestBean1) getBean("RequestBean1"); } public String dcnx_action() { // TODO: Process the action. Return value is a navigation // case name where null will return to the same page. getApplicationBean1().setlogin(""); return null; } public String ok_action() { // TODO: Replace with your code /* try { String m=module.getValue().toString(); Module mod=new Module(m, null, null, null); String nmp=ens.getValue().toString(); Enseignant en=new Enseignant(null, null, null, null, null, null, null, null, nmp, null, null, null, null); Formation f= new Formation(); f=this.getApplicationBean1().getform(); //String t=f.getTypeF(); if(f.equals(null)){ log.setText("null"); } else{ int i=f.getFormationId(); /*int t=f.getTarif(); String d=f.getDescription(); Formation form=new Formation("cours_acc", t, d, null, null, null, null, null); Session sess = null; sess = HibernateUtil.currentSession(); Transaction tx = sess.beginTransaction(); CoursAcc ca=new CoursAcc(); ca.setEnseignant(en); ca.setFormation(form); ca.setModule(mod); sess.save(ca); sess.save(f); tx.commit(); this.getApplicationBean1().setform(null);}} catch(Exception e){ System.out.println(e.getMessage()); }*/ try { int enid=ens.getValue().hashCode(); int mid=module.getValue().hashCode(); Formation f= new Formation(); f=this.getApplicationBean1().getform(); int fid=f.getFormationId(); /* Create string of connection url within specified format with machine name, port number and database name. Here machine name id localhost and database name is student. */ String connectionURL = "jdbc:mysql://localhost:3306/smartplus"; // declare a connection by using Connection interface Connection connection = null; /* declare object of Statement interface that is used for executing sql statements. */ Statement statement = null; // declare a resultset that uses as a table for output data from tha table. ResultSet rs = null; // Load JBBC driver "com.mysql.jdbc.Driver" Class.forName("com.mysql.jdbc.Driver").newInstance(); /* Create a connection by using getConnection() method that takes parameters of string type connection url, user name and password to connect to database.*/ connection = DriverManager.getConnection(connectionURL, "root", "smart"); /* createStatement() is used for create statement object that is used for sending sql statements to the specified database. */ statement = connection.createStatement(); // sql query to retrieve values from the secified table. String QueryString = "insert into cours_acc (enseignant_id, module_id, formation_id) values ('1', '2', '1')"; int nb=statement.executeUpdate(QueryString); rs.close(); statement.close(); connection.close(); } catch(Exception e){ System.out.println(e.getMessage()); } return null; } public String annuler_action() { // TODO: Replace with your code return null; } }