Monday, May 07, 2007

Simple JSF

Here my snippet that working successfully...
The page is where user can view ,add,delete and edit the data in the same page.

My Managed bean
public class MyBean {

private List myDataList;
private HtmlDataTable myDataTable;//bind
private MyData myDataItem=new MyData();
private boolean editMode=false;
private String status="";
private MyDataAccess da=new MyDataAccess();
/** Creates a new instance of MyBean */

public MyBean() {
loadMyDataList();
}
public void loadMyDataList(){
//my dao thing
try {
myDataList=da.retrieveNationalityList();
} catch (Exception ex) {
System.out.println("Something error while loadMyDataList...");
ex.printStackTrace();
}

}
public List getMyDataList() {
if(FacesContext.getCurrentInstance().getRenderResponse()){
loadMyDataList();
}
return myDataList;
}

public void setMyDataList(List myDataList) {
this.myDataList = myDataList;
}

public String deleteMyData(){
//get selected MyData
setMyDataItem((MyData)getMyDataTable().getRowData());
status=da.deleteNationality( getMyDataItem().getId());
setMyDataItem(null);//clean textfield
System.out.println("Str inside delete-->"+ status);
return "delete"; //navigation case
}

public HtmlDataTable getMyDataTable() {
return myDataTable;
}

public void setMyDataTable(HtmlDataTable myDataTable) {
this.myDataTable = myDataTable;
}

//addition
public String insertData(){
try {
MyDataAccess da=new MyDataAccess();
System.out.println("Tgk jap date ko tulih camnaa? --->" + getMyDataItem().getSetupDate());
status=da.insertData(getMyDataItem());

} catch (Exception ex) {
ex.printStackTrace();
}
if(status=="success"){
System.out.println("status--->"+ status);
setMyDataItem(null);
return "success";
}
else{
return "fail";
}
}

public MyData getMyDataItem() {
return myDataItem;
}

public void setMyDataItem(MyData myDataItem) {
this.myDataItem = myDataItem;
}

public String editData(){
editMode=true;
System.out.println("editMode --> "+ editMode);
setMyDataItem((MyData)getMyDataTable().getRowData());
return "edit";
}

public String saveData(){ //in edit mode
System.out.println("editMode---> "+ editMode);
status=da.editNationality(getMyDataItem());
setMyDataItem(null);//clean textfield
System.out.println("status inside saveData-->"+ status);
return "save";
}
}
My data object
public class MyData {
private String id;
private String descr;
private String setupDate;
private String changeDate;

/** Creates a new instance of MyData */
public MyData() {
}

//setter
public void setId(String id) {
this.id = id;
}

public void setChangeDate(String changeDate) {
this.changeDate = changeDate;
}

public void setSetupDate(String setupDate) {
// setupDate.toString();
this.setupDate = setupDate;
}

public void setDescr(String descr) {
this.descr = descr;
}

//getter
public String getDescr() {
return descr;
}

public String getId() {
return id;
}
public String getSetupDate() {
return setupDate;
}

public String getChangeDate() {
return changeDate;
}

}
My data access

public class MyDataAccess {
private String str="";
Connection con = null;
PreparedStatement ps = null;
/** Creates a new instance of MyDataAccess */
public MyDataAccess() {
}

public List retrieveNationalityList() throws Exception{
ArrayList ls=new ArrayList();
ResultSet rsReturn = null;

try {
con = DBManager.getDBConnection();
String sql="select id,descr,to_char(setup_date,'MM/dd/yyyy, hh:mm:ss'),to_char(change_date,'MM/dd/yyyy, hh:mm:ss') from nationality order by id asc" ;
System.out.println("sql-->"+ sql);
ps = con.prepareStatement(sql);
System.out.println("Nilai ps---->"+ ps);
rsReturn = ps.executeQuery();
System.out.println("rsReturn-->"+rsReturn);
while(rsReturn.next()){
MyData n=new MyData();
n.setId(rsReturn.getString(1));
System.out.println("rsReturn.getString(1)"+ rsReturn.getString(1));
n.setDescr(rsReturn.getString(2));
System.out.println("rsReturn.getString(2)"+ rsReturn.getString(2));
n.setSetupDate(rsReturn.getString(3));
n.setChangeDate(rsReturn.getString(4));
System.out.println("rsReturn.getString(4)"+ rsReturn.getString(4));
ls.add(n);
}
System.out.println("list size---->"+ ls.size());
} catch(SQLException sqlex) {
System.out.println("Inside sqlexception ...");
sqlex.printStackTrace();
} finally {
con.close();
ps.close();
}

return ls;
}


public String deleteNationality(String id){
try {
try {
con = DBManager.getDBConnection();
} catch (Exception ex) {
System.out.println("Inside deleteNationality ");
ex.printStackTrace();
}
int count=0;

String sql="delete nationality where id='"+id+"'";
System.out.println("sql-->"+ sql);
ps = con.prepareStatement(sql);
System.out.println("Nilai ps---->"+ ps);
count= ps.executeUpdate();
if(count<0 data-blogger-escaped-str="success">"+str);

} catch(SQLException sqlex) {
sqlex.printStackTrace();
} finally {
try {
con.close();
ps.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
return str;
}

//for addition
public String insertData(MyData nationality) throws Exception {
try {
con = DBManager.getDBConnection();
int count=0;

String sql="insert into nationality(id,descr,setup_date,change_date) values('"+nationality.getId()+
"','"+nationality.getDescr()+"',current_timestamp,current_timestamp)";
System.out.println("sql--&gt;"+ sql);
ps = con.prepareStatement(sql);
System.out.println("Nilai ps----&gt;"+ ps);
count= ps.executeUpdate();
if(count<0 data-blogger-escaped-str="success">"+str);

} catch(SQLException sqlex) {
System.out.println("Inside sqlexception ...");
sqlex.printStackTrace();
} finally {
con.close();
ps.close();
}
return str;
}

public String editNationality(MyData data){
try {
try {
con = DBManager.getDBConnection();
} catch (Exception ex) {
System.out.println("Inside editNationality ");
ex.printStackTrace();
}
int count=0;
String sql="UPDATE nationality SET descr='"+data.getDescr()
+"',change_date=current_timestamp WHERE id ='"+data.getId()+"'";
System.out.println("sql--&gt;"+ sql);
ps = con.prepareStatement(sql);
System.out.println("Nilai ps----&gt;"+ ps);
count= ps.executeUpdate();
if(count<0 data-blogger-escaped-str="success">"+str);

} catch(SQLException sqlex) {
sqlex.printStackTrace();
} finally {
try {
con.close();
ps.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
return str;
}
}

Tuesday, February 06, 2007

How to setup JBOSS?


1.Download JBOSS Application Server Installer, mine is version 4.0.5 , http://labs.jboss.com/portal/jbossas/download
2.Just install it .
3.Open MyEclipse,mine is 5.1.0 go to Window >Preferences>MYEclipse>Application Servers
4.Choose JBoss 4,setup JBoss server to Enable


5. Make sure that it read the right JRE.Like my latest JRE is inside folder Java



6.Then start JBoss,it should be OK.But if you get an error something like this …"JVM address in used" that 's mean the default port of JBoss which is 8080 is used by other program.
If you feel wasting your time to figure out which program is it, you just need to change port for JBoss.Use other port instead of 8080.
To change the port is,


7.Go to F:\jboss\server\default\deploy\jbossweb-tomcat55.sar ,where you install your JBpss.Open server.xml,change 8080 to any other number that you prefer.For example I changed it to 8081

8.Start your JBoss again, and you can see that your JBoss start happily ever after.

Tuesday, January 23, 2007

How to install and setup cvs


This setup is only basic manual.I created it after successfully install and setup cvs.The different step that I faced while reading references thru internet makes me create new manual so I will not forget in the future.I am happy if you feel it's useful.

Software requirement

  1. Installation step
    Install CVS and WinCVSa) Install cvsnt-2.5.0.3.2382 and WinCVS

    (Sometimes it's already bundled with Wincvs,if not just install it separately)

    b) Go to Control Panel,click twice on CVSNT Server

    c)Choose Repository Configuration, click Add


    d)Then choose location,make new folder if you do not have it yet.For example my Location is F:/Repositories/MyRepo.

    At Name I put as /MyRepo to make people outside see it just as /MyRepo not F:/Repositories/MyRepo.Then click OK,usually it will prompt you "F:/Repositories/MyRepo,but is not a valid CVS repository.Do you want to initialise it?" Just click Yes.


    e)Go to About tab, and start the service.

    Install python 2.5
    a)The installation is straightforward but make sure you install it for all user.

    b)In customization make sure the Tcl/Tk features available.
    <
    c)Just next next until you complete the installation

    Install pywin32 (Optional)
    Just follow the step straightforward


    Install WinMerge
    Just follow the step straightforward
  2. Configuration of WinCVS
    a)Browse folder for example mine is F:\Projects

    b)Go to Admin menu,select Preferences,click on CVS tab.

    At Home, just choose folder that you like.Home directory is where CVS and WinCVS will look for local,user –specific configuration.
    Then check on Alternate CVS executable,browse where cvs.exe


    c)Click on WinCvs tab.
    Check on External diff:,browse where location that you install WinMerge.

    At Python DLL, put python25.dll.If you install Python 2.4 just put it as python24.dll.Same goes with other versions.

    After that, click on Command Dialogs, and in Skip Dialogs, check on Graph.


  3. Import module
    Actually I tried it several time ,after facing failure several times then it's success.So maybe my steps is quite odd but my objective here to make sure that Eclipse can checkout the project from CVS server.If you not developing project using Eclipse maybe you can just follow the tutorial link that I refered.
    a)Right-click on MyProject,Import Filter will pop-up ,just click OK.But in case if you to filter the file just click Edit and edit whatever you want.


    b)Then Import Setting like figure below will pop-up.Repository path is the location where our project is stored in the repository.
    If you not importing third party source,check on Don't create vendor branch or release tags.

    Then we will set up the CVSROOT connection string.

    c)I choose pserver protocol.At Repository Path I just type : Administrator:cunid@localhost:/MyRepo

    The format is username:password@hostname/repositoryname

    Username is the computer username,password is your computer password,hostname is the name of your computer.You can refer the scrip at links that I provided.

    I am not quite sure what the hell proxy is all about.But you can try and tell me.Thanks in advance.


    d)Then click on Import option tab,check on Create CVS directories while importing. Then OK. ***** CVS exited normally with code 0 ***** means that you code is correct else there's something wrong.Ok,the configuration is complete.Then you can search other command at Internet.
  4. To add user
    cvs passwd -r Administrator -a syikin



  5. Connection string
    :pserver:Administrator:cunid@localhost:/MyRepo
    p/s:Please email me if you want manual with picture,I am quite lazy to upload those pictures.I'll send to you if you email me.

    Useful links that I refered
    http://freenet-homepage.de/ogiesen/wincvsnt-tour-ext.html

    http://ssi7.cs.tamu.edu/ssi/tutorials/cvsNt/addUsers.pdf