on 01-09-2007 9:54 AM
I have defined SearchUser() in bean class and importing this bean to Web Dynpro application.After extarcting data from data base i am storing it in public varilabes My qury is now how to display all field's information In the ResultView.If i will write system.out.println within bean it won't work in NWDS.How i will display this field's information in My ResultView?
public void SearchUser()
{
Connection connection = null;
try{
Statement st=connection.createStatement();
ResultSet rs=st.executeQuery("select * from Resource where Employee_Id=?");
//System.out.println("result" +rs);
while(rs.next())
{
empId=rs.getString(1);
name=rs.getString(2);
technology=rs.getString(3);
designation=rs.getString(4);
emailId=rs.getString(5);
phone1=rs.getString(6);
phone2=rs.getString(7);
location=rs.getString(8);
photoPath=rs.getString(9);
}//end of while
rs.close();
st.close();
connection.close();
}catch(SQLException se)
{
se.printStackTrace();
se.getMessage();
}
catch(Exception e)
{
e.printStackTrace();
}
}
In the ResultView I am calling
public void onPlugFromMyProfileCompView(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onPlugFromMyProfileCompView(ServerEvent)
IWDMessageManager msgMgr=wdComponentAPI.getMessageManager();
try
{
wdContext.currentMyProfileBeanElement().modelObject().SearchUser();
//wdContext.currentMyProfileBeanElement().modelObject().getEmpId();
//msgMgr.reportSuccess("Congratulations,User Added to the Database tables..inside try");
}
In The ResultView i have taken 9 label and textview to display user information and i also did context mapping from component controller to Resultview.But while running the application it's not displaying the data in the TextView.
Hi Susmita,
you have to fill data into context elements selbst (this element you can bind to Labels or inputfields). In your code, you have read the data but not save it anywhere. Have a look at this tutorial https://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/b1a3e990-0201-0010-aeb2-a2ef5bc3da8e passibly that help a little.
Regards
Bogdan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
i have already done all binding to the textview and contect mapping from component controller ResultView In the bean class I am storing the retrieved field's information in respective global varibale Is there any another way to store the retrieved information?My problem is how i will display this store information in the resultview.Whenver i am calling wdContext.currentMyProfileBeanElement().modelObject().SearchUser(); in the ResultView it's not shoing the data in the respective textview of ReaultView.
Hi
I am giving the deatils.I couldn't found how i will show the information retrived from sql server.
Inside COMPONENT CONTROLLER............................
wdDoInit()
try
{
//wdContext.nodeUserInfoBean().bind(new UserInfoBean());
wdContext.nodeMyProfileBean().bind(new MyProfileBean());
}
catch(Exception ex)
{
IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();
msgMgr.reportException(ex.getLocalizedMessage(),true);
}
//@@end
}
Inside MyProfileCompView......................................
public void onActionSearchInfo(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionSearchInfo(ServerEvent)
IWDMessageManager msgMgr=wdComponentAPI.getMessageManager();
String EmpId=wdContext.currentMyProfileBeanElement().modelObject().getEmpId();
msgMgr.reportSuccess("EmpId"+EmpId);
int temp=wdContext.currentMyProfileBeanElement().modelObject().getFlag();
// int temp=wdContext.currentContextElement().getFlag();
msgMgr.reportSuccess("temp value"+temp);
if(EmpId==null)
{
msgMgr.reportWarning("Employee Id can not be null");
}
else if(EmpId.length()<8)
{
msgMgr.reportWarning("Length should not be less than 8");
}
else if(EmpId.length()>8){
msgMgr.reportWarning("Length should not greater than 8");
}
else{
msgMgr.reportWarning("Accessing the Data Base");
}
try{
if(temp!=0)
{
wdThis.wdFirePlugToResultProfileView();
}
else{
msgMgr.reportWarning("User Id doesn't exist in the data base");
}
}catch(Exception e)
{
msgMgr.reportSuccess("CAUGHT BY EXCEPTION");
msgMgr.reportException(e.getLocalizedMessage(),true);
}
Inside ResultView....................
public void onPlugFromMyProfileCompView(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onPlugFromMyProfileCompView(ServerEvent)
IWDMessageManager msgMgr=wdComponentAPI.getMessageManager();
try
{
wdContext.currentMyProfileBeanElement().modelObject().SearchUser();
//msgMgr.reportSuccess("Inside successfully");
wdContext.currentMyProfileBeanElement().modelObject().getEmpId();
//wdContext.currentMyProfileBeanElement().modelObject().getDesignation();
//msgMgr.reportSuccess("Congratulations,User Added to the Database tables..inside try");
}
catch(Exception e)
{
msgMgr.reportSuccess("Congratulations,User Id is not exist in the Database tables...Caught by exception");
msgMgr.reportException(e.getLocalizedMessage(),true);
}
msgMgr.reportSuccess("SUCCESS");
// wdContext.currentMyProfileBeanElement().modelObject().setEmailId()
//@@end
}
//@@begin javadoc:onActionBackInfo(ServerEvent)
/** Declared validating event handler. */
//@@end
public void onActionBackInfo(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionBackInfo(ServerEvent)
wdThis.wdFirePlugToMyProfileCompView();
//@@end
}
Inside Bean class MyProfileBean...............
public class MyProfileBean
{
private String empId;
private String name;
private String technology;
private String designation;
private String emailId;
private String phone1;
private String phone2;
private String location;
private String photoPath;
private byte[] image;
private int flag;
private Connection connection;
private ResultSet rs;
static DataSource dataSource;
public MyProfileBean()
{
try
{
//code to look up the datasource
InitialContext initialContext = new InitialContext();
dataSource = (DataSource)initialContext.lookup("jdbc/aliasforradar");
}
catch (NamingException e)
{
e.getMessage();
}
}
public void SearchUser()
{
Connection connection = null;
try{
Statement st=connection.createStatement();
ResultSet rs=st.executeQuery("select * from Resource where Employee_Id=?");
if(rs!=null)
{
flag=1;
}else{
flag=0;
}
//System.out.println("result" +rs);
while(rs.next())
{
empId=rs.getString(1);
name=rs.getString(2);
technology=rs.getString(3);
designation=rs.getString(4);
emailId=rs.getString(5);
phone1=rs.getString(6);
phone2=rs.getString(7);
location=rs.getString(8);
photoPath=rs.getString(9);
}//end of while
rs.close();
st.close();
connection.close();
}catch(SQLException se)
{
se.printStackTrace();
se.getMessage();
}
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
{
connection = dataSource.getConnection();
}
catch (SQLException e)
{
e.getMessage();
}
return connection;
}
/**
@return
*/
public String getDesignation() {
return designation;
}
/**
@return
*/
public String getPhone1() {
return phone1;
}
/**
@return
*/
public String getEmailId() {
return emailId;
}
/**
@return
*/
public String getEmpId() {
return empId;
}
/**
@return
*/
public String getPhone2() {
return phone2;
}
/**
@return
*/
public String getName() {
return name;
}
/**
@return
*/
public String getPhotoPath() {
return photoPath;
}
/**
@return
*/
public String getTechnology() {
return technology;
}
/**
@return
*/
public String getLocation() {
return location;
}
/**
@param string
*/
public void setDesignation(String string) {
designation = string;
}
/**
@param string
*/
public void setPhone1(String string) {
phone1 = string;
}
/**
@param string
*/
public void setEmailId(String string) {
emailId = string;
}
/**
@param string
*/
public void setEmpId(String string) {
empId = string;
}
/**
@param string
*/
public void setPhone2(String string) {
phone2 = string;
}
/**
@param string
*/
public void setName(String string) {
name = string;
}
/**
@param string
*/
public void setPhotoPath(String string) {
photoPath = string;
}
/**
@param string
*/
public void setTechnology(String string) {
technology = string;
}
/**
@param string
*/
public void setLocation(String string) {
location = string;
}
/**
@return
*/
public byte[] getImage() {
return image;
}
/**
@param bs
*/
public void setImage(byte[] bs) {
image = bs;
}
/**
@return
*/
/**
@return
*/
public int getFlag() {
return flag;
}
/**
@param i
*/
public void setFlag(int i) {
flag = i;
}
public int flagValue()
{
return flag;
}
}
public class MyProfileBean
{
private String empId;
private String name;
private String technology;
private String designation;
private String emailId;
private String phone1;
private String phone2;
private String location;
private String photoPath;
private byte[] image;
private int flag;
private Connection connection;
private ResultSet rs;
static DataSource dataSource;
public MyProfileBean()
{
try
{
//code to look up the datasource
InitialContext initialContext = new InitialContext();
dataSource = (DataSource)initialContext.lookup("jdbc/aliasforradar");
}
catch (NamingException e)
{
e.getMessage();
}
}
public void SearchUser()
{
Connection connection = null;
try{
Statement st=connection.createStatement();
ResultSet rs=st.executeQuery("select * from Resource where Employee_Id=?");
if(rs!=null)
{
flag=1;
}else{
flag=0;
}
//System.out.println("result" +rs);
while(rs.next())
{
empId=rs.getString(1);
name=rs.getString(2);
technology=rs.getString(3);
designation=rs.getString(4);
emailId=rs.getString(5);
phone1=rs.getString(6);
phone2=rs.getString(7);
location=rs.getString(8);
photoPath=rs.getString(9);
}//end of while
rs.close();
st.close();
connection.close();
}catch(SQLException se)
{
se.printStackTrace();
se.getMessage();
}
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
{
connection = dataSource.getConnection();
}
catch (SQLException e)
{
e.getMessage();
}
return connection;
}
/**
@return
*/
public String getDesignation() {
return designation;
}
/**
@return
*/
public String getPhone1() {
return phone1;
}
/**
@return
*/
public String getEmailId() {
return emailId;
}
/**
@return
*/
public String getEmpId() {
return empId;
}
/**
@return
*/
public String getPhone2() {
return phone2;
}
/**
@return
*/
public String getName() {
return name;
}
/**
@return
*/
public String getPhotoPath() {
return photoPath;
}
/**
@return
*/
public String getTechnology() {
return technology;
}
/**
@return
*/
public String getLocation() {
return location;
}
/**
@param string
*/
public void setDesignation(String string) {
designation = string;
}
/**
@param string
*/
public void setPhone1(String string) {
phone1 = string;
}
/**
@param string
*/
public void setEmailId(String string) {
emailId = string;
}
/**
@param string
*/
public void setEmpId(String string) {
empId = string;
}
/**
@param string
*/
public void setPhone2(String string) {
phone2 = string;
}
/**
@param string
*/
public void setName(String string) {
name = string;
}
/**
@param string
*/
public void setPhotoPath(String string) {
photoPath = string;
}
/**
@param string
*/
public void setTechnology(String string) {
technology = string;
}
/**
@param string
*/
public void setLocation(String string) {
location = string;
}
/**
@return
*/
public byte[] getImage() {
return image;
}
/**
@param bs
*/
public void setImage(byte[] bs) {
image = bs;
}
/**
@return
*/
/**
@return
*/
public int getFlag() {
return flag;
}
/**
@param i
*/
public void setFlag(int i) {
flag = i;
}
public int flagValue()
{
return flag;
}
}
public class MyProfileBean
{
private String empId;
private String name;
private String technology;
private String designation;
private String emailId;
private String phone1;
private String phone2;
private String location;
private String photoPath;
private byte[] image;
private int flag;
private Connection connection;
private ResultSet rs;
static DataSource dataSource;
public MyProfileBean()
{
try
{
//code to look up the datasource
InitialContext initialContext = new InitialContext();
dataSource = (DataSource)initialContext.lookup("jdbc/aliasforradar");
}
catch (NamingException e)
{
e.getMessage();
}
}
public void SearchUser()
{
Connection connection = null;
try{
Statement st=connection.createStatement();
ResultSet rs=st.executeQuery("select * from Resource where Employee_Id=?");
if(rs!=null)
{
flag=1;
}else{
flag=0;
}
//System.out.println("result" +rs);
while(rs.next())
{
empId=rs.getString(1);
name=rs.getString(2);
technology=rs.getString(3);
designation=rs.getString(4);
emailId=rs.getString(5);
phone1=rs.getString(6);
phone2=rs.getString(7);
location=rs.getString(8);
photoPath=rs.getString(9);
}//end of while
rs.close();
st.close();
connection.close();
}catch(SQLException se)
{
se.printStackTrace();
se.getMessage();
}
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
{
connection = dataSource.getConnection();
}
catch (SQLException e)
{
e.getMessage();
}
return connection;
}
/**
@return
*/
public String getDesignation() {
return designation;
}
/**
@return
*/
public String getPhone1() {
return phone1;
}
/**
@return
*/
public String getEmailId() {
return emailId;
}
/**
@return
*/
public String getEmpId() {
return empId;
}
/**
@return
*/
public String getPhone2() {
return phone2;
}
/**
@return
*/
public String getName() {
return name;
}
/**
@return
*/
public String getPhotoPath() {
return photoPath;
}
/**
@return
*/
public String getTechnology() {
return technology;
}
/**
@return
*/
public String getLocation() {
return location;
}
/**
@param string
*/
public void setDesignation(String string) {
designation = string;
}
/**
@param string
*/
public void setPhone1(String string) {
phone1 = string;
}
/**
@param string
*/
public void setEmailId(String string) {
emailId = string;
}
/**
@param string
*/
public void setEmpId(String string) {
empId = string;
}
/**
@param string
*/
public void setPhone2(String string) {
phone2 = string;
}
/**
@param string
*/
public void setName(String string) {
name = string;
}
/**
@param string
*/
public void setPhotoPath(String string) {
photoPath = string;
}
/**
@param string
*/
public void setTechnology(String string) {
technology = string;
}
/**
@param string
*/
public void setLocation(String string) {
location = string;
}
/**
@return
*/
public byte[] getImage() {
return image;
}
/**
@param bs
*/
public void setImage(byte[] bs) {
image = bs;
}
/**
@return
*/
/**
@return
*/
public int getFlag() {
return flag;
}
/**
@param i
*/
public void setFlag(int i) {
flag = i;
}
public int flagValue()
{
return flag;
}
}
Hi,
When you print the values using message manager are these values coming. My guess is they are not.
Inside the Bean, the exception which are caught are not printed. Please use throw exception and see if the exceution of the bean has been successful.
Other than that, there is not anything special to make it work.
Regards
Bharathwaj
Hi Susmita,
I dont understand exactly what do you in fact want to do:
Would you like to give an employId and show employ detail info
or
would you like to show a table with employs info?
Possible that /people/balaramnaidu.bankuru/blog/2006/04/23/importing-complex-javabean-model-into-webdynpro-by-creating-relationships-for-the-model-classes help you.
Regards
Bogdan
Now i am able to dispaly the information.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.