Showing posts with label Article. Show all posts
Showing posts with label Article. Show all posts

Friday, June 01, 2007

AJAX SAMPLE

In simple terms Ajax, is plain old JavaScript, with the

ability to do asynchronous http requests, this requests are mainly XML (therefore
the name Asynchronous JavaScript and XML), however we can user the XMLHttpRequest object to get virtually any kind of document.

The JavaScript communicates with the web server

independently of the rest of the page (Asynchronously) allowing the us to get or
modify only small portion of the page making it faster and more efficient than
bringing the whole thing again every time the user changes something.

The first thing to do is to create the

XMLHttpRequest object, there are some different between who IE and other
browsers do this, so you need to validate the user's current browser



function getXMLHTTPObject()
{
try
{
req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try{req = new ActiveXObject("Microsoft.XMLHTTP");}
catch(e2) { req = null;}
}
if(!req && typeof XMLHttpRequest != "undefined")
{ req = new XMLHttpRequest(); }
return req;
}

Then you create the a function that uses the object to
make a request, this function will be the one you call on your HTML, for example
when the users clicks a button or changes a form field.

The first thing is to get the object,

XmlHttp= getXMLHTTPObject();

After that, you define what you want to do after the

request has been made, usually you will call a JavaScript function to receive
the response and then change your page accordingly

XmlHttp.onreadystatechange="doSomething"

Then, you define the request, for example, you can call a

java servlet that will return the new html depending in a parameter, you can
pretty much call anything here as long as it returns either HTML (text) , or XML

You can do your request either through GET or POST with

GET, you can pass the paramenters in the URL of the request:

XmlHttp.open("GET","/apps/getContent.jsp?param2=123&param2=ABC"
,true);
XmlHttp.send(null);

Or you can use POST, for this you need to define the header of the request and the values:

XmlHttp.open("POST", "/apps/getContent.jsp",true);
XmlHttp.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");

XmlHttp.send("param2=123&param2=ABC");

After the request has been made, and a we have response, it's up to normal JavaScript to do the modifications to the HTML DOM of the page, a pretty common technique is to use the innerHTML property on DIV elements, you use XmlHttp.readyState and XmlHttp.status to know when the request has been finalized (readyStae=4) and to get the HTTP response code (success=200)

function doSomething()
{
if (XmlHttp.readyState == 4 &&
(XmlHttp.status==200 || XmlHttp.status ==0))
{
document.getElementById("div_changing").innerHTML = XmlHttp.responseText;
}
}

Here is a full sample (4 files)

region1.txt

|jsmith, John Smith|pperez, Pedro Perez|JDoe, Joe Doe

region2.txt

|jblack, John Black|jmorrison, Jim Morrison|fsinatra,
Frank Sinatra

view_divcontent.html

<h2>Changed Div Content</h2>

sample.html

<html>
<body>
<script language = "Javascript">
var XmlHttp=null;
function getXMLHTTPObject()
{
try
{
req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try{req = new ActiveXObject("Microsoft.XMLHTTP");}


catch(e2) { req = null;}

}


if(!req && typeof XMLHttpRequest != "undefined")


{ req = new XMLHttpRequest(); }


return req;


}


function getSalesReps(region)


{


XmlHttp= getXMLHTTPObject();


if(XmlHttp)


{


try
{


var directory = ""+document.location;


directory = directory.substr(0, directory.lastIndexOf('/'));


XmlHttp.onreadystatechange = fillSalesRep;


XmlHttp.open("GET",directory+"/"+region,true);


XmlHttp.send(null);


}


catch(e)


{


alert(e);


}


}


}


function getApprovers()


{


XmlHttp= getXMLHTTPObject();


if(XmlHttp)


{


XmlHttp.onreadystatechange = updateApprovers;


XmlHttp.open("POST", "view_divcontent.html",true);


XmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");


XmlHttp.send(getquerystring());


}


}




function updateApprovers()


{


if (XmlHttp.readyState == 4 && (XmlHttp.status==200 || XmlHttp.status == 0))


{


document.getElementById("div_approvers").innerHTML = XmlHttp.responseText;


}


}


function getquerystring()
{


var form = document.forms["sp_req"];


var word = form.p_region_id.value;


qstr = "p_region_id=" + form.p_region_id.value;


qstr = qstr+"&p_category_id=" + "aslkhd";


return qstr;


}


function fillSalesRep()


{


var rep_select = document.forms["sp_req"].elements["p_sales_rep"];


if (XmlHttp.readyState == 4)


{


if (XmlHttp.status == 200 || XmlHttp.status == 0)


{


var response = XmlHttp.responseText;


var reps = response.split("|");


rep_select.length = 1;


rep_select.length = reps.length;




for (o=1; o < reps.length; o++)


{


var name = reps[o].split(",");


rep_select[o].text = name[1];


rep_select[o].value = name[0];


}


}


else


{


alert("Error populating Sales rep. \nStatus="+XmlHttp.status);


}


getApprovers();


}


}


</script>


<form name="sp_req">


<table>


<tr>


<td bgcolor="#EEEEDD" align="right"><b>Region: </font></b></td>


<td width="40%">


<select class="selectbox" name="p_region_id" onchange="javascript:getSalesReps(this.value);">


<option value=""> </option>


<option value="region1.txt">Region 1</option>


<option value="region2.txt">Region 2</option>


</select>


</td>


<td align="right" bgcolor="#EEEEDD" width="10%"><b>Account Rep/Manager:
</b></td>


<td width="40%">


<select class="selectbox" name="p_sales_rep">


<option value=""></option>


</select>


</td>


</tr>


</table>

</form>


<div id="div_approvers">Initial Content</div>

</body>

</html>

Saturday, July 08, 2006

Portal 10.1.4 and Item placeholders

Well, it’s been a while, cartman and I have been a bit busy and we haven’t be able to continue writing for the blog, but we still believe in the idea and that’s why I want to start updating again so we can create our little community and exchange ideas, tips, complains, jokes or anything we want, all in the name of the Oracle app server and the headaches and triumphs it causes us.

But now, to the point, I’ve been wanting to talk about the new version of Oracle Portal 10.1.4. It is still not part of any release as you’ll need to upgrade the repository of the 10G r2 app server version, and the portal for the release 3 hasn’t been release.

The reason why I believe this new version of portal is important is a new feature that allows us to define templates for the items we upload. This html based templates are not something new in portal, we saw them on early release of webdb and portal for the portal providers (forms and reports within portal), and one of the best features of r2 was the ability to apply them to portal pages (I believe cartman has implemented a couple of sites in Colombia using this functionality). But in my opinion, being able to assign these templates to uploaded HTML files or text items will change the way companies use oracle portal to publish content on the web.

Let me explain, in my own experience, I have seen quite a few companies struggling to covert html pages into portal text items and put other portlets and customized content around them, them after that tedious process they struggle again to be able to migrate the same content from one environment to the other, I’ve hear some pretty convincing arguments against portal when the companies are coming from a static content to a personalised portal, of course we all know the advantages of a common gateway for all applications and the power of the portal tool, but plain html files that can be copied and pasted across any web server are just to simple and easy to argue.

One of the first things I have always said in favour of Oracle Portal is that companies should not try to replicate their current content into the portal, that doesn’t add value and just increase complexity and overheads to publish content, instead companies should explore the customised services portal provides and combine them with their existing static content, but again Oracle’s sales speech are sometimes too good to change the already sold minds of some CIO’s.

And here is where the new feature of items placeholders or templates, comes to play. Basically, it allows you to keep the content in html files, and then define a template, that can be a mixt of html and some portlets you want around your content. After that you will simply map you webdav access to portal as network drive on your pc and copy and paste the content in whatever environment you want. When you call the item, portal renders the item and displays it with the pre-defined template, showing a portal page, that can have customized content and which content is maintain as any other plain html site.

It’s probably easier to see it working; oracle has a nice OBE with the feature, check it out on http://www.oracle.com/technology/obe/obe1014portal/item_placeholders/itmplacehold.htm

Once again it is not the “one solution fits all” and I still believe we need to find the right solution for each problem not try to put it all in what oracle salesmen told us we should, nevertheless, if well applied, I do see a significant change on how companies manage their content and a lot of opportunities with this new portal. Let me know what you think.

Juan Becerra (Homer)

Wednesday, April 26, 2006

Oracle Portal. ..... . a mature product?

After analysing the proved new features indicated by Oracle Corporation on the Oracle Portal product, seems to me that the quarter from hour of this product has arrived. As important characteristics as the incorporation of WSRP and JSR 168 standards, because of this, the product leaves a side all those barriers of integration with other services and becomes a mature and interoperable product. It will be necessary to watch the support to standard JSR 170, we hope that it is soon to be incorporated (focused towards the strategy fusion of oracle).

Another important point is the opportunity to leave little by little the data base domain that the product has with the mod_PLSQL , Oracle has generated a service that emulates this module aiming for the possibility to said that the web server of the Portal application can be separated, with other characteristics as they are the one of true pool of connections in the data base and not fighting with numbers of sessions growing on it.

Cartman

Opening Note

Hi everyone and welcome to our page, cartman and I have been working with the Oracle app server since forever, and we though it would be a good idea to get a blog to post all the shortcuts and tech tips that we have found along the way.

I know by experience how frustrating the different tools of the app server can be, and how many near-suicidal experience some of you must have had working with them, but at the end of the day we still believe in the tool and we want to have a place where we can both bitch about it and also help us up with whatever new trick we discoverer.

So I hope you guys enjoy it and get involve so we can publish some interesting stuff here.

Homer