1 2 Previous Next 16 Replies Latest reply: Aug 22, 2012 3:52 AM by Ajay Sharma RSS

    Query on EO Object

    Ajay Sharma
      Hello Gurus..

      I have a requirement. I have a EO - "InsertDeviceDetailsEO"; VO - "InsertDeviceDetailsEOView" and AM - "DeviceDetailsAM"

      I have a Page DeviceDetails with a button "CreateDevice". When user clicks on this button a new page is open for entering devicedetails.

      In this page I am not showing a database field DEVICEID but i want that when user enters other details ans click on "Apply" button this id will be automatically generated and stored in the database table with all user entered field.

      How to achieve this ?


      Regards
      Ajay Sharma

      Edited by: Ajay Sharma on Aug 13, 2012 2:52 PM
        • 1. Re: Query on EO Object
          Ajay Sharma
          Hello Gurus..


          I am waiting for this issues.. Please Reply :)



          Thanks
          Ajay
          • 2. Re: Query on EO Object
            919822
            Hi,

            Create a sequence in Oracle and use below logic.

            public void create(AttributeList attributeList)
            {

            super.create(attributeList);

            OADBTransaction transaction = getOADBTransaction();
            Number employeeId = transaction.getSequenceValue("FWK_TBX_EMPLOYEES_S");
            setEmployeeId(employeeId);

            } // end create()

            Check Create Page tutorial for more details.

            Thanks,
            Venkat.
            • 3. Re: Query on EO Object
              Ajay Sharma
              Hi Venket..

              Thanks for reply. Will test it and reply :)

              But I have some questions. I am new to OAF

              1. Where to use this code. In controller or AM or VO.
              2. Why to use super.create method.
              3. Which parameter i need to pass to getSequenceValue method.
              4. And how it will persists this data to database When user will click on apply button



              Regards
              Ajay Sharma

              Edited by: Ajay Sharma on Aug 14, 2012 6:26 PM
              • 4. Re: Query on EO Object
                Ajay Sharma
                Hi Venket..

                Please reply to my query...



                Regards,
                Ajay
                • 5. Re: Query on EO Object
                  933532
                  Hi Ajay,

                  1. Where to use this code. In controller or AM or VO.
                  ANSWER: we need to place this code in XXXXEOImpl.java

                  2. Why to use super.create method.
                  ANSWER: our EOImpl class extens super class OAEntityImpl, which will have base create method,
                  that's the reason we have to call super.create(attributeList).

                  3. Which parameter i need to pass to getSequenceValue method.

                  ANSWER: In the piece of code, we have
                  setEmployeeId(employeeId);

                  here, if your column name is "COLUMN1", then
                  setCOLUMN1(<sequence ID which you are getting from the previous line>);

                  4. And how it will persists this data to database When user will click on apply button.

                  ANSWER: Have a look on MVC Architecture, to get clear idea on this.

                  Regards,
                  Naren.
                  • 6. Re: Query on EO Object
                    Ajay Sharma
                    Thank You Naren and Venket :)

                    Will test it now.


                    Regards,
                    Ajay
                    • 7. Re: Query on EO Object
                      Ajay Sharma
                      Hi..

                      I created following method in my "InsertDeviceDetailsEOImpl"

                      ----------------

                      public void autoGenerateDeviceID(AttributeList attributeList)
                      {
                      /*
                      * Our InsertDeviceDetailsEOImpl class extens super class OAEntityImpl, which will have base create method,
                      * that's the reason we have to call super.create(attributeList).
                      */
                      super.create(attributeList);

                      OADBTransaction transaction = getOADBTransaction();

                      // Calling the Sequence stored in database
                      Number deviceId = transaction.getSequenceValue("xxios_device_details_s");

                      // setDeviceId method will set the auto generated device id to column DeviceId.
                      setDeviceId(deviceId);

                      } // end autoGenerateDeviceID()

                      -------------------

                      When I run the page, inserted data into fields and clicked on "Apply" button it shown me folloeing error.

                      -----------

                      Attribute DeviceId in DeviceDetailsAM.InsertDeviceDetailsVO1 is required

                      ------------------


                      Regards,
                      Ajay
                      • 8. Re: Query on EO Object
                        Ajay Sharma
                        Hello Gurus..


                        Please help me in this issue :)

                        Thanks and Regards,

                        Ajay Sharma
                        • 9. Re: Query on EO Object
                          Ajay Sharma
                          Hi..

                          I successfully generated DeviceId and Device code as page loads. Thanks to You.
                          '
                          I have one more issue.
                          In database table Device Code is Unique field.

                          In OAF page I auto generate device code so it will be unique but I also allowed user to edit this Device Code if he wish to.

                          If user enters a Device Code that is already present in database I am getting error " Attribute DeviceCode in DeviceDetailsAM.InsertDeviceDetailsEOView1 is required "
                          it is not user friendly error as user entered a Device Code no. Instead of this I want to show an error like
                          " Please Enter Unique Value for Device Code. The Value you entered in Already Present" . ( is it a appropriate message ?? )

                          Waiting for reply :)


                          Regards,
                          Ajay
                          • 10. Re: Query on EO Object
                            933532
                            Hi Ajay,

                            When user click on "Apply" button, get the device code value from the page &
                            check with the existing device codes from the table.
                            If this value is (Page Value) is same as table value, then throw the Exception
                            with the Message you wish.

                            Regards,
                            Naren.
                            • 11. Re: Query on EO Object
                              Ajay Sharma
                              Hi Naren,

                              Thanks.
                              But how to check it with table value as there will be n number of records in table. how to iterate through each row in table. and compare this.




                              Regards,
                              Ajay
                              • 12. Re: Query on EO Object
                                933532
                                Hi Ajay,

                                No need iterate with each & every row. Eg: page is having device code as "D1", then write a query like select..... from Table where devicecode = D1, if it returns record means already D1 is present in table else happily we can save.

                                Regards,
                                Naren.
                                • 13. Re: Query on EO Object
                                  Ajay Sharma
                                  Hi Naren,

                                  Thanks..

                                  Somewhere I read that its good practice to create methods in AM and call that method from controller.

                                  So i created one method in my AM validateFields().

                                  No i want to call this method from my controller by passing device Code to it. How to it ?
                                  As am.invokeMethod() ; dnt allow this ?




                                  Regards
                                  Ajay
                                  • 14. Re: Query on EO Object
                                    Ajay Sharma
                                    Hi Naren,

                                    Here is my code..

                                    Still it giving me standard error not user defined error.

                                    ------------------------------------------------

                                    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
                                    {
                                    super.processFormRequest(pageContext, webBean);

                                    OAApplicationModule am = pageContext.getApplicationModule(webBean) ;

                                    if(pageContext.getParameter("Apply")!=null){

                                    String deviceCode = pageContext.getParameter("DeviceCode1");
                                    OADBTransaction transaction = am.getOADBTransaction();
                                    String query = "select Device_Code from XXIOS_DEVICE_DETAILS " +
                                    "where Device_code = "+deviceCode;
                                    ResultSet resultSet;
                                    int resultCount = 0;
                                    PreparedStatement preparedStatement = transaction.createPreparedStatement(query,0);

                                    System.out.println("Prepared Staement Created = "+ preparedStatement);

                                    try{

                                    resultSet= preparedStatement.executeQuery();
                                    System.out.println("Result Set Created = "+ resultSet);
                                    while(resultSet.next()){
                                    if(resultSet.getString("Device_Code").equalsIgnoreCase(deviceCode));
                                    throw new OAException ("Device Code is Already Present. Please Provide Unique Device Code");
                                    }// end while
                                    }// end try
                                    catch(Exception e){

                                    throw new OAException (e.getMessage(),OAException.ERROR);

                                    }// end catch

                                    }// end main if


                                    //am.invokeMethod("validateData");
                                    am.invokeMethod("insertDataToDeviceDetailsTable") ;
                                    }



                                    Regards,
                                    Ajay
                                    1 2 Previous Next