Calling MS SQL Server 2005 Stored Procedure from Spring JDBCTemplate

 

The idea came from DotNetNuke design pattern, based on experience on DNN based project, SoftONE Logic’s team try to find the easier way to use Stored Procedure on the Spring JDBCTemplate . SoftONE Logic’s team has used iBatis to call stored procedure. Due to the ‘complexity’ of XML, the team start to do research to find other way to implement it.

Here are the outcome of the research.

  •     DB Server : MS SQL Server 2005
  •     Spring Framework 2.5 (JDBCTemplate features).
Get Object from DB

Create Stored Procedure named hr_GetRequisitionForm, has one input parameter.

USE [hr]
    GO
SET ANSI_NULLS ON
    GO
SET QUOTED_IDENTIFIER ON
    GO
CREATE procedure [dbo].[hr_GetRequisitionForm]
    @id int
as
    select
*
    from hr_vw_RequisitionForm
where
   id = @id

Create Method to call above stored procedure by using Spring JDBC Template.

public RequisitionFormVO getRequisitionDataByRequisitionId(int id){
     String queryString = "{call hr_GetRequisitionForm(?)}";
     Object args []= new Object[] {id};
     return (RequisitionFormVO)jdbcTemplate.queryForObject(queryString, args, new RequisitionFormMapper());
}

I assume reader has already familiar with Spring JDBC Tempalte. The hr_GetRequisitionForm stored procedure has one input parameter (id). Pass the value of id to the stored procedure with hr_GetRequisitionForm(?) statement, and Object args []= new Object[] {id}; . Cast the returned object from jdbcTemplate and use the method queryForObject as shown below:

(RequisitionFormVO)jdbcTemplate.queryForObject(queryString, args, new RequisitionFormMapper());

Get List from DB

Create Stored Procedure named hr_GetApprovedRequisitionForm

USE [hr]
   GO
SET ANSI_NULLS ON
   GO
SET QUOTED_IDENTIFIER ON
   GO
CREATE procedure [dbo].[hr_GetApprovedRequisitionForm]
   as
SELECT
   *
FROM
   hr_vw_RequisitionForm
WHERE
   HRManagerVerifiedStatus = 'verified' AND
   SGManagerApprovedStatus = 'approved' AND
   ManagingDirectorApprovedStatus = 'approved'

Create Method to call above stored procedure by using Spring JDBC Template.

public List getApprovedRequisitionData(){
     String queryString = "{call hr_GetApprovedRequisitionForm}";
     return jdbcTemplate.query(queryString, new RequisitionFormMapper());
}

The MapperClass is to map the Database column with ValueObject class.

package com.softonelogic.project.smoe.hr.utils.persistence.sqlmapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import com.softonelogic.project.smoe.hr.utils.vo.RequisitionFormVO;
public class RequisitionFormMapper implements RowMapper {
public Object mapRow(ResultSet rs, int arg1) throws SQLException {
     RequisitionFormVO obj = new RequisitionFormVO();
     obj.setId(rs.getInt("ID"));
     obj.setPositionVacant(rs.getString("PositionVacant"));
     ...
     return obj;
     }
}

 

Sep 6, 2009 Posted Under: Java Enterprise Edition, Spring Framework   Read More

Introduction to LaTeX and Getting it to Work

 

What is LaTeX?

LaTeX is a typesetting software that can be used to produce documents. It is like the well-known graphical typesetting software such as MS. Words or Open Office Writer. However, the typesetting process in LaTeX is not so straightforward. You need to code it properly to produce high quality documents.

 

Why LaTeX?

LaTeX loses to MS Words in terms of the user-friendly but it has many advantages such as:

  • Documents produced by Latex has higher quality when it is displayed or printed.

  • The programmable typesetting ensures that the format consistency can be maintained

  • It is simply the best package for documents containing mathematics and graphical plots. To insert mathematics expression or graphical plot of a function can be simply done by typing, leaving the trouble of producing the equations and plots on the other software.

  • It is free on virtually every computer in the world and it is platform independent. One may produce a document in Windows but it can still be compiled and run in Linux or MAC.

  • It is portable, i.e. stick to the standard commands and everyone can read and exchange documents.

  • LaTeX has the reputation of being hard, but in fact it is effectively the same as HTML!

 

How to run LaTeX in Windows?

To run Latex, we need two things: one is the LaTeX compiler and two is the text-editor. There are many compilers and text-editors available for free. In this document, we show one example that we have tested in Windows Vista and XP. First, we need to install the compiler and the text-editor to proceed.

 

Compiler (using MiKTeX)

  • Download the compiler here. You may opt for either the basic or the complete versions. For the purpose of this article, we use the basic installation.

  • Make sure that you get basic-miktex-2.7.3248.exe for the installation.

  • Run the installer and follow the standard procedure of installation.

  • Once the installation is complete, the MiKTeX is ready for compiling.

 

Text-editor (using TeXnicCenter)

  • Download the installer here. For majority of the users, the option 1 ( TeXnicCenter installer) is sufficient. Please take note some errors that may occur if you use older version of windows and/or the internet explorer.

  • Make sure that you get TXCSetup_1StableRC1.exe.

  • Run the installer and complete the standard procedure.

  • Open the TeXnicCenter application and it will show the configuration window.

 

  • Click Next and specify the MiKTeX installation directory. Let say my installed MiKTeX is in “C:\Program Files (x86)\MiKTeX 2.7\”. Then, point to the directory of C:\Program Files (x86)\MiKTeX 2.7\miktex\bin” in the configuration window. It should look like this

 

  • Click Next and Finish.

  • Congratulations! Now, you can start to use LaTeX for typesetting and produce high quality documents.

  • To use it, just simply open the TeXnicCenter for inserting the codes.

 

To be continued: Producing simple document with LaTeX.

NB: Please report for the broken link!

Sep 3, 2009 Posted Under: Uncategorized   Read More

Embedded Fonts in Pdf

 

It is often that we need to submit paper or report electronically in portable document format (p.d.f.) that requires the fonts are embedded so that it is easily distributed or printed in various machines and p.d.f. version. It is usual for us to encounter the problem of emmbeded fonts simply because we use our own p.d.f converter. It may be from the pdf driver such as cutepdf, primopdf or our ghost script p.d.f converter.

Here is some "hacking techniques" to debug the problem of embedded fonts (in linux, taken from [1]).  Suppose your non-working p.d.f file is text.pdf

 

(1) convert to ps (postscript file):
pdftops text.pdf

(2) convert back to pdf using prepress settings:
ps2pdf14 -dPDFSETTINGS=/prepress text.ps

(3) check new text.pdf for horrendous formatting errors due to double conversion, and embedded fonts as above.

 

http://axiom.anu.edu.au/~luke/embedded_fonts.html

 

Sep 2, 2009 Posted Under: HOW TO, Portable Document, UNIX   Read More

Role based implementation in RichFaces with Spring Security

 

This article will explain how to implement role based system in the user control panel page. The login process is required to enter the page. The authentication process will be handled by the Spring Framework. I assume the reader understand how the Spring Security authentication works.
 
In the RichFaces page:
Page contain list of menu by implementing <rich:toolBar/> RichFace tag. The menu will be rendered based on user credential. The rendering process will be controled by bean class via rendered parameter in <rich:toolBar/> tag.
 
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:rich="http://richfaces.org/rich">

<rich:toolBar itemSeparator="line">
     <rich:toolBarGroup rendered="#{managerControlBean.menuSubscriber}">
          <rich:dropDownMenu value="Subscriber">
               <rich:menuGroup value="Manage Subscription" direction="right">
                    <rich:menuItem submitMode="ajax" value="Current Subscription">
                    </rich:menuItem>
                            …
                </rich:dropDownMenu>
            </rich:toolBarGroup>

In the bean class:

Declare the property of menuSubscriber in the class as a boolean type.

private boolean menuSubscriber = false;

Declare a final string type for the ROLE type. User can declare more than 1 role type, please ensure the role type in the bean class is the same as the role type declared in database.

private final String role_subscriber = "ROLE_SUBSCRIBER";

In the <rich:toolBar/> the rendered parameter will get the value of menuSubcriber property via isMenuSubcriber() method

public boolean isMenuSubscriber() {
        this.menuSubscriber = validateAuthorization(role_subscriber);
        return menuSubscriber;
}

Method isMenuSubcriber() will call method validateAuthorization(String) to validate the user credential. Spring Framework method is used to validate the user credential.

private boolean validateAuthorization(String authorizationString){
        boolean authStatus = false;
       
        SecurityContext securityContext = SecurityContextHolder.getContext();
        if(securityContext != null){
            Authentication authentication = securityContext.getAuthentication();
           
            GrantedAuthority[] authorities = authentication.getAuthorities();
           
            for(GrantedAuthority authStr : authorities){
                if((authStr.toString()).compareToIgnoreCase(authorizationString) == 0){
                    authStatus = true;
                }
            }
        }
        return authStatus;
    }

 

Aug 30, 2009 Posted Under: JavaServer Faces, Spring Framework   Read More

DNN NAV CSS

 

Modify the style of menu bar
Description Menu bar CSS class
Parameter Name CSSControl
CSS Selector
main_dnn_menubar
Example of usage

Properties to modify:

  • length of menu bar
  • background color of menu bar
  • cursor type when the cursor hover the menu bar

.main_dnnmenu_bar
{
    cursor:pointer;
    background-color:#e38a8a;
    width: 900px;
}

 

Example of implementation

 

 

Modify the style for the menu root item in the menu bar
Description CSS Class used for root menu items – Overrides CSSNode
Parameter Name CSSNodeRoot
CSS Selector
main_dnnmenu_rootitem
Example of usage

Properties to modify:

  • font color of the root item
  • background color of the root item
  • font size of the root item
  • font weight of the root item
  • text alignment of the root item
  • height of the root item
  • top, bottom, left, right padding from the text
  • text transform

.main_dnnmenu_rootitem 
{   
    color: white;
    background-color: #e38a8a;
    font-size: 13px;
    font-weight:bold;    
    text-align:center;
    line-height:46px;
    padding:15px 15px 15px 15px;
    text-transform:uppercase;
margin-right:1px;
}

 

Example of implementation

 

 

Modify the style if the menu in menu bar is in hover
Description CSS Class used for root menu items when they moused-over – Overrides CSSNodeHover
Parameter Name CSSNodeHoverRoot
CSS Selector
main_dnnmenu_rootitem_hover
Example of usage

Properties to modify:

  • font color of the root item on hover
  • background color of the root item on hover
  • font size of the root item on hover
  • font weight of the root item on hover
  • text alignment of the root item on hover
  • height of the root item on hover
  • top, bottom, left, right padding from the text on hover
  • text transform on hover

.main_dnnmenu_rootitem_hover
{   
    color: white;
    background-color: #cc3333;
    font-size: 13px;
    font-weight:bold;    
    text-align:center;
    line-height:46px;
    padding:15px 15px 15px 15px;
    text-transform:uppercase;
margin-right:1px;
}

 

Example of implementation: Cursor hovers on membership menu

 

 

Modify the style if the menu in menu bar is selected
Description CSS Class used for root menu items when they are the active tab – Overrides CSSNode, CSSBreadCrumbRoot
Parameter Name CSSNodeSelectedRoot
CSS Selector
main_dnnmenu_rootitem_selected
Example of usage

Properties to modify:

  • font color of the root item on selected menu
  • background color of the root item on selected menu
  • font size of the root item on selected menu
  • font weight of the root item on selected menu
  • text alignment of the root item on selected menu
  • height of the root item on selected menu
  • top, bottom, left, right padding from the text on selected menu
  • text transform on selected menu

.main_dnnmenu_rootitem_selected
{   
    color: white;
    background-color: #cc3333;
    font-size: 13px;
    font-weight:bold;    
    text-align:center;
    line-height:46px;
    padding:15px 15px 15px 15px;
    text-transform:uppercase;
margin-right:1px;
}

 

Example of implementation: About Pactrims menu is selected

 

 

Modify the style of sub menu
Description Sub menu CSS class
Parameter Name CSSContainerSub
CSS Selector
main_dnnmenu_submenu
Example of usage

Properties to modify:

  • Submenu border
  • Background color
  • Font size
  • Font weight
  • Display order
  • Text alignment
  • Text color
  • Text margin
  • Text padding

.main_dnnmenu_submenu
{
    border:1px solid #CC3333;
}

.main_dnnmenu_submenu td
{
    background-color:#FFFFFF;
    z-index: 1000;
    font-size: 11px;
    font-weight:bold;
    text-align:left;
    color:#000000;
    line-height:2em;
    padding: 0px 5px;
    margin:0px;
}

 

Example of implementation

 

 

Modify the style of sub menu on mouse over
Description Menu Item CSS Class for mouse-over – ALL Nodes
Parameter Name CSSNodeHoverSub
CSS Selector
main_dnnmenu_itemhover
Example of usage

Properties to modify:

  • Submenu border
  • Background color
  • Font size
  • Font weight
  • Display order
  • Text alignment
  • Text color
  • Text margin
  • Text padding

.main_dnnmenu_itemhover
{
    background: #CC3333;
    z-index: 1000;
    font-size: 11px;
    font-weight:bold;
    text-align:left;
    color:#FFFFFF;
    line-height:2em;
    padding: 0px 5px;
    margin:0px;
}

 

Example of implementation

 

 

Modify the style of sub menu on mouse over
Description CSS Class used for sub menu items when they are the active tab – Overrides CSSNode, CSSBreadCrumbRoot
Parameter Name CSSNodeSelectedSub
CSS Selector
main_dnnmenu_itemselected
Example of usage

Properties to modify:

  • Submenu border
  • Background color
  • Font size
  • Font weight
  • Display order
  • Text alignment
  • Text color
  • Text margin
  • Text padding

.main_dnnmenu_itemselected
{
    background: #CC3333;
    z-index: 1000;
    font-size: 11px;
    font-weight:bold;
    text-align:left;
    color:#FFFFFF;
    line-height:2em;
    padding: 0px 5px;
    margin:0px;
}

 

Example of implementation

Aug 29, 2009 Posted Under: DotNetNuke   Read More

Get ASP.NET control’s ID to be used by JavaScript function

 

Sometime we want to use javascript to be used in our ASP.NET (or any server side scripting language). The problem will occur if we want to get/store value from javascript to ASP.NET UI component (example asp:TextBox). Since the rendered ID of the ASP.NET component is generated in the runtime, so it’s difficult to set the ASP.NET component’s ID to the javascript in development process.

I suggest to assign the ASP.NET component’s ID to javascript in the code-behind file. In this article, I will explain how to add javascript pop-up calendar into the ASP.NET page.

In the ASP.NET page:

<asp:TextBox ID="StartDate" runat="server" CssClass="NormalTextBox" ReadOnly="false" Width="80"/>    

……

<asp:ImageButton ID="imageButtonStartDate" runat="server" ImageUrl="~/images/calendar.png"/>

The image button will be used as a trigger to show the pop-up calendar.  In code-behind, in the Page_Load() method, we need to do:

Registering the javascript into the ASP.NET

String moduleDir = this.TemplateSourceDirectory;

Page.ClientScript.RegisterClientScriptInclude("scw", moduleDir + "/JS/scw.js");

Add the action into the image button, choose OnClientClick

imageButtonStartDate.OnClientClick = "scwShow(" + StartDate.ClientID + ",event); return false;";

The scwShow method need to get the ASP.NET TextBox’s component ID. StartDate is the ID of the ASP.NET TextBox component. Use ClientID to get the ID of the TextBox.

Aug 28, 2009 Posted Under: .NET, HOW TO   Read More

DNN NAV Skin Parameter

 

NAV control orientation parameter
Description The orientation of the menu, default is horizontal, usage depends on the provider used
Parameter Name ControlOrientation
Possible Value Horizontal, Vertical
Example of usage Skin development in ascx level: modify the <dnn:NAV />tag

<dnn:nav ControlOrientation="Vertical" ProviderName="DNNMenuNavigationProvider" id="dnnNAV" runat="server"></dnn:nav>

 

Skin development in HTML level: modify the skin.xml file
<Object>
     <Token>[NAV]</Token>
          <Settings>
    <Setting>
         <Name>ControlOrientation</Name>
         <Value>Vertical</Value>
    </Setting>
               …

 

 

NAV indicate children parameter
Description Whether to display an indicator to show that there are child menu item
Parameter Name IndicateChildren
Possible Value True, False
Example of Usage Skin development in ascx level: modify the <dnn:NAV />tag

<dnn:NAV runat="server" id="dnnNAV" ProviderName="DNNMenuNavigationProvider" IndicateChildren="True"/>

 

Skin development in HTML level: modify the skin.xml file
<Object>
     <Token>[NAV]</Token>
          <Settings>
    <Setting>
         <Name>IndicateChildren</Name>
         <Value>True</Value>
    </Setting>
               …
 

The children indicator is represented with the white downward triangle

 

 

NAV level parameter
Description Defines which level need to be used to render the menu, default value is root
Parameter Name Level
Possible Value

Root

Child

Parent

Same

Example of usage Skin development in ascx level: modify the <dnn:NAV />tag

<dnn:NAVTopMenu runat="server" id="dnnNAVTopMenu" ProviderName="DNNMenuNavigationProvider" Level="Root"…/>

<dnn:NAVLeftMenu runat="server" id="dnnNAVLeftMenu" ProviderName="DNNMenuNavigationProvider" Level="Child"…/>

 

Skin development in HTML level: modify the skin.xml file
<Object>
     <Token>[NAV:TopMenu]</Token>
          <Settings>
    <Setting>
         <Name>Level</Name>
         <Value>Root</Value>
    </Setting>
               …

<Object>
     <Token>[NAV:LeftMenu]</Token>
          <Settings>
    <Setting>
         <Name>Level</Name>
         <Value>Child</Value>
    </Setting>
               …
 

The top menu is example for the usage of Level = Root and the left menu is displayed the submenu of the top menu by setting Level = Child

 

 

NAV Separator HTML, Separator Left HTML, Separator Right HTML
Description SeparatorHTML:
Text to use as a separator for root menu items

SeparatorLeftHTML:
Text to use as left-only separator for root menu items that are not the first item in the menu

SeparatorRightHTML:
Text to use as right-only separator for root menu items that are notthe first item in the menu
 

Parameter Name SeparatorHTML
SeparatorLeftHTML
SeparatorRightHTML
Possible Value Any character
Example of usage Skin development in ascx level: modify the <dnn:NAV />tag, add the property SeparatorHTML=" | "…. />

<dnn:NAV runat="server" id="dnnNAV" ProviderName="DNNMenuNavigationProvider" SeparatorHTML="  |  "…/>

The SeparatorHTML of | character is displayed in the text menu

 

Skin development in ascx level: modify the <dnn:NAV />tag, add the property SeparatorLeftHTML=" | "…. />

<dnn:NAV runat="server" id="dnnNAV" ProviderName="DNNMenuNavigationProvider" SeparatorLeftHTML="  |  "…/>

The different between SeparatorHTML and SeparatorLeftHTML is in SeparatorHTML there is no separator in the first menu (HOME).

 

Skin development in ascx level: modify the <dnn:NAV />tag, add the property SeparatorRightHTML=" | "…. />

 <dnn:NAV runat="server" id="dnnNAV" ProviderName="DNNMenuNavigationProvider" SeparatorRightHTML="  |  "…/>

The separator is displayed in the right side of the text menu

 

Aug 28, 2009 Posted Under: DotNetNuke   Read More

Auto Increment in PostgreSQL

First of all, create a sequence:

CREATE SEQUENCE question_sequence;

Then create the table:

CREATE TABLE question (
    ID INTEGER NOT NULL PRIMARY KEY DEFAULT nextval(’question_sequence’),
    QUESTION_TEXT CHARACTER VARYING(250),
    QUESTION_LEVEL CHARACTER VARYING(50)
);

 

Aug 13, 2009 Posted Under: HOW TO   Read More

ASP.NET Regular Expression Validation: Email Address

 

In the form, normally we need to validate the user input. One of the validation is using Regular Expression. This article will show how to use regular expression to validate the email address based on its pattern.

Create the text box field to enter the email address:

<asp:TextBox ID="textBoxEmail" runat="server" CssClass="NormalTextBox" Width="256px"/>

Regular Expression Validation for email address is given below:

<asp:RegularExpressionValidator Display="Dynamic"  ID="ValidatorEmail"
          runat="server" ControlToValidate="textBoxEmail"
          ValidationExpression="([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA- Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})">
                <asp:Image ID="imageErrorEmailAddress" runat="server" ImageUrl="~/images/delete.gif" />
                <asp:Label ID="labelErrorMessageEmailAddress" Text="Incorrect Email Format" CssClass="SubHead" runat="server" />
</asp:RegularExpressionValidator>

If user enter the incorrect pattern of email address, the error message will appear in the asp.net webform, and it will always appear until the user enter the correct pattern of email address.

Jul 22, 2009 Posted Under: .NET   Read More

Exporting Collection Data to Excel format from ASP.NET Control

 

Ok, let assume that you have DataGrid/GridView/any other ASP.NET Control that display collection data from DataSource. You want to export the collection data to excel file.

<asp:DataGrid ID="dataGridViewAbstract"…>

</asp:DataGrid>

Add linkButton as a trigger to the event handler to generate excel file

<asp:LinkButton ID="linkButtonDownloadExcel" runat="server" Text="Export to Excel" CssClass="SubHead" OnClick="linkButtonDownloadExcel_Click"/>

We create the event handler that contain the step to generate the excel file from data collection on ASP.NET Component

Jul 21, 2009 Posted Under: .NET   Read More
Page 2 of 3«123»