This discussion is archived
11 Replies Latest reply: Mar 2, 2013 11:52 PM by Subramanian Meyyappan RSS

how can I use Method in the bean

user222 Newbie
Currently Being Moderated
Hi every one

please I made a method in for example employees entity "EmployeesImpl"
the name of method getmax() it return number

how can I use it at the bean
for eaxmple when I want to press button give me the value from this method

sorry Iam still beginner

thanks in advance
  • 1. Re: how can I use Method in the bean
    Timo Hahn Oracle ACE
    Currently Being Moderated
    User, please tell us your jdev version!

    Can you give some more information about your use case?
    Are you using ADF business components? Or EJB?

    Timo
  • 2. Re: how can I use Method in the bean
    user222 Newbie
    Currently Being Moderated
    Thanks sir for your response

    my version
    oracle jdeveloper reales 1 (11,1,1,4,0)
    I use business component



    I make method

    this metod wrote at enitity "EmployeesImpl"


    public Number getMax() throws JboException
    {
    PreparedStatement stat=null;
    ResultSet rs=null;
    try {
    String sql="select max(EMPLOYEE_ID)+1 from EMPLOYEES";
    stat=getDBTransaction().createPreparedStatement(sql, 1);
    rs=stat.executeQuery();
    if (rs.next()) {
    return new Number (rs.getInt(1));
    }

    } catch (Exception e) {
    // TODO: Add catch code
    //e.printStackTrace();
    throw new JboException("error");
    } finally {
    try {
    rs.close();
    stat.close();

    } catch (Exception e) {
    // TODO: Add catch code
    //e.printStackTrace();
    }
    }
    // oracle.jbo.domain.Number
    return new Number (1);
    }

    }



    ----
    I made a jsf page
    and I put button at the page

    I want when press the button give me message contain the number which come from previous metod


    thanks my dear
  • 3. Re: how can I use Method in the bean
    Timo Hahn Oracle ACE
    Currently Being Moderated
    Looks like you are trying to implement some kind of primary key generator.
    This is a very bad practice. The way you try will get you duplicate values in a multi use environment.
    Next this is that it is already implemented in a way which guarantees that you don't get duplicate values. Check http://tompeez.wordpress.com/2011/09/02/using-groovy-expression-to-set-a-primary-key-with-a-sequence-number/ which shows how to use Groovy to get a primary key from a sequence.

    Timo
  • 4. Re: how can I use Method in the bean
    user222 Newbie
    Currently Being Moderated
    thanks dear for your replay

    I know this a mistake but I try to traing to improve my skills

    I try to learn as Iam say still beginner


    so try to help me in this task

    thanks again
  • 5. Re: how can I use Method in the bean
    user222 Newbie
    Currently Being Moderated
    ok
    I Try to write this code in button action


    ---------------------------------------
    public String cb2_action() {
    // Add event code here...
    try {


    FacesContext context=FacesContext.getCurrentInstance();
    Application app=context.getApplication();
    ValueBinding bind=app.createValueBinding("#{data.testAppModuleDataControl.dataProvider}");
    EmployeesImpl am =(EmployeesImpl)bind.getValue(context);
    Number n=am.getnMax();
    it11.setValue(n);
    FacesMessage message=new FacesMessage("the value" +" "+n);
    context.addMessage(null,message);
    } catch (Exception e) {
    // TODO: Add catch code
    // it11.setValue(111);
    FacesContext context=FacesContext.getCurrentInstance();
    FacesMessage message=new FacesMessage("problem");
    e.printStackTrace();
    context.addMessage(null,message);

    }
    return null;
    }


    but give me the message in the catch
    please help me
  • 6. Re: how can I use Method in the bean
    dvohra21 Oracle ACE
    Currently Being Moderated
    What is the exception message?
  • 7. Re: how can I use Method in the bean
    user222 Newbie
    Currently Being Moderated
    no exception message
    but the message "problem" in the sction catch appear
  • 8. Re: how can I use Method in the bean
    dvohra21 Oracle ACE
    Currently Being Moderated
    Replace
    FacesMessage message=new FacesMessage("problem");

    with

    FacesMessage message=new FacesMessage(e.getMessage());
  • 9. Re: how can I use Method in the bean
    user222 Newbie
    Currently Being Moderated
    ok
    but I want message give me the value of n?


    i need the part of try>> execute
    not the part of catch
  • 10. Re: how can I use Method in the bean
    Timo Hahn Oracle ACE
    Currently Being Moderated
    Before getting into detail let me ask you if you have to use jdev 11.1.1.4.0?
    This version is a bit old and most developers are using 11.1.1.6.0 or 11.1.2.3.0.

    Timo
  • 11. Re: how can I use Method in the bean
    Subramanian Meyyappan Expert
    Currently Being Moderated
    this is to user,, you already went off "302" post. so you should know how phrase the question in forums. not like this....
    user says
    but I want message give me the value of n?
    i need the part of try>> execute
    not the part of catch
    if am getting you correctly means. you want to generate the employee id "automatically". if this is your requirement am strong suggested to go with timo suggested "db sequence"..coming to code part which you have . you had a method in implclass it should return the number ( i hope it would be employee id). so simple,
    1. expose the method
    2. try to bind the method which you had exposed in your pagedef
    3. call the methodaction in your bean. which you already binded in your pagedef.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points