I have one question.
I write the following in a JSP file.
<s:url id="printURL" action="actMod" method="printout">
<s:param name="txt_ActEdit_accid"><s:property value="%{txt_ActEdit_accid}" /></s:param>
<s:param name="txt_ActEdit_accffname"><s:property value="%{txt_ActEdit_accffname}" /></s:param>
<s:set var="loginPassword"><%=OpeCommon.LOGIN_PASSWORD %></s:set>
<s:param name="%{#loginPassword}"><%=OpeCommon.encriptPassword(p_userID, p_passCode)%></s:param>
</s:url>
<s:submit name="btn_ActList_print" cssClass="dispLvl3 mediumbutton" value="%{getFieldName('S05AccountEdit.print_button')}"
onclick="javascript:popUp('%{printURL}','elastic',500,500);return false;"/>
I write the following in a js file.
var newWin = null;
function popUp(strURL, strType, strHeight, strWidth) {
if (newWin != null && !newWin.closed)
newWin.close();
var strOptions="";
if (strType=="console")
strOptions="resizable,height="+
strHeight+",width="+strWidth;
if (strType=="fixed")
strOptions="status,height="+
strHeight+",width="+strWidth;
if (strType=="elastic")
strOptions="toolbar,menubar,scrollbars,"+
"resizable,location,height="+
strHeight+",width="+strWidth;
newWin = window.open(strURL, 'newWin', strOptions);
newWin.focus();
}
it knows all parameter value but when I change the JavaScript function name and script coding, it does not work. I means it knows only first parameter value (txt_ActEdit_accid).
<s:submit name="btn_ActList_print" cssClass="dispLvl3 mediumbutton" value="%{getFieldName('S05AccountEdit.print_button')}"
onclick="javascript:printWindow('%{printURL}','',500,500);return false;"/>
function printWindow(x_URL, x_ARG, x_WIDTH, x_HEIGHT)
{
var x_OPT = "dialogHeight: "+x_HEIGHT+"px; "
+"dialogWidth: "+x_WIDTH+"px; "
+"edge: Raised; center: Yes; resizable: Yes; status: Yes;";
window.showModalDialog(x_URL, x_ARG, x_OPT);
}
How to fix this?
Now, you have the problem with s:url tag.
Struts tags usually escape the value of the tag. But it prevents the javascript to work correctly.
You need to add escapeAmp="false" to the s:url tag to get other parameters.
Related
I have to show two different banner in two different locations, first one is inside a thank you page and the second one is inside the confirmation email.
In both the case i need to print some info inside the urls.
In the first case the banner is generated by a script where i pass some values using Sling
<sly data-sly-use.data="........controller.BookingFormModificaController"></sly>
<sly data-sly-use.booking=".......controller.BookingConferma"></sly>
<div id='b_container'>
<script type = 'text/javascript' id='sp_widget' data-hash='00000' datacontainer='b_container' data-size='1080x500' data-tpncy='false' src='example.com/js/booking_sp_widget.js?checkin=${ data.depDateOld }&checkout=${ data.retDateOld }&iata_orr=1&iata=${ data.arrivalAirport }&lang=${ booking.selectedLanguage }&selected_currency=${ booking.ctx.currency } '></script>
</div>
This is the result and is correct:
src="http://www.example.com/00000?fid=1540980292381&checkin=2018-12-17&checkout=2018-12-22&iata_orr=1&iata=MXP&lang=it&selected_currency=EUR&dsize=1080,500&dtpncy=false&dtsize=&dmsize="
In the second case (the email) is not a script but just an img with an a tag like below
<sly data-sly-use.data="........controller.BookingFormModificaController"></sly>
<sly data-sly-use.booking=".......controller.BookingConferma"></sly>
<a href="https://example.com/searchresults.it.html?aid=1503416&checkin=${ data.depDateOld }&checkout=${ data.retDateOld }&iata_orr=1&iata=${ data.arrivalAirport }&lang=${ booking.selectedLanguage }&selected_currency=${ booking.ctx.currency }">
<img src="https://via.placeholder.com/1080x300" width="100%" alt="" style="margin:0; padding:0;border:none;display:block;" />
</a>
but in this case, after the email is sent, it has the following url:
href="https://example.com/searchresults.it.html?aid=1503416&checkin=&checkout=&iata_orr=1&iata=&lang=&selected_currency="
My goal is generate an URL like the first one.
When attaching queryParameter to a link in HTL/Sightly you can easily use the build in link builder. Simply build a Map in a SlingModel you are good to go.
HTL
<a class="a-link" href="${ myModel.linkPath # extension='json', query=myModel.queryParameterMap }">...</a>
Sling Model
public static Map<String, String> getQueryParameterMap(final Page currentPage)
{
final Map<String, String> map = new HashMap<>();
if (Objects.nonNull(currentPage))
{
map.put("someParameterA", "someValueA");
map.put("someParameterB", "someValueB");
}
return map;
}
I have a jsp page , from which I am getting the list of the checkboxes selected by a user.
And as per the selected checkboxes I want to call my controller using the jQuery.
<input type="checkbox" name="XYZ" value="hello1"/>Hello1<br>
<input type="checkbox" name="XYZ" value="hello2"/>Hello2<br>
I obtained all the values in the jQuery and set all the parameters into a variable as given below.
var allVals = [];
$("input[name=XYZ]:checked").each(function() {
allVals.push($(this).val());
});
and I am using an AUI to call my controller, I am passing the value as parameter.
AUI().use('aui-base',
'aui-io-request',
'liferay-portlet-url',
function(A) {
var A = AUI();
var myResourceURL = Liferay.PortletURL.createResourceURL();
myResourceURL.setResourceId('getABC');
myResourceURL.setParameter("action",'ZYX');
myResourceURL.setPortletId(pid);
myResourceURL.setParameter("list",allVals);
A.io.request(myResourceURL.toString(),
{
method : 'post',
dataType : 'text',
on : {
start : function() {
.
.
.});
And in my controller I want to obtain the list and my controller is like this:
System.out.println(request.getParamter("list"));
This statement is just giving me the first selected element, not the complete list of the elements.
Is there something I am missing , or any other way to do it??
I think you will need to go with 'getParameterNames()' instead http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#getParameterNames()
Hope it helps
I have a ppc landing page that I want to change the hidden value of a form field based on the URL parameter.
The field
<input id="Campaign_ID" name="Campaign_ID" type="hidden" value="7g012455dv5441vdf">
The URL would be something like mysite.com/?campaignidvalue=7g012455dv5441vdf
There will be other field "values" that are also based on the URL parameter, so it has to tie the "input id" (or name) to that specific value.
EDIT: There was an error in my code.
PHP would be the easiest!
<?php
if(!empty($_GET['campaignidvalue']))
{
echo '<input id="Campaign_ID" name="Campaign_ID" type="hidden" value="'. $_GET['campaignidvalue'].'"/>';
}
?>
This block will check to see if the value is passed in a GET parameter, and then echo it out into a hidden form field.
The first part:
if(!empty($_GET['campaignidvalue']))
Is checking to see if a parameter named Campaign_ID is being passed.
So your URL of:
mysite.com/?campaignidvalue=7g012455dv5441vdf
Would allow the code to continue, as it is not empty.
This section is the part that actually displays it on the page.
echo '<input id="Campaign_ID" name="Campaign_ID" type="hidden" value="'. $_GET['campaignidvalue'].'"/>';
If you view the source of the HTML page, you would see
By using this function:
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null) {
return "";
} else {
return decodeURIComponent(results[1]);
}
}
You'll be able to get any URL parameter by name, like so:
var cid = getParameterByName(campaignidvalue);
Then, once you have the value you can use jQuery to set it, like so:
$(function() {
$("#Campaign_ID").val(cid);
});
I am trying to create a form using java script, the form is created but the dynamic param values to the form are not replaced. The following is my form....
var formVar='<form:form name="service_form" commandName="command1" action="/serviceProcess" method="post">';
formVar+='<label for="'+ paramsdata[2] + '">'+paramsdata[3]+'</label><br/>';
formVar+='<form:input type='+paramsdata[2]+' path="webParamMap['+paramsdata[2]+'].webValue" value='+ paramsdata[5] +' class="input"></form:input><br>' ;
formVar+='<label for=" '+paramsdata[2]+' ">'+paramsdata[3]+'</label><br/>';
formVar+='<div id="select">';
formVar+='<form:select path="webParamMap[' +paramsdata[2] + '].webValue">';
formVar+='<form:option value='+paramdata[8]+'>'+paramdata[9]+'</form:option>';
formVar+='</form:select></div>';
formVar+='</form:form>';
In the above form the label tag values(dynamic param values) are updated but the form:input and select tag values(dynamic param values) are not updated in the output.
please help me how to create these tags with dynamic parameters ?
JAVA != JAVASCRIPT
Notice:
<form:form>
This is server-side Java.
Your Javascript is client-side only.
With following script each element is getting its right value. I wonder why are you using "
<script>
var paramsdata = new Array();;
paramsdata[2]='param2';
paramsdata[3]='param3';
paramsdata[5]='param5';
paramsdata[8]='param8';
paramsdata[9]='param9';
var formVar='<form:form name="service_form" commandName="command1" action="/serviceProcess" method="post">';
formVar+='<label for="'+ paramsdata[2] + '">'+paramsdata[3]+'</label><br/>';
formVar+='<form:input type='+paramsdata[2]+' path="webParamMap['+paramsdata[2]+'].webValue" value='+ paramsdata[5] +' class="input"></form:input><br>' ;
formVar+='<label for=" '+paramsdata[2]+' ">'+paramsdata[3]+'</label><br/>';
formVar+='<div id="select">';
formVar+='<form:select path="webParamMap[' +paramsdata[2] + '].webValue">';
formVar+='<form:option value='+paramsdata[8]+'>'+paramsdata[9]+'</form:option>';
formVar+='</form:select></div>';
formVar+='</form:form>';
document.body.innerHTML = formVar;
</script>
<script>
//helper function to create the form
function getNewSubmitForm(){
var submitForm = document.createElement("FORM");
document.body.appendChild(submitForm);
submitForm.method = "POST";
return submitForm;
}
//helper function to add elements to the form
function createNewFormElement(inputForm, elementName, elementValue){
var newElement = document.createElement("<input name='"+elementName+"' type='hidden'>");
inputForm.appendChild(newElement);
newElement.value = elementValue;
return newElement;
}
//function that creates the form, adds some elements
//and then submits it
function createFormAndSubmit(){
var submitForm = getNewSubmitForm();
createNewFormElement(submitForm, "field1", "somevalue");
createNewFormElement(submitForm, "field2", "somevalue");
submitForm.action= "someURL";
submitForm.submit();
}
</script>
<input type="button" value="Click to create form and submit" onclick="createFormAndSubmit()">
<% if(empRecNum != null && !(empRecNum.equals("")))
{
empSelected=true;
}
boolean canModify = UTIL.hasSecurity("PFTMODFY") && empSelected;
%>
<script type="text/javascript">
function add(){
alert('hello');
df('ADD');
}
</script>
On the click of add button, i need to pass the boolean value to another jsp and then go on with the df servlet function.
pass in URL like
second.jsp?param=value
access param from second jsp
request.getParameter("param");
OR:
Store it in cookie
OR:
Persist it in DB
I found this, which may help:
http://www.exampledepot.com/egs/javax.servlet.jsp/caller.jsp.html