Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Showing 21 - 23 of 23 results.
of 2
a g
RE: onclick event, i need to get the records from database
July 25, 2013 10:46 PM
Answer

a g

Rank: Expert

Posts: 409

Join Date: March 2, 2012

Recent Posts

Hello Manish,

I tried with your suggestion, but I can't succeed.

now I try without click like below in its working and it gone to the serverReource()

View.jsp
function getData(){


alert("calling ajax method getData()");

$(document).ready(function(){
alert("1");

var t02Travelfrom = $("#t02Travelfrom").val();
var t02Travelto=$("#t02Travelto").val();
var dataString4 = 'function=TravelDetails'+'&t02Travelfrom='+ t02Travelfrom+'&t02Travelto='+ t02Travelto;
alert("after dataString4");
if(t02Travelfrom!=0 && t02Travelto!=0)
{
$.ajax({

url: "${getTravelDetailsUrl}",
data: dataString4,
cache: false,
success: function(html)
{
var straaray= html.split("/");
$("#t02Landmark").val(straaray[0]);
$("#t02Totalkm").val(straaray[1]);
alert("success value of straaray[0]--->"+$("#t02Landmark").val(straaray[0]));
}
}); return false;
}else
{
$("#t02Landmark").val("");
$("#t02Totalkm").val("");

alert("value of "+$("#t02Landmark").val(""));
alert("value of "+$("#t02Totalkm").val(""));
}


});
}


Traveldetails.java

public void serveResource(ResourceRequest resourceRequest,ResourceResponse resourceResponse)
throws IOException, PortletException {

System.out.println("********inside serveResource()********");
String cmd = ParamUtil.getString(resourceRequest, Constants.CMD);
if (cmd.equals("2")){
try {
System.out.println("*********inside try in serveResource()***********");
GetTravelDetails(resourceRequest, resourceResponse);
} catch (SystemException e) {

e.printStackTrace();
}
}

}


public void GetTravelDetails(ResourceRequest request, ResourceResponse response) throws SystemException {

System.out.println("********inside GetTravelDetails()********");


/*RenderRequest renderRequest = null;*/

String tfrom =request.getParameter("t02Travelfrom");
String tto = request.getParameter("t02Travelto");

System.out.println("tfrom----->"+tfrom);
System.out.println("tto------->"+tto);

int count = EMP_TRAVEL_DETAILSLocalServiceUtil.getEMP_TRAVEL_DETAILSsCount();
List <EMP_TRAVEL_DETAILS> travelDetailLists = EMP_TRAVEL_DETAILSLocalServiceUtil.getEMP_TRAVEL_DETAILSs(0, count);

String t02Travelfrom;
String t02Travelto;
String t02Landmark;
int t02Totalkm;

String buffer;

for(EMP_TRAVEL_DETAILS travelList:travelDetailLists ){

t02Travelfrom=travelList.getT02Travelfrom();
t02Travelto=travelList.getT02Travelto();
System.out.println("t02Travelfrom----->"+t02Travelfrom);
System.out.println("t02Travelto----->"+t02Travelto);

if(tfrom.equals(t02Travelfrom) && tto.equals(t02Travelto)){

System.out.println("inside if condition");

t02Landmark=travelList.getT02Landmark();
t02Totalkm=travelList.getT02Totalkm();

buffer= t02Landmark +"/" + t02Totalkm ;
System.out.println("buffer values are----->"+buffer);
try {
System.out.println("*****inside try********");
response.getWriter().println(buffer);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

}


Now I try to get the value of what I typed, so that I can check the condition if the get value and database get value is same I can get the Landmark & TotalKm f

String tfrom =request.getParameter("t02Travelfrom");
String tto = request.getParameter("t02Travelto");

but i am getting, Plz see the screenshot.
tfrom----->undefined
tto------->undefined
Attachment

Attachments: dataString4.jpg (11.4k), view.jsp (12.6k)
a g
RE: onclick event, i need to get the records from database
July 26, 2013 12:06 AM
Answer

a g

Rank: Expert

Posts: 409

Join Date: March 2, 2012

Recent Posts

Hi,

Now I am getting the value of text field after I modify like below. Even I gave a textfield id but it is not taking. when I checked in the viewsource, in the id=_EmpTravelDetails_WAR_EmpTravelDetailsportlet_t02Travelfrom, so i used var t02Travelfrom=$("#<portlet:namespace />t02Travelfrom").val(); ,

function getData(){


alert("calling ajax method getData()");

$(document).ready(function(){
alert("1");


var t02Travelfrom=$("#<portlet:namespace />t02Travelfrom").val();
var t02Travelto = $("#<portlet:namespace />t02Traveltoid").val();



alert("Value of t02Travelfrom-->"+t02Travelfrom);
alert("Value of t02Travelto-->"+t02Travelto);

var dataString4 = 'function=GetTravelDetails'+'&t02Travelfrom='+ t02Travelfrom+'&t02Travelto='+ t02Travelto;
alert("after dataString4");
alert("value of dataString4"+dataString4);

if(t02Travelfrom!=0 && t02Travelto!=0)
{
$.ajax({

url: "${getTravelDetailsUrl}",
data: dataString4,
cache: false,
success: function(html)
{
var straaray= html.split("/");
$("#t02Landmark").val(straaray[0]);
$("#t02Totalkm").val(straaray[1]);
alert("success value of straaray[0]--->"+$("#t02Landmark").val(straaray[0]));
}
}); return false;
}else
{
$("#t02Landmark").val("");
$("#t02Totalkm").val("");

alert("value of "+$("#t02Landmark").val(""));
alert("value of "+$("#t02Totalkm").val(""));
}


});
}
a g
RE: onclick event, i need to get the records from database
July 26, 2013 2:38 AM
Answer

a g

Rank: Expert

Posts: 409

Join Date: March 2, 2012

Recent Posts

Hi,

I have written Jquery/Ajax and call serveResource() , & based on the condition i am getting the records and stored and sent to AJAX.

TravelDetails.java

public void GetTravelDetails(ResourceRequest request, ResourceResponse response) throws SystemException {

System.out.println("********inside GetTravelDetails()********");
.................
............
buffer= t02Landmark +"/" + t02Totalkm ;
System.out.println("buffer values are----->"+buffer);
try {
System.out.println("*****inside try********");
System.out.println("-----------------------");
response.getWriter().println(buffer);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


View.jsp:
if(t02Travelfrom!=0 && t02Travelto!=0)
{
$.ajax({

url: "${getTravelDetailsUrl}",
data: dataString4,
cache: false,
success: function(html)
{
var straaray= html.split("/");
$("#t02Landmark").val(straaray[0]);
$("#t02Totalkm").val(straaray[1]);

alert("success value of straaray[0]--->"+$("#<portlet:namespace />#t02Landmark").val(straaray[0]));---> display undefined
alert("success value of straaray[1]--->"+$("##<portlet:namespace />t02Totalkm").val(straaray[1]));
---> display undefined
}
}); return false;
}else
{
$("#t02Landmark").val("");
$("#t02Totalkm").val("");

alert("value of "+$("#t02Landmark").val(""));
alert("value of "+$("#t02Totalkm").val(""));
}
/* }); */

});


how to display in the view.jsp in the appropriate text fields

<aui:input name="t02Landmark" id="t02Landmarkid" type="text" label="" maxlength="15" value="" onclick="getData()">
<aui:input name="t02Totalkm" type="text" label="" maxlength="7" value="">


And I am getting the output in the console

********inside serveResource()********
*********inside try in serveResource()***********
********inside GetTravelDetails()********
tfrom----->Airport
tto------->BBcircle
t02Travelfrom----->Airport
t02Travelto------->BBcircle
*****inside if condition*****
buffer values are----->Aaa/20
*****inside try********
Showing 21 - 23 of 23 results.
of 2