I want to get render parameter.
I wrote the following aui:script for opening new dialog. In that script I set parameter.
<input type="text" name="<portlet:namespace/>weburl" size="75: id="weburl" label="" inlineField="true" />
<aui:button name="btnPreview" id="btnPreview" value="Preview"/>
<aui:script>
AUI().use('aui-base','aui-io-plugin-deprecated','liferay-util-window','liferay-portlet-url', 'aui-dialog-iframe-deprecated', function(A) {
A.one('#<portlet:namespace />btnPreview').on('click', function(event){
alert(document.getElementById('weburl').value)
var strUrl=document.getElementById('weburl').value;
var renderURL =Liferay.PortletURL.createRenderURL();
renderURL.setParameter("nameUrl",strUrl);
renderURL.setParameter("mvcPath",'/html/view2.jsp');
renderURL.setPortletId("Portlets_WAR");
renderURL .setWindowState("pop_up");
alert(renderURL.toString());
var popUpWindow=Liferay.Util.Window
.getWindow({
dialog: {
centered: true,
constrain2view: true,
modal: true,
resizable: false,
width: 500
}
})
.plug(A.Plugin.DialogIframe, {
autoLoad: true,
iframeCssClass: 'dialog-iframe',
uri:'<%=portletSettingsURL.toString()%>'
})
.render();
popUpWindow.show();
popUpWindow.titleNode.html("Image Preview");
popUpWindow.io.start();
});
});
</aui:script>
Using this script i redirect to my view2.jsp and open that page in dialog succesfully. Here I also set the parameter using :
var strUrl=document.getElementById('weburl').value
var testurl =Liferay.PortletURL.createRenderURL();
testurl.setParameter("name",strUrl);
My portal:renderURL is as follow
<portlet:renderURL var="portletSettingsURL"
windowState="<%=LiferayWindowState.POP_UP.toString()%>">
<portlet:param name="mvcPath" value="/html/view2.jsp"/>
</portlet:renderURL>
My view2.jsp file is as follow
<%
String str1=renderRequest.getParameter("nameUrl");
System.out.print("value " +str1);
%>
I want to send my weburl textbox value to view2.jsp file
I just want the value of name in my view2.jsp file
How can I get my value in view2.jsp file?
Have you tired the ParamUtil class?
ParamUtil.get(request, param, defaultValue).
For putting params to the URL you can check this. This is for scriptlet but you can use it in AUI script too.
https://www.liferay.com/community/forums/-/message_boards/message/43775763
Edit:
You can add your parameter to the URL like this:url = url + '&<portlet:namespace/>yourParamName=yourParamValue'
Try with renderRequest.getParameter("name"), it shoud work.
Related
Here's the JSP from where my Javascript function is being called:
JSP code
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="continueTour" onclick="showTutorial()">Take a Quick Tour</button>
Skip Tour
</div>
Here's the Javascript function from where I need to render another JSP, and hence need to get to the Render method in the controller. Notice the 'simulate' method that I'm calling to simulate the click of the hyperlink (!Not sure if this is right or not!):
Javascript Code showTutorial() method:
function showTutorial(){
launchTutorial();
}
function launchTutorial(){
var enjoyhint_instance = new EnjoyHint({
onEnd: function(){
AUI().use('liferay-portlet-url', function(A) {
var plid = Liferay.ThemeDisplay.getPlid();
var url=Liferay.PortletURL.createRenderURL();
/*url.setPortletId(plid);*/
url.setPortletName(Liferay.ThemeDisplay.getp)
url.setParameter('render','redirectToEmpInfo');
alert(url);
A.one(document.createElement('a')).attr('href',url).simulate('click');
});
}
});
var enjoyhint_script_steps = [
{
"next #newAuthorizationActive": 'To create an authorization form'
}
];
enjoyhint_instance.set(enjoyhint_script_steps);
enjoyhint_instance.run();
}
Here's the controller method which I've written to catch the render request from the Javascript.
Controller Method (Not getting to this method)
#RenderMapping(params = "render=redirectToEmpInfo")
protected ModelAndView redirectToEmpInfoForAuthTour(ModelMap map, RenderRequest renderRequest, RenderResponse response) {
LiferayPortal.logInfo(_log, "Inside the render method for Emp Info");
return null;
/*return new ModelAndView("emailsuccess", map);*/
}
You add this code in head of jsp:
<%# taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%# taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme"%>
<liferay-theme:defineObjects/>
<portlet:defineObjects />
Also in you code:
var plid = Liferay.ThemeDisplay.getPlid();
var url=Liferay.PortletURL.createRenderURL();
/*url.setPortletId(plid);*/
url.setPortletName(Liferay.ThemeDisplay.getp)
url.setParameter('render','redirectToEmpInfo');
alert(url);
Replace, similar to this:
var plid = Liferay.ThemeDisplay.getPlid();
var url = Liferay.PortletURL.createRenderURL();
url.setPortletId('<%=themeDisplay.getPortletDisplay().getId() %>');
url.setParameter('render', 'redirectToEmpInfo');
alert(url);
I am dispaying the book details from database. I want to get details of a user who has checked out the book on onclick of the button.
My AUI script:
<aui:script>
function displayUserDetails(userId,userName)
{
var details="<table><tr><td>"+userId+"</td><td>"+userName+"</td></tr></table>";
AUI().use('liferay-util-window','aui-io-deprecated',function(A)
{
var dialog=Liferay.Util.Window.getWindow(
{
dialog: {
title:'userdetails',
bodyContent:details,
centered:true,
modal: true,
width: 500,
height: 400
}
}).render();
});
}
</aui:script>
I am calling the function here
<aui:button name="button9" value="details" id='getMoreInfo_<%=bookId %>' onclick="displayUserDetails(<%=userId %>,<%=un %>);" />
I am getting syntax error that while calling the function on button click (above line)
If i call the function like this...
onclick="displayUserDetails('<%=userId %>','<%=un %>');"
output will be like <%=userId%><%=un%> (in table)
onclick="displayUserDetails(<%=userId %>,<%=un %>);"
Below code is working.....:-)
onClick='<%="displayUserDetails(\'"+userId+"\',\'"+un+"\');"%>'
credits to
Nishikant sapkal # http://www.liferay.com/community/forums/-/message_boards/message/27640265
I want to create a new type of aui validator.
For example :
<aui:input name="firstName" type="text" maxlength="40">
<aui:validator name="required" />
<aui:validator name="alpha" />
</aui:input>
the alpha validator does not accept the space character, i want to use a type that accepts alpha characters plus the space character, i have already a solution using javascript to use a custom validator, but i want to define a new validator type to use like the others by invoking the validator tag e.g :
<aui:validator name="myValidator" />
Is that possible ?! and how can i do it ;)
Try your luck on it :)
<aui:input name="firstName" type="text">
<aui:validator name="myValidator" errorMessage="numbers-not-allowed">
function(val, fieldNode, ruleValue){
var matches = val.match(/\d+/g);
if(matches != null)
return false;
else
return true;
}
</aui:validator>
</aui:input>
As an alternative to Parkash answer, you can make a separate jspf file and write your validations like this:
<aui:script use="liferay-form">
var ns = '<portlet:namespace/>';
window.onload = function() {
var form = Liferay.Form.get(ns+'form_add_user');
form.set(
'fieldRules',
[
{
fieldName: ns+'middlename',
validatorName: 'custom_middlename',
custom: true,
errorMessage: 'Only text and spaces here!',
body: function(value, field, rule)
{
return /^[a-zA-Z\s\.\u00E0-\u00FC]+$/.test(value);
}
},
...
]
);
}
</aui:script>
Found in Liferay 7.0 documentation
I'm just started to develeop a web app with Durandal. I don't understand how call a function from a viewmodel and why if I find an element of my document it seems is not attached yet.
Example: viewmodel.js
define( ['libone', 'libtwo'], function () {
$('.carousel').libone({
expandbuttons: true,
keyboard: true,
mouse: true
});
});
It doesn't find the ID call carousel is why there's no view.hmtl content but index.html content.
Any ideas?
Thanks in advance
UPDATE
No errors but the view content is not returned.
view.html
<section>
<h2 data-bind="html:name"></h2>
<blockquote data-bind="html:descr"></blockquote>
<div class="carousel">
<div class="carousel-sections">
<div class="carousel-section"> ... some content ... </div>
</div>
</div>
<a id="carousel-scroll-prev" href="#"></a>
<a id="carousel-scroll-next" href="#"></a>
<section>
modelview.js
define( ['libone', 'libtwo'], function (libone, libtwo) {
var viewattached = function(view){
var view = $(view);
view.find('.carousel').libone({
expandbuttons: true,
keyboard: true,
mouse: true
});
};
var vm = {
attached: viewattached,
name: 'How about we start?',
descr: 'You have many choices to make and many roads to cross...'
};
return vm;
});
Only name, descr and scroll are shown but not carousel-section.
The rendering problem has been resolved using compositionComplete instead attached.
to gain access to the controls using jquery like you are requesting, you should use the views attached event
e.g.
define( ['libone', 'libtwo'], function (libone, libtwo) {
var viewattached = function(view){
var view = $(view);
view.find('.carousel').libone({
expandbuttons: true,
keyboard: true,
mouse: true
});
};
var vm = {
attached: viewattached
};
return vm;
});
The other one that may work will be the compsitionComplete..
compositionComplete works fine.But if you refresh the page ,composition complete skips the binding of element with the carousel and teh carousel doesnt work.
Any
I have one jquery function which will redirect to my edit page when i click on the edit icon of the column in my custom liferay portlet..
but some how when i click on that icon its just reloading the page but not redirecting to the page i want
here is my view.jsp code
MY PORTLET ACTION URL CODE
<portlet:actionURL var="editrestaurantURL" >
<portlet:param name="jspPage" value="/jsps/edit_restaurant.jsp"/>
My column on click of that jquery will invoke
<td class="editable"><%=temprest.getName() %></td>
this is my script code
<script>
$(document).ready(function() {
$(".editable").hover(function(){
$(this).append("<i class='splashy-pencil_right'></i>")
}, function(){
$(this).children("i").remove();
});
$(".editable").click(function(){
$.colorbox({
initialHeight: '0',
initialWidth: '0',
href: "#confirm_dialog",
inline: true,
opacity: '0.3',
onComplete: function(){
$('.confirm_yes').click(function(e){
e.preventDefault();
window.location.href = "<%=editrestaurantURL.toString() %> ";
$.colorbox.close();
});
$('.confirm_no').click(function(e){
e.preventDefault();
$.colorbox.close();
});
}
});
});
//* show all elements & remove preloader
setTimeout('$("html").removeClass("js")',1000);
});
</script>
Anyone can guide me that where is the problem?i cant know where is going wrong..
The definition of the URL:
<portlet:actionURL var="editrestaurantURL" >
<portlet:param name="jspPage" value="/jsps/edit_restaurant.jsp"/>
</portlet:actionURL>
stores the value into an EL variable. Check that you are not missing part. And if your javascript is working correctly (try to enter any static URL, e.g. www.google.com), do following
...
window.location.href = "${editrestaurantURL}";
...