Showing posts with label ADF. Show all posts
Showing posts with label ADF. Show all posts

Friday, February 03, 2006

ADF active data model

This link explains how a change to model is automatically notified to client in case of ADFBC, so that there is no need to transfer the data back and forth.

Thursday, October 13, 2005

ADF : Class Casting Exception with ApplicationModule

1. I have written my Base applicationmodule(say, CatalogApplicationModuleImpl) extending ApplicationModuleImpl in my frameworkextension Project.
2. Then in the Model project which is dependent on this fwkextension project, I write my ApplicationModule(say, CatalogServiceImpl) extending CatalogApplicationModuleImpl.
3. Then I expose some of the methods of CatalogServiceImpl through a interface CatalogService to the DataAction classes in controller.
4. Now similar to AM, I've base controller CatalogDataForwardAction in fwkextension project which is extended by the actual dataaction classesin the viewController project. In the base controller i've the utility method:

protected CatalogApplicationModuleImpl getApplicationModule(String dataControlName,DataActionContext ctx)
{DCDataControl dc = ctx.getBindingContext().findDataControl(dataControlName);
if ((dc != null) && dc instanceof DCJboDataControl)
{return (CatalogApplicationModuleImpl) dc.getDataProvider();}
return null;}

5. This is the same method as in Toystore project of SMUENCH. The changeis I'm casting the CatalogServiceImpl(from dc.getDataProvider()) to itsbase class CatalogApplicationModuleImpl, so that I can invoke some methodson the base AM(CatalogApplicationModuleImpl) from the base controller(CatalogDataForwardAction). I need this since I'm writing some methods inthe base controller which need not be replicated in all the controllers implementing this class.
6. The problem is that the above casting fails. I understand that by the above I'm trying to cast a class to a Impl class which is not present in the client side(controller) and hence this exception. If that is the case, what is the wayI can access the methods in the base AM(CatalogApplicationModuleImpl)from the base controller(CatalogDataForwardAction)(these two classesare present in the fwkExtension project). i.e., how can I expose theCatalogApplicationModuleImpl to the controller(should I have to writethis Impl as implementing some interface and use that interface in thebase controller. If so, where should the base interface be created?
Thanks,Krishna.

ADF:Setting of who columns(Audit columns) in the Entity Object

Posted the following question in jdeveloper forum today
I have who columns like created_by, creation_date, last_update_date, last_updated_by etc., in the table(and so the entity object). These need to get set based on the user logged in. Currently, I'm achieving the same by following logic:
1. Wrote my own TransactionImpl extending DBTransactionImpl2 and registeredthe transaction factory to the application module.
2. In my transactionImpl, there is a setter method: public void setUserId(int userId)
3. I've a filter to redirect the user to login page if not logged in. In the filter Istore the userid in the session, if user is authenticated.
4. Everytimein the DataAction PrepareModel phase, I invoke the methodsetUserId on the applicationModule passing the value from the session, whichsets the same in the TransactionImpl. Then in the EntityObject create method,I access this value to set the userId. I call the setter in all theaction class(so that if in the next request I get a different application moduleor a different transaction due to transaction/AM harvesting, the statevariable may be lost and hence in the preparemodel phase i explicity set them). Is this correct or any other way I can achieve the same
5. My next question is : how do I set these last_update_date and last_updated_by when the entity object is queried and changed. I can do thisin SetAttributeInternal Method(with a check that the index is not these twoattributes). However, this logic will then become tied to a particular entityobject. I want this logic to be written in my base class of EntityImpl so thatall EntityImpl extending my base EntityImpl will have this logic incorporatedautomatically.
Please let me know how can I acheive this.
Thanks,Krishna.

Friday, September 02, 2005

Struts html checkbox : unchecked is not getting posted

Recently posted a question in oracle jdeveloper forum :
If a struts html checkbox is unchecked, then when submitting this form containing this checkbox, the checkbox value is not getting posted. Hence, the same is not getting reflected in themodel. So, to post the unchecked value also, what should I do?
Got the reply:
Read the Struts newbie FAQ : http://struts.apache.org/faqs/newbie.html#checkbox

Wednesday, August 24, 2005

Form Submission

Form content types
The enctype attribute of the FORM element specifies the content type used to encode the form data set for submission to the server. User agents must support the content types listed below. Behavior for other content types is unspecified.
Please also consult the section on
escaping ampersands in URI attribute values.
application/x-www-form-urlencoded
This is the default content type. Forms submitted with this content type must be encoded as follows:
Control names and values are escaped. Space characters are replaced by
`+', and then reserved characters are escaped as described in [RFC1738], section 2.2: Non-alphanumeric characters are replaced by `%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character. Line breaks are represented as "CR LF" pairs (i.e., `%0D%0A').
The control names/values are listed in the order they appear in the document. The name is separated from the value by
`=' and name/value pairs are separated from each other by `&'.
multipart/form-data
Note. Please consult
[RFC2388] for additional information about file uploads, including backwards compatibility issues, the relationship between "multipart/form-data" and other content types, performance issues, etc.
Please consult the appendix for information about
security issues for forms.
The content type "application/x-www-form-urlencoded" is inefficient for sending large quantities of binary data or text containing non-ASCII characters. The content type "multipart/form-data" should be used for submitting forms that contain files, non-ASCII data, and binary data.
The content "multipart/form-data" follows the rules of all multipart MIME data streams as outlined in
[RFC2045]. The definition of "multipart/form-data" is available at the [IANA] registry.
A "multipart/form-data" message contains a series of parts, each representing a
successful control. The parts are sent to the processing agent in the same order the corresponding controls appear in the document stream. Part boundaries should not occur in any of the data; how this is done lies outside the scope of this specification.
As with all multipart MIME types, each part has an optional "Content-Type" header that defaults to "text/plain". User agents should supply the "Content-Type" header, accompanied by a "charset" parameter.
Each part is expected to contain:
a "Content-Disposition" header whose value is "form-data".
a name attribute specifying the
control name of the corresponding control. Control names originally encoded in non-ASCII character sets may be encoded using the method outlined in [RFC2045].
Thus, for example, for a control named "mycontrol", the corresponding part would be specified:

Content-Disposition: form-data; name="mycontrol"
As with all MIME transmissions, "CR LF" (i.e., `%0D%0A') is used to separate lines of data.
Each part may be encoded and the "Content-Transfer-Encoding" header supplied if the value of that part does not conform to the default (7BIT) encoding (see
[RFC2045], section 6)
If the contents of a file are submitted with a form, the file input should be identified by the appropriate
content type (e.g., "application/octet-stream"). If multiple files are to be returned as the result of a single form entry, they should be returned as "multipart/mixed" embedded within the "multipart/form-data".
The user agent should attempt to supply a file name for each submitted file. The file name may be specified with the "filename" parameter of the 'Content-Disposition: form-data' header, or, in the case of multiple files, in a 'Content-Disposition: file' header of the subpart. If the file name of the client's operating system is not in US-ASCII, the file name might be approximated or encoded using the method of
[RFC2045]. This is convenient for those cases where, for example, the uploaded files might contain references to each other (e.g., a TeX file and its ".sty" auxiliary style description).
The following example illustrates "multipart/form-data" encoding. Suppose we have the following form:

enctype="multipart/form-data"
method="post">


What is your name?

What files are you sending?



If the user enters "Larry" in the text input, and selects the text file "file1.txt", the user agent might send back the following data:
Content-Type: multipart/form-data; boundary=AaB03x

--AaB03x
Content-Disposition: form-data; name="submit-name"

Larry
--AaB03x
Content-Disposition: form-data; name="files"; filename="file1.txt"
Content-Type: text/plain

... contents of file1.txt ...
--AaB03x--

If the user selected a second (image) file "file2.gif", the user agent might construct the parts as follows:
Content-Type: multipart/form-data; boundary=AaB03x

--AaB03x
Content-Disposition: form-data; name="submit-name"

Larry
--AaB03x
Content-Disposition: form-data; name="files"
Content-Type: multipart/mixed; boundary=BbC04y

--BbC04y
Content-Disposition: file; filename="file1.txt"
Content-Type: text/plain

... contents of file1.txt ...
--BbC04y
Content-Disposition: file; filename="file2.gif"
Content-Type: image/gif
Content-Transfer-Encoding: binary

...contents of file2.gif...
--BbC04y--
--AaB03x--

Friday, July 22, 2005

ADF Event handling precedence

When an event named YourEvent fires, then...

If you have apublic void onYourEvent(DataActionContext ctx) method in the data action class handling the request, it will be invoked to handle the event with custom code.
If you have an action binding in the current binding container named YourEvent, it will be invoked.

When used in combination with 1, your event-handler code needs to explicitly invoke the default action for the current event by using code like:

if (ctx.getEventActionBinding() != null) ctx.getEventActionBinding().doIt();
If you have a Struts forward named YourEvent, it will be used to determine the next page to forward control to.

When used in combination with 1, if your event-handling code invokes ctx.setActionForward(), then your programmatically set forward takes precedence.

Thursday, July 21, 2005

ADF : Creating PreparedStatements

While creating preparedStatement from Application Module, it is better to not close them in a finally block. But, close them in the overridden remove() method of the AM by calling some method which will close all the local statements. Thus, will improve performance.

Sunday, May 22, 2005

Steps to dynamically bind a dynamically created view object

1. Expose the method recreateDynamicViewObjectWithNewQuery(String newSQL) to the client in the AM. This method will basically find the view object, remove it, create a new instance of vo from the query and executes the query:
findViewObject(DYNAMIC_VO_NAME).remove();
ViewObject vo = createViewObjectFromQueryStmt(DYNAMIC_VO_NAME,newSQL);
vo.executeQuery();
2. In the Client side(controller), override the prepareModel. The overriden method should
- unset the tokenvalidation through : ctx.getBindingContainer().setEnableTokenValidation(false);
- Unbind the rowsetIterator from the dynamicqueryiteratorbinding through : ctx.getBindingContainer(). findIteratorBinding(DYNAMIC_VO_ITER_NAME).bindRowSetIterator(null,false);
- call the method exposed by AM to bind the newSQL to the view object.
- remove the control binding by name. removeControlBinding(ctx,DYNAMIC_VO_RANGE);(basically remove the control binding from the iterator binding list and remove it from the binding container).
removeControlBinding:
---------------------------
DCBindingContainer bc = ctx.getBindingContainer();
DCControlBinding binding = bc.findCtrlBinding(name);
binding.getDCIteratorBinding().removeValueBinding(binding);
bc.removeControlBinding(binding);
- recreate the control binding and add it to the binding container:addDynamicRangeBinding(ctx,DYNAMIC_VO_RANGE, DYNAMIC_VO_ITER_NAME);
addDynamicRangeBinding
-------------------------------
DCBindingContainer bc = ctx.getBindingContainer();
JUCtrlRangeBinding dynamicRangeBinding =
new JUCtrlRangeBinding(null,bc.findIteratorBinding(iterName),null);
bc.addControlBinding(bindingName,dynamicRangeBinding);
- Execute super.prepareModel(ctx);
- Reset the tokenvalidation through : ctx.getBindingContainer().setEnableTokenValidation(true);

ADF - Dynamic rendering of UI irrespective of dataobjects

The following code in the view layer will render the dataobjects without any change in the view layer even though the view object gets re-constructed in the transaction.

<pre>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<c:forEach var="attributeLabel" items="${bindings.(voname).labelSet">
<th>
<c:out value="${attributeLable}" />
</th>
</c:forEach>
</tr>
<c:forEach var="Row" items="${bindings.(voname).rangeSet">
<tr>
<c:forEach var="attrValue" items="${Row.attributeValues}" >
<td>
<c:out value="${attrValue}" />
</td>
</c:forEach>
</tr>
</c:forEach>
</table>
</pre>

Basically the above code makes use of the labelSet and rangeSet properties of the VO object in the bindings and loop through them and print the same.

Thursday, May 19, 2005

JBO-30003

Getting this error:
oracle.jbo.common.ampool.ApplicationPoolException: JBO-30003: The application pool (model.AppModuleLocal) failed to checkout an application module due to the following exception:
Solution:
- May be the database is down. Bring it up.

Tuesday, May 17, 2005

Master-Detail design using ADF in uix page

In case the view layer is using UIX page, this requirement can even be simplified by dragging the child view object in view link with the option of Master to Detail(many to many). This will automatically take care of synchronization between master and details during navigation.

Simplest way to design Master-detail tables using ADF

Simplese way to design a master-detail table using ADF,
1. Create the master and detail entity objects. Create the appropriate association objects and view links.
2. Using the master view object in data control, create the master table.
3. Using the detail view object(present in view link) and create a child table
4. In the master table, add a column with ADF operation: setCurrentRowWithKey
that's it... now run the page, clicking on the select link in master will automatically refresh the child table(vo gets refreshed automatically by viewlink).

Conditional display of table data

This code snippet makes use of JSTL core taglib to display no data found if the table contains no records, else it display the records.

------------------------------------
<table border="1" width="100%">
<tr>
<th> </th>
<th>
<c:out value="${bindings.DummyView1.labels['Field1']}"/>
</th>
<th>
<c:out value="${bindings.DummyView1.labels['Field2']}"/>
</th>
<th>
<c:out value="${bindings.DummyView1.labels['Field3']}"/>
</th>
</tr>
<c:choose>
<c:when test="${bindings.DummyView1Iterator.estimatedRowCount>0}">
<c:forEach var="Row" items="${bindings.DummyView1.rangeSet}">
<tr>
<td>
<c:out value="${Row.currencyString}"/>
</td>
<td>
<c:out value="${Row['Field1']}"/> 
</td>
<td>
<c:out value="${Row['Field2']}"/> 
</td>
<td>
<c:out value="${Row['Field3']}"/> 
</td>
</tr>
</c:forEach>
</c:when>
<c:otherwise>
<tr>
<td colspan="4">no data found</td>
</tr>
</c:otherwise>
</c:choose>
</table>

Saturday, May 14, 2005

Question in ADF

I got this question: In a multi-page data entry flow where all the pages share the same underlying Entity Object, how should the entity level validation(validateEntity) be prevented until the user navigates to the final review and submit page. So, posted this question in a forum and got the response:
We have this SAME question.

We were thinking of:
1. add an attribute to the entity (not persistent) called pagenum

2. Expose this in the view

3. Expose in page as hidden value with the page# filled in

In validation methods (in EO) say:
public boolean validateEOfield1()
{
if thisFieldNeedsValidateOnPage( "field", getPageNum() )
{
// perform the validation logic here...
if ( thisFieldInError( "field" ) )
return false;
else
return true;
}

// if not on this page, then ...
// everything is ok
return true;

}

I haven't gotten very far with this idea and wanted to post a question, but I don't receive much feedback on my posts, so I wasn't sure what to do with it...

My Reply:
The above suggestion resolves the issue where the field validation is manually written by me in the EO. But, in case of declarative validations which I specify through Jdeveloper, how can I control the field validations.

One question here: model layer validations should be independent of the view layer right(either single/multi step). In this case, are n't we mixing the page flow logic
in our entity objects, which is a violation of MVC.

Instead, is it possible to get all the validation exceptions for all the EO's in the current transaction in the controller and check whether these exception can happen in the current page. If so, we will display these exceptions. Else, we will silently disregard these validation exceptions.

BC4J Entity States

Entity States in BC4J are as follows:
STATUS_INITIALIZED = -1
STATUS_NEW = 0
STATUS_UNMODIFIED = 1
STATUS_MODIFIED = 2
STATUS_DELETED = 3
STATUS_DEAD = 4