This discussion is archived
8 Replies Latest reply: Nov 14, 2012 12:34 PM by 745915 RSS

Field value not being written to database

745915 Newbie
Currently Being Moderated
Hello,

I'm trying to auto-populate a form field from a value in one of my backing beans by changing the field value property from #{bindings.Modifiedby1.inputValue} to #{pageFlowScope.backing_Login.userName}. When I open the form, the correct value from the backing bean is displayed in the field now, but when I save/commit the record the value doesn't make it to the database so while it is displayed on the screen in the form field, it doesn't get written to the database. Is there something that needs to be done to update the input value in the actual binding or something? I'm developing in JDeveloper 11.1.1.3.

Thanks!
  • 1. Re: Field value not being written to database
    Timo Hahn Oracle ACE
    Currently Being Moderated
    Well, the "#{bindings.Modifiedby1.inputValue}" stands for the db attribute so when you changed this to #{pageFlowScope.backing_Login.userName} you strore the value in the bean property and not the db.

    Please tell us what you are trying to do, so we can give an advice on how to fix it.

    Timo
  • 2. Re: Field value not being written to database
    745915 Newbie
    Currently Being Moderated
    I have a login page with a backing bean that captures and stores the user name of the logged in person. After logging in, when the user then opens a form to add a new record I have an "Updated By" field that's set to read-only on the form that I want to auto-populate with the user name from the login backing bean so that I can capture the user name of the person who updated the record when it's saved. Does that make sense?
  • 3. Re: Field value not being written to database
    Timo Hahn Oracle ACE
    Currently Being Moderated
    Yes, this makes more sense.
    If you user Adf security you can use the build in mechanism called history columns which will do that for you.
    Of not you can add a SetPropertyListener on the save button. This you use to copy the value from the bean to the binding. Leave the update by field pointing to the bean to display the user name. Only when the user clicks on save the value gets copied to the binding value.

    Timo
  • 4. Re: Field value not being written to database
    745915 Newbie
    Currently Being Moderated
    My form is inside of a popup dialog box with "OK" and "Cancel" buttons assigned to the dialog box. I already have some backing bean code that forces a commit when the "OK" button is selected (see backing bean code below), can I just add a line of code in here to set the binding value for the Updated By field before the line of code that forces the commit, and if so, can you tell me what the line of code to set the binding value would need to be?

    public void editDialogListener(DialogEvent dialogEvent){
    if (dialogEvent.getOutcome().name().equals("ok")){
    BindingContainer bindings = getBindings();
    OperationBinding operationBinding = bindings.getOperationBinding("Commit");
    operationBinding.execute();
    }
    }
  • 5. Re: Field value not being written to database
    Timo Hahn Oracle ACE
    Currently Being Moderated
    Yes, you can set the value from your bean as
    // get an ADF attributevalue from the ADF page definitions
    AttributeBinding attr = (AttributeBinding)bindings.getControlBinding("Modifiedby1");
    attr.setInputValue("GET THE USERNAME FROM THE USER BEAN HERE");
    Timo
  • 6. Re: Field value not being written to database
    745915 Newbie
    Currently Being Moderated
    Excellent, I'll give that a shot. Thank you very much for your help!
  • 7. Re: Field value not being written to database
    745915 Newbie
    Currently Being Moderated
    That worked. Thanks again!
  • 8. Re: Field value not being written to database
    745915 Newbie
    Currently Being Moderated
    Well, I thought it was working. I've found that the ModifiedBy and ModifiedDate fields do get updated in the database now, but it updates those two fields in the first row that was displayed on the table instead of the row that was selected. Here's my backing bean code (I've tried to comment what I'm doing in each step):

    public void editDialogListener(DialogEvent dialogEvent) {
    //when "ok" button in dialog box is selected
    if (dialogEvent.getOutcome().name().equals("ok")) {
    //get userName from Login backing bean and save as loggedInUser
    RequestContext requestContext =
    RequestContext.getCurrentInstance();
    String loggedInUser =
    (String)requestContext.getPageFlowScope().get("userName");

    //get bindings
    BindingContainer bindings = getBindings();

    //get Modifiedby1 attribute from bindings and setInputValue to LoggedInUser
    AttributeBinding attrModifiedBy =
    (AttributeBinding)bindings.getControlBinding("Modifiedby1");
    attrModifiedBy.setInputValue(loggedInUser);

    //get Modifieddate1 attribute from bindings and setInputValue to current date
    AttributeBinding attrModifiedDate =
    (AttributeBinding)bindings.getControlBinding("Modifieddate1");
    attrModifiedDate.setInputValue(new Date());

    //perform Commit
    OperationBinding operationBinding =
    bindings.getOperationBinding("Commit");
    operationBinding.execute();
    }
    }

    Can anyone see what I need to add or do differently to grab the selected row's attributes for updating?

Legend

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