Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version='1.0' encoding='UTF-8' ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
- xmlns:h="http://java.sun.com/jsf/html"
- xmlns:f="http://java.sun.com/jsf/core"
- xmlns:ui="http://java.sun.com/jsf/facelets">
- <h:head>
- <ui:insert name="header">
- <ui:include src="header.xhtml"/>
- </ui:insert>
- </h:head>
- <h:body>
- <h1><img src="resources/css/images/icon.png" alt="NVIDIA.com" /> Settings Center</h1>
- <!-- layer for black background of the buttons -->
- <div id="toolbar" style="margin: 0 auto; width:1180px; height:30px; position:relative; background-color:black">
- <!-- Include page Navigation -->
- <ui:insert name="Navigation">
- <ui:include src="Navigation.xhtml"/>
- </ui:insert>
- </div>
- <div id="greenBand" class="ui-state-default ui-corner-allh" style="position:relative; top:35px; left:0px;">
- <h:graphicImage alt="Application Settings" style="position:relative; top:-20px; left:9px;" value="resources/images/logo_application_settings.png" />
- </div>
- <div id="main" style="margin: 0 auto; width:1190px; height:700px; position:absolute; background-color:transparent; top:105px">
- <div id="mainpage" style="margin: 0 auto; width:1190px; height:500px; position:absolute; background-color:transparent; top:80px">
- <div id="settingsdiv" style="width:350px; height:400px; position:absolute; background-color:r; top:20px; left:1px">
- <h:panelGrid columns="2">
- <h:panelGroup>User Session Timeout</h:panelGroup>
- <h:panelGroup>
- <h:selectOneMenu value="#{ApplicationController.session}">
- <f:selectItem itemValue="one" itemLabel="Option one" />
- <f:selectItem itemValue="two" itemLabel="Option two" />
- <f:selectItem itemValue="three" itemLabel="Option three" />
- <f:selectItem itemValue="custom" itemLabel="Define custom value" />
- <f:ajax render="input" />
- </h:selectOneMenu>
- <h:panelGroup id="input">
- <h:inputText value="#{ApplicationController.session}" rendered="#{ApplicationController.session == 'custom'}" required="true" />
- </h:panelGroup>
- </h:panelGroup>
- <h:panelGroup>Maximum allowed users</h:panelGroup>
- <h:panelGroup>#{ApplicationController.settingValue('MaxUsersActive')}</h:panelGroup>
- </h:panelGrid>
- <h:commandButton value="Submit" action="#{bean.submit}"/>
- </div>
- <div id="settingsdiv" style="width:350px; height:400px; position:absolute; background-color:transparent; top:20px; left:400px">
- </div>
- <div id="settingsdiv" style="width:350px; height:400px; position:absolute; background-color:transparent; top:20px; left:800px">
- </div>
- </div>
- </div>
- </h:body>
- </html>
- //// the code of the bean
- import java.io.Serializable;
- import javax.enterprise.context.SessionScoped;
- // or import javax.faces.bean.SessionScoped;
- import javax.inject.Named;
- /* include SQL Packages */
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.HashMap;
- import javax.annotation.PostConstruct;
- import javax.sql.DataSource;
- import javax.annotation.Resource;
- import javax.faces.context.FacesContext;
- import javax.inject.Inject;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpSession;
- // or import javax.faces.bean.ManagedBean;
- import org.glassfish.osgicdi.OSGiService;
- @Named("ApplicationController")
- @SessionScoped
- public class Application implements Serializable {
- /* This Hash Map will be used to store setting and value */
- private HashMap<String, String> settingsMap = null;
- public Application(){
- }
- /* Call the Oracle JDBC Connection driver */
- @Resource(name = "jdbc/Oracle")
- private DataSource ds;
- private String session = "six";
- public String getsession() {
- return session;
- }
- public void setsession(String session) {
- this.session = session;
- }
- /* Get setting value using key */
- public String settingValue(String key)
- {
- try
- {
- return (String) settingsMap.get(key);
- }
- catch(Exception x) { return "error - " + x.getMessage(); }
- }
- /* Hash Map declaration */
- public HashMap<String, String> getSetting(String key)
- {
- return settingsMap;
- }
- /* Get a Hash Map with settings and values. The table is genarated right
- * after the constructor is initialized.
- */
- @PostConstruct
- public void initSettings() throws SQLException
- {
- settingsMap = new HashMap<String, String>();
- if(ds == null) {
- throw new SQLException("Can't get data source");
- }
- /* Initialize a connection to Oracle */
- Connection conn = ds.getConnection();
- if(conn == null) {
- throw new SQLException("Can't get database connection");
- }
- /* With SQL statement get all settings and values */
- PreparedStatement ps = conn.prepareStatement("SELECT * from GLOBALSETTINGS");
- try
- {
- //get data from database
- ResultSet result = ps.executeQuery();
- while (result.next())
- {
- settingsMap.put(result.getString("SettingName"), result.getString("SettingValue"));
- }
- }
- finally
- {
- ps.close();
- conn.close();
- }
- }
- public void SettingsDBUpdate(){
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement