Advertisement
Guest User

Untitled

a guest
Mar 15th, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.69 KB | None | 0 0
  1. <?xml version='1.0' encoding='UTF-8' ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
  4. xmlns:h="http://java.sun.com/jsf/html"
  5. xmlns:f="http://java.sun.com/jsf/core"
  6. xmlns:ui="http://java.sun.com/jsf/facelets">
  7. <h:head>
  8. <ui:insert name="header">
  9. <ui:include src="header.xhtml"/>
  10. </ui:insert>
  11. </h:head>
  12. <h:body>
  13.  
  14. <h1><img src="resources/css/images/icon.png" alt="NVIDIA.com" /> Settings Center</h1>
  15. <!-- layer for black background of the buttons -->
  16. <div id="toolbar" style="margin: 0 auto; width:1180px; height:30px; position:relative; background-color:black">
  17. <!-- Include page Navigation -->
  18. <ui:insert name="Navigation">
  19. <ui:include src="Navigation.xhtml"/>
  20. </ui:insert>
  21.  
  22. </div>
  23.  
  24. <div id="greenBand" class="ui-state-default ui-corner-allh" style="position:relative; top:35px; left:0px;">
  25. <h:graphicImage alt="Application Settings" style="position:relative; top:-20px; left:9px;" value="resources/images/logo_application_settings.png" />
  26. </div>
  27. <div id="main" style="margin: 0 auto; width:1190px; height:700px; position:absolute; background-color:transparent; top:105px">
  28.  
  29. <div id="mainpage" style="margin: 0 auto; width:1190px; height:500px; position:absolute; background-color:transparent; top:80px">
  30.  
  31. <div id="settingsdiv" style="width:350px; height:400px; position:absolute; background-color:r; top:20px; left:1px">
  32. <h:panelGrid columns="2">
  33. <h:panelGroup>User Session Timeout</h:panelGroup>
  34. <h:panelGroup>
  35. <h:selectOneMenu value="#{ApplicationController.session}">
  36. <f:selectItem itemValue="one" itemLabel="Option one" />
  37. <f:selectItem itemValue="two" itemLabel="Option two" />
  38. <f:selectItem itemValue="three" itemLabel="Option three" />
  39. <f:selectItem itemValue="custom" itemLabel="Define custom value" />
  40. <f:ajax render="input" />
  41. </h:selectOneMenu>
  42. <h:panelGroup id="input">
  43. <h:inputText value="#{ApplicationController.session}" rendered="#{ApplicationController.session == 'custom'}" required="true" />
  44. </h:panelGroup>
  45.  
  46. </h:panelGroup>
  47.  
  48. <h:panelGroup>Maximum allowed users</h:panelGroup>
  49. <h:panelGroup>#{ApplicationController.settingValue('MaxUsersActive')}</h:panelGroup>
  50. </h:panelGrid>
  51. <h:commandButton value="Submit" action="#{bean.submit}"/>
  52.  
  53.  
  54. </div>
  55.  
  56. <div id="settingsdiv" style="width:350px; height:400px; position:absolute; background-color:transparent; top:20px; left:400px">
  57.  
  58.  
  59.  
  60. </div>
  61.  
  62. <div id="settingsdiv" style="width:350px; height:400px; position:absolute; background-color:transparent; top:20px; left:800px">
  63.  
  64.  
  65. </div>
  66.  
  67.  
  68.  
  69. </div>
  70. </div>
  71.  
  72. </h:body>
  73. </html>
  74.  
  75.  
  76.  
  77. //// the code of the bean
  78.  
  79.  
  80. import java.io.Serializable;
  81. import javax.enterprise.context.SessionScoped;
  82. // or import javax.faces.bean.SessionScoped;
  83. import javax.inject.Named;
  84. /* include SQL Packages */
  85. import java.sql.Connection;
  86. import java.sql.PreparedStatement;
  87. import java.sql.ResultSet;
  88. import java.sql.SQLException;
  89. import java.util.HashMap;
  90. import javax.annotation.PostConstruct;
  91. import javax.sql.DataSource;
  92. import javax.annotation.Resource;
  93. import javax.faces.context.FacesContext;
  94. import javax.inject.Inject;
  95. import javax.servlet.http.HttpServletRequest;
  96. import javax.servlet.http.HttpSession;
  97. // or import javax.faces.bean.ManagedBean;
  98.  
  99. import org.glassfish.osgicdi.OSGiService;
  100.  
  101. @Named("ApplicationController")
  102. @SessionScoped
  103. public class Application implements Serializable {
  104.  
  105. /* This Hash Map will be used to store setting and value */
  106. private HashMap<String, String> settingsMap = null;
  107.  
  108. public Application(){
  109. }
  110.  
  111. /* Call the Oracle JDBC Connection driver */
  112. @Resource(name = "jdbc/Oracle")
  113. private DataSource ds;
  114.  
  115. private String session = "six";
  116.  
  117. public String getsession() {
  118. return session;
  119. }
  120.  
  121. public void setsession(String session) {
  122. this.session = session;
  123. }
  124.  
  125.  
  126. /* Get setting value using key */
  127. public String settingValue(String key)
  128. {
  129. try
  130. {
  131. return (String) settingsMap.get(key);
  132.  
  133. }
  134. catch(Exception x) { return "error - " + x.getMessage(); }
  135.  
  136. }
  137.  
  138. /* Hash Map declaration */
  139. public HashMap<String, String> getSetting(String key)
  140. {
  141. return settingsMap;
  142. }
  143.  
  144. /* Get a Hash Map with settings and values. The table is genarated right
  145. * after the constructor is initialized.
  146. */
  147. @PostConstruct
  148. public void initSettings() throws SQLException
  149. {
  150. settingsMap = new HashMap<String, String>();
  151.  
  152. if(ds == null) {
  153. throw new SQLException("Can't get data source");
  154. }
  155. /* Initialize a connection to Oracle */
  156. Connection conn = ds.getConnection();
  157.  
  158. if(conn == null) {
  159. throw new SQLException("Can't get database connection");
  160. }
  161. /* With SQL statement get all settings and values */
  162. PreparedStatement ps = conn.prepareStatement("SELECT * from GLOBALSETTINGS");
  163.  
  164. try
  165. {
  166. //get data from database
  167. ResultSet result = ps.executeQuery();
  168. while (result.next())
  169. {
  170. settingsMap.put(result.getString("SettingName"), result.getString("SettingValue"));
  171. }
  172. }
  173. finally
  174. {
  175. ps.close();
  176. conn.close();
  177. }
  178. }
  179.  
  180.  
  181. public void SettingsDBUpdate(){
  182.  
  183.  
  184. }
  185.  
  186.  
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement