February 6, 2013

How to display a message dialog on the JSF page



The below code will be used to display a message dialog on the JSF page.

        FacesContext facesContext = FacesContext.getCurrentInstance();
        FacesMessage facesMessage = new FacesMessage(message);
        facesMessage.setSeverity(severity);
        facesContext.addMessage(null, facesMessage);

Where message is the message what we want to display on the dialog box and severity is to show the severity of the message. Example for severity is FacesMessage.SEVERITY_INFO which displays the dialog box as an information message. Inputs for severity is available in FacesMessage class.

Creating GraphDataModel object for pieGraph



When creating a dvt:pieGraph, an object of GraphDataModel class needs to be passed as input to it.

The below code helps to understand how to create GraphDataModel object.

In the below code, I am taking data from database.

    public static GraphDataModel getGraphDataModel(String table,                                                                                                     String cust_id) throws Exception {     
  String[] columnLabels = { "" };
        String[] columnNames = getColumnNames(table);//User defind Method, returns all column names of the given table
        int size = columnNames.length;
        if (ignoreFields != null)
            size = size - ignoreFields.size();
        Object[][] data2 = new Object[1][size];
        String[] seriesLabels = new String[size];

        Connection con = createConnection(); //Method to return connection object
        Statement stmt = con.createStatement();
                StringBuilder query = new StringBuilder("SELECT * FROM " + table+ "where cust_id="+cust_id);
              
        System.out.println("Query of graph: " + query);
        ResultSet rs = stmt.executeQuery(query);
        if (rs.next()) {
            for (int i = 0, j = 0; i < columnNames.length && j < size; i++) {
                if ("cust_id".equals(columnNames[i]))
                    continue;
                seriesLabels[j] = columnNames[i];
                data2[0][j] = new Double(rs.getDouble(i + 1));
                j++;
            }
        }
        rs.close();
        stmt.close();
        con.close();

        oracle.dss.dataView.LocalXMLDataSource ds =
            new oracle.dss.dataView.LocalXMLDataSource(columnLabels,
                                                       seriesLabels, data2);
        GraphDataModel graphData =
            new oracle.adf.view.faces.bi.model.GraphDataModel();
        graphData.setDataSource(ds);
        return graphData;}

Inserting Date and Time in database

I want to insert date and time into a field of a Oracle table whose data type is "Date".

To do so, I have used the below command.


to_date('2011/12/12 11:15:00', 'yyyy/mm/dd hh24:mi:ss')

Example:

Table definition: 
create table ATG(local_id varchar2(50) primary key,Last_Sale Date, Last_Sale_Value varchar2(50),Total_12_month_Value  varchar2(50));

In the above table, I want to insert data and time to "Last_Sale field".

Insert data:

insert into ATG values ('9986',to_date('2011/12/12 11:15:00', 'yyyy/mm/dd hh24:mi:ss'),'£319.99','£1,234,96');