Skip to Content
0
Dec 18, 2006 at 02:09 PM

How to import a simple JavaBean as a modelObject ?? -- Urgent

12 Views

Hi All,

Taking leaves from the tutorial how to use EJB's in WebDynPro applications, I am trying to use a SimpleJava bean as a modelObject and instead of Using EJB's to persist data, I want to connect to the backend using the JDBC connection, So I have put on certain methods to getConnection() and one method to addUser( ) with in the JavaBean model class only.

Now, after extracting out the bean jar and importing it as a model, while trying to execute the addUser( ) from the JavaBean in the Save Action

wdContext.currentUserInfoBeanElement().modelObject().addUser( )

I get the error that the method modelObject is undefined for IPrivateResourceEntry.IUserInfoBeanElement( )

It would be really helpful If somebody could suggest how do I solve this ? or better still some error free step by step way to use a simple javabean with methods.So that I am able to persist data from the model class only!!

following is my JavaBean Model class

***************************************************************************************

public class UserInfoBean

{

private String empId;

private String name;

private String primarySkill;

private String designation;

private String emailId;

private String deskPhone;

private String mobile;

private String workLocation;

private String photoPath;

private Connection connection;

//

private ResultSet rs;

public UserInfoBean()

{

}

public void execute()

{

}

public void addUser()

{

Connection connection = null;

try

{

connection = getConnection();

String query = null;

PreparedStatement ps = connection.prepareStatement("insert into User (Employee_Id,Name,Phone1,Phone2,"+

"Location,Designation,Technology,Email_Id,Photo_Path)"+

"values(?,?,?,?,?,?,?,?,?)");

try

{

ps.setString(1,getEmpId());

ps.setString(2,getName());

ps.setString(3,getDeskPhone());

ps.setString(4,getMobile());

ps.setString(5,getWorkLocation());

ps.setString(6,getDesignation());

ps.setString(7,getPrimarySkill());

ps.setString(8,getEmailId());

ps.setString(9,getPhotoPath());

ps.executeUpdate();

}

catch(SQLException se)

{

se.printStackTrace();

}

catch(Exception e)

{

e.printStackTrace();

}

finally

{

ps.close();

}

}

catch(Exception e)

{

e.printStackTrace();

}

}

public static Connection getConnection() throws SQLException, ClassNotFoundException

{ /*

Connection connection = null;

Class.forName(IConstants.SQL_DRIVER);

connection = DriverManager.getConnection(IConstants.SQL_URL,IConstants.SQL_UN,IConstants.SQL_PWD);

return connection; */

java.sql.Connection connection = null ;

try

{

InitialContext initialContext = new InitialContext();

DataSource dataSource = (DataSource)initialContext.lookup("jdbc/aliasforradar");

connection = dataSource.getConnection();

}

catch (SQLException e)

{

e.getMessage();

}

catch (NamingException e) {

e.getMessage();

}

return connection;

}

/**

  • @return

*/

public String getDesignation() {

return designation;

}

/**

  • @return

*/

public String getDeskPhone() {

return deskPhone;

}

/**

  • @return

*/

public String getEmailId() {

return emailId;

}

/**

  • @return

*/

public String getEmpId() {

return empId;

}

/**

  • @return

*/

public String getMobile() {

return mobile;

}

/**

  • @return

*/

public String getName() {

return name;

}

/**

  • @return

*/

public String getPhotoPath() {

return photoPath;

}

/**

  • @return

*/

public String getPrimarySkill() {

return primarySkill;

}

/**

  • @return

*/

public String getWorkLocation() {

return workLocation;

}

/**

  • @param string

*/

public void setDesignation(String string) {

designation = string;

}

/**

  • @param string

*/

public void setDeskPhone(String string) {

deskPhone = string;

}

/**

  • @param string

*/

public void setEmailId(String string) {

emailId = string;

}

/**

  • @param string

*/

public void setEmpId(String string) {

empId = string;

}

/**

  • @param string

*/

public void setMobile(String string) {

mobile = string;

}

/**

  • @param string

*/

public void setName(String string) {

name = string;

}

/**

  • @param string

*/

public void setPhotoPath(String string) {

photoPath = string;

}

/**

  • @param string

*/

public void setPrimarySkill(String string) {

primarySkill = string;

}

/**

  • @param string

*/

public void setWorkLocation(String string) {

workLocation = string;

}

}