Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF1.2 Core+AJAX+Portlets getting problematic while constructing the url

 
Ganesh Gadde
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I have written a sample application using JSF1.2 Core(without using richfaces/myfaces) which is using AJAX inside a Portal Environment(JSR 286,WebSphere Portal 6.1).

I have written java script inside my jsp/.xhtml file which will ajaxify and invoke my servlet and give the response.while constructing the url ,it is getting problematic.I am not getting the status of xmlHttpRequest,able to get the xmlHttpRequest.readyState.Please give me comments/suggestions on this.

this is my .xhtml/jsp

<script type='text/javascript'>
function getXMLObject() //XML OBJECT
{
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") // For Old Microsoft Browsers
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") // For Microsoft IE 6.0+
}
catch (e2) {
xmlHttp = false // No Browser accepts the XMLHTTP Object then false
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest(); //For Mozilla, Opera Browsers
}
return xmlHttp; // Mandatory Statement returning the ajax object created
}

var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax object

function ajaxFunction() {
var getdate = new Date(); //Used to prevent caching during ajax call
if(xmlhttp) {
xmlhttp.open("GET","gettime?"+ getdate.getTime(),true); //gettime will be the servlet name
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(null);
}
}

function handleServerResponse() {
if (xmlhttp.readyState == 4) {

if(xmlhttp.status == 200) {
alert("######## ready state val#########" +xmlhttp.status);
document.myForm.time.value.innerHTML=xmlhttp.responseText; //Update the HTML Form element
}
else {
alert("Error during AJAX call. Please try again"+xmlhttp.responseText);
}
}
}
</script>
<body>

<div class="home-container">
<h:form id="myForm">
<f:view>

Server time
<h:inputText id="time"/>

<h:commandLink value="click this button..." onclick="ajaxFunction()"/>
<div id="msg">


xmlhttp.open("GET","gettime?"+ getdate.getTime(),true); // think this line getting problematic

gettime is my servlet class name.I have configured this in web.xml properly

 
Komari raj
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ganesh,

check clealry url which is specified in you method as shown in below.

xmlhttp.open("GET","gettime?"+ getdate.getTime(),true);

"gettime?"+ getdate.getTime()" this is wrong url format

you need to include requestparameter variable name with this url....

url="gettime?time="+getdate.getTime();

here time is request parameter for accessing time from jsp to servlet.

i hope this will solve your problam.


Regards
Raju
 
Ganesh Gadde
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raj,

Thanks for quick reply.

One of my concern is if i have not used the request paremeter called "time"

then the content should be like this
xmlhttp.open("GET","gettime?"true); //gettime will be the servlet name

is it the rightway,correct me if i was wrong.

-Thanks
 
Komari raj
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi ganesh

please remove '?' from that url as shown in below..




Regards
raju

 
Ganesh Gadde
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yep.Thanks Raj
 
Komari raj
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome Ganesh,


Reagrds
Raj
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic