cancel
Showing results for 
Search instead for 
Did you mean: 

How to display the information

susmita_panigrahi
Active Participant
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

susmita_panigrahi
Active Participant
0 Kudos

Hi Bogdan,

I will try this out.

susmita_panigrahi
Active Participant
0 Kudos

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.

Former Member
0 Kudos

Hi,

Can you paste the whole code including the ones where you are setting the context attributes. ?

Have you message manager to print the data which is comin in ?

Is that part working properly ?

Regards

Bharathwaj

susmita_panigrahi
Active Participant
0 Kudos

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;

}

}

Former Member
0 Kudos

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

Former Member
0 Kudos

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

susmita_panigrahi
Active Participant
0 Kudos

Hi

In the MyprofileCompView I am giving a employee id ,if it is a valid id then it will show all the information of that employee from the data base in the Result View.

susmita_panigrahi
Active Participant
0 Kudos

Hi Bharatwaj

yes you are right.While i am trying to print the value using message manage null is printing.

Former Member
0 Kudos

Hi,

It works then isn't it ?

In case if its a invalid id.. its not displaying.. ??? Is this your query ???

Maybe it throws an exception and u r not printing it..

Regards

Bharathwaj

susmita_panigrahi
Active Participant
0 Kudos

Hi Bhardwaj

yes my query is if it is not a valid id it will display messge not a valid id and if it is valid then dispaly all the information

Former Member
0 Kudos

Oops.. !

If its a valid id.. is the data coming ?

If its a invalid id .. is the message coming ?

Which state is not working ?

In case of a valid id .. if message manager prints null.. there must be some error in the query execution or connection itself .

susmita_panigrahi
Active Participant
0 Kudos

Hi

When i am giving valid id and try to print it is printing null.

When i am giving invalid id , it will taken that id and display in the TextView of Resultview

Former Member
0 Kudos

Its a problem with the connection or query execution..

Check that part

susmita_panigrahi
Active Participant
0 Kudos

Hi Bhardwaj,

Thanks a lot.I will check the DB connection.

Answers (1)

Answers (1)

susmita_panigrahi
Active Participant
0 Kudos

Now i am able to dispaly the information.