My requirement was to have a input text box value submitted with enter key - without clicking any
button, invoke business logic and stay on the same page.
This is how it can be achieved
Firstly, I added valueChangeListener to the input box and associated it with a method in a managed
bean
Page XML:
add these
attributes to inputText tag
valueChangeListener="#{myBean.myMethod}"
onkeypress="return submitme()"
Secondly, I added JavaScript to the page, for submitting the form on click of enter key,
I have to name the form as myform in order to make this script work.
JavaScript
function submitme() {
if (window.event.keyCode == 13)
{
document.myform.submit();
} else {
return false;
}
}
And finally, this is the backing bean code. Here I am calling gobutton_action method, which will take
care of the business logic that needed to be invoked on submit. I can bind it with the a method of
the Application Module. You can write a code that invokes an AppModule method.
myBean.java
public void myMethod(ValueChangeEvent valueChangeEvent)
{
System.out.println("I am in Bean");
gobutton_action();
}
Now I can enter value in the textbox and hit enter key to submit the value.
22 June 2009
Access DBTransaction from ManagedBean in Oracle ADF
Oracle ADF - How to access DBTransaction from ManagedBean
situation one is, You have ADFUtils classes
You can Borrow ADFUtils classes from SRDemo application, which you can freely download,
ADFUtils and JSFUtils are extremely useful.
The second situation is, If you don't have ADFUtils Classes
FacesContext ctx = FacesContext.getCurrentInstance();
ValueBinding vb = ctx.getCurrentInstance().getApplication().createValueBinding("#{data}");
BindingContext bc = BindingContext)vb.getValue(ctx.getCurrentInstance());
DataControl dc = bc.findDataControl("myServiceDataControl");
ApplicationModuleImpl am = ((ApplicationModuleImpl)(ApplicationModule)dc.getDataProvider());
Statement stmt = am.getDBTransaction().createStatement(0);
How to find out DataControl name :
While working on ADF project , there may be situation when we have to depend on plain old SQL query - for doing a specific job , and need to execute that SQL query right from the managed bean.
For executing the query we need to create a statement, and we have to access DBTransaction from within a managed bean.
Following code snippets will access DBTransaction in ManagedBean
There are two ways to access the DBTransaction from managed bean
situation one is, You have ADFUtils classes
You can Borrow ADFUtils classes from SRDemo application, which you can freely download,
ADFUtils and JSFUtils are extremely useful.
ApplicationModuleImpl am = (ApplicationModuleImpl)ADFUtils.getApplicationModuleForDataControl("myServiceDataControl");
Statement stmt = am.getDBTransaction().createStatement(0);The second situation is, If you don't have ADFUtils Classes
FacesContext ctx = FacesContext.getCurrentInstance();
ValueBinding vb = ctx.getCurrentInstance().getApplication().createValueBinding("#{data}");
BindingContext bc = BindingContext)vb.getValue(ctx.getCurrentInstance());
DataControl dc = bc.findDataControl("myServiceDataControl");
ApplicationModuleImpl am = ((ApplicationModuleImpl)(ApplicationModule)dc.getDataProvider());
Statement stmt = am.getDBTransaction().createStatement(0);
How to find out DataControl name :
Open the DataBindings.cpx file and see the id attribute of the BC4JDataControl tag
Use your data control name when creating the DataControl object
here in this code I am using - BC4JDataControl id="myServiceDataControl"
Subscribe to:
Posts (Atom)