留言板

RE: Liferay.Address is undefined for anonymous user

thumbnail
Alexey Kakunin,修改在13 年前。

Liferay.Address is undefined for anonymous user

Liferay Master 帖子: 621 加入日期: 08-7-7 最近的帖子
Hi!

I'm trying to implement own registration in plugin env and during registration ask user for address. I'm using Liferay.DynamicSelect for selecting country and region (for selected country) and code looks like:

<%
themeDisplay.setIncludeServiceJs(true); // to enable dynamic selectors
%>

<aui:script use="liferay-dynamic-select">
	new Liferay.DynamicSelect(
		[
			{
				select: "<portlet:namespace />billing-countryId",
				selectId: "countryId",
				selectDesc: "name",
				selectVal: "&lt;%= address != null ? address.getCountryId() : 13 %&gt;",
				selectData: Liferay.Address.getCountries
			},
			{
				select: "<portlet:namespace />billing-regionId",
				selectId: "regionId",
				selectDesc: "name",
				selectVal: "&lt;%= address != null ? address.getRegionId() : 0 %&gt;",
				selectData: Liferay.Address.getRegions
			}
		]
	);

</aui:script>


Everything works fine for registered user, but for anonymous (this portlet should be used by anonymous) I've got javascript error in browser:

Uncaught TypeError: Cannot read property 'getCountries' of undefined


Does I missed something to enable usage of Liferay services via JS for anonymous user?

==
Alexey Kakunin
EmForge: Liferay Based Project Hosting Service
thumbnail
Alexey Kakunin,修改在13 年前。

RE: Liferay.Address is undefined for anonymous user

Liferay Master 帖子: 621 加入日期: 08-7-7 最近的帖子
OK, found
I need to move /liferay/address.js from javascript.everything.files to the javascript.barebone.files

Unfortunatelly these properties not supported via portlets hook, so, only possible change them via ext (but good thing - ext environment in 6 managed from same plugins)

==
Alexey Kakunin
EmForge: Liferay Based Project Hosting Service
Carlos Llongo,修改在13 年前。

RE: Liferay.Address is undefined for anonymous user

New Member 帖子: 10 加入日期: 10-3-10 最近的帖子
Hi Alexey,

I have a similar problem. As a registered user, the country list is populated, but for anonymous users it's empty.

I tried moving address.js from "everything" to "barebone" but the problem persisted.

I then moved all the js used in the page to "barebone", but not luck either with that.

Any idea what the problem can be?

Thanks!
thumbnail
Alexey Kakunin,修改在13 年前。

RE: Liferay.Address is undefined for anonymous user

Liferay Master 帖子: 621 加入日期: 08-7-7 最近的帖子
Hi Carlos
In my case it was enough. Liferay use caching very agressively.
probably it is cashed barebone.js somethere
Try to clean /tmp/liferay or ${tomcat}/tmp/liferay folders


==
Alexey Kakunin
EmForge: Liferay Based Project Hosting Service
Carlos Llongo,修改在13 年前。

RE: Liferay.Address is undefined for anonymous user

New Member 帖子: 10 加入日期: 10-3-10 最近的帖子
Hi Alexey,

I tried cleaning those folders but the problem persists.

I have been reading lots of documentation and most agree that most Liferay services require the user to be logged in to work. That would explain why the select is populated if the user is logged in, but it's not when it's an anonymous user.

¿You where able to populate the select with an anonymous user?

Thanks!
thumbnail
Viktor Palai,修改在13 年前。

RE: Liferay.Address is undefined for anonymous user

New Member 帖子: 20 加入日期: 10-10-14 最近的帖子
Hi Carlos,

have you been able to fix this issue?

Im having the same problem that I cant display list of Countries on the create_account page even I did all the suggested steps.

Please help me if you can.

Thank you
thumbnail
Corentin R,修改在12 年前。

RE: Liferay.Address is undefined for anonymous user

Junior Member 帖子: 92 加入日期: 10-6-18 最近的帖子
Hi,
I'm facing exactly the same problem. I'm trying to use the Liferay.DynamicSelect on liferay's create_account.jsp.
To do so I tryed to add js librairies to barbone but I'm still getting this message from Firebug AUI().io.request is not a function
I tryed to add the Alloyui io librairies to barebone but it seems not to change anything since I'm still getting exactly the same output from Firebug...
aui/aui-base/aui-base.js,\
        aui/aui-io/aui-io.js,\
        aui/aui-io/aui-io-request.js,\
        aui/aui-io/aui-io-plugin.js,\

Looks like I'm missing some Js librairies ? But which one ?
thumbnail
Corentin R,修改在12 年前。

RE: Liferay.Address is undefined for anonymous user

Junior Member 帖子: 92 加入日期: 10-6-18 最近的帖子
Found it !
In my case I have to add liferay/address.js to barebone via portla-ext.properties and then use the following code to use it. Pay attention to the aui-io-request library that must be specified in the use attribute of aui:script when displayed on guest pages (on authenticated pages it seems to work even without it).
<aui:script use="liferay-dynamic-select,[color=#ff0000]aui-io-request[/color]">
						new Liferay.DynamicSelect(
							[
								{
									select: '<portlet:namespace />addressCountryId',
									selectData: Liferay.Address.getCountries,
									selectDesc: 'name',
									selectId: 'countryId',
									selectVal: ''
								},
								{
									select: '<portlet:namespace />addressRegionId',
									selectData: Liferay.Address.getRegions,
									selectDesc: 'name',
									selectId: 'regionId',
									selectVal: ''
								}
							]
						);
			</aui:script>
thumbnail
Tanweer Ahmed .,修改在1 年前。

RE: Liferay.Address is undefined for anonymous user

Expert 帖子: 322 加入日期: 10-3-11 最近的帖子
Hi Coretin,

I am trying to implement the Dynamic Select for Country > Region.
For a logged in user, it works perfectly fine. But for guests/unregistered users, it doesn't work.I tried following your solution, but even that doesn't work for me.It seems you have got it working for the guest user.Can you share the code or provide some solution?

Any help is Appreciated.

Regards,
Tanweer Ahmed Ansari,
mPowerian-BoschLer
thumbnail
Corentin R,修改在12 年前。

RE: Liferay.Address is undefined for anonymous user

Junior Member 帖子: 92 加入日期: 10-6-18 最近的帖子
Hi !
If it's working for your authenticated user only that may be because you didn't add liferay/address.js to barebone in your portal-ext.properties ...
Have you got an javascript error when the page is loading ?

Corentin.
thumbnail
Tanweer Ahmed .,修改在1 年前。

RE: Liferay.Address is undefined for anonymous user

Expert 帖子: 322 加入日期: 10-3-11 最近的帖子
Corentin R:
Hi !
If it's working for your authenticated user only that may be because you didn't add liferay/address.js to barebone in your portal-ext.properties ...
Have you got an javascript error when the page is loading ?

Corentin.


Coretin,

I have already added liferay/address.js to barebone through portal-ext.But even that doesn't help.Wel I do not get any js error in browser.
Can you share your exact implemented code ?

Regards,
Tanweer Ahmed Ansari,
mPowerian-BoschLer
thumbnail
Corentin R,修改在12 年前。

RE: Liferay.Address is undefined for anonymous user

Junior Member 帖子: 92 加入日期: 10-6-18 最近的帖子
Hello,
Hummm ... what else can I add emoticon
Did you insert
themeDisplay.setIncludeServiceJs(true);
in the top of your jsp ?

Here is my portal-ext.properties :
javascript.barebone.files=\
        \
        #
        # YUI core
        #
        \
        aui/yui/yui.js,\
        \
        #
        # YUI modules
        #
        \
        aui/attribute/attribute.js,\
        aui/event-custom/event-custom.js,\
        aui/loader/loader.js,\
        aui/oop/oop.js,\
        \
        #
        # Alloy core
        #
        \
        aui/aui-base/aui-base.js,\
        \
        #
        # Liferay module definitions
        #
        \
        liferay/modules.js,\
        liferay/address.js,\
        \
        #
        # Liferay base utility scripts
        #
        \
        liferay/dependency.js,\
        liferay/language.js,\
        liferay/liferay.js,\
        liferay/util.js,\
        \
        #
        # Liferay utility scripts
        #
        \
        liferay/events.js,\
        liferay/portal.js,\
        liferay/portlet.js,\
        liferay/dynamic_select.js,\
        liferay/portlet_sharing.js

Hope it will help you solve your problem.
Corentin
Carl Spangenberger,修改在12 年前。

RE: Liferay.Address is undefined for anonymous user

New Member 帖子: 2 加入日期: 12-2-24 最近的帖子
I am having same problem with Liferay 6.1 EE GA. Trying to get country and region using liferay-dynamic-select but does not work.
This is my test page for create_account.jsp hook. do not get error, but does not load the Lifreray.Address.countries or Licrary,Address.regions in the page.What am I doing incorrectly? I look at the javascript in firebug and the Address class is there and the javascript is executing.

Thanks,

Carl

<%--
/**
* Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
--%>
<script src="/html/js/liferay/service.js" type="text/javascript"> </script>


<%@ include file="/html/portlet/login/init.jsp" %>



<%
themeDisplay.setIncludeServiceJs(true);
String redirect = ParamUtil.getString(request, "redirect");

String openId = ParamUtil.getString(request, "openId");

PasswordPolicy passwordPolicy = PasswordPolicyLocalServiceUtil.getDefaultPasswordPolicy(company.getCompanyId());

Calendar birthday = CalendarFactoryUtil.getCalendar();

birthday.set(Calendar.MONTH, Calendar.JANUARY);
birthday.set(Calendar.DATE, 1);
birthday.set(Calendar.YEAR, 1970);

boolean male = ParamUtil.getBoolean(request, "male", true);
%>



<portlet:actionURL var="createAccoutURL">
<portlet:param name="saveLastPath" value="0" />
<portlet:param name="struts_action" value="/login/create_account" />
</portlet:actionURL>

<aui:form action="<%= createAccoutURL %>" method="post" name="fm">
<aui:input name="<%= Constants.CMD %>" type="hidden" value="<%= Constants.ADD %>" />
<aui:input name="redirect" type="hidden" value="<%= redirect %>" />
<aui:input name="openId" type="hidden" value="<%= openId %>" />

<liferay-ui:error exception="<%= AddressCityException.class %>" message="please-enter-a-valid-city" />
<liferay-ui:error exception="<%= AddressStreetException.class %>" message="please-enter-a-valid-street" />
<liferay-ui:error exception="<%= AddressZipException.class %>" message="please-enter-a-valid-postal-code" />
<liferay-ui:error exception="<%= CaptchaMaxChallengesException.class %>" message="maximum-number-of-captcha-attempts-exceeded" />
<liferay-ui:error exception="<%= CaptchaTextException.class %>" message="text-verification-failed" />
<liferay-ui:error exception="<%= CompanyMaxUsersException.class %>" message="unable-to-create-user-account-because-the-maximum-number-of-users-has-been-reached" />
<liferay-ui:error exception="<%= ContactFirstNameException.class %>" message="please-enter-a-valid-first-name" />
<liferay-ui:error exception="<%= ContactFullNameException.class %>" message="please-enter-a-valid-first-middle-and-last-name" />
<liferay-ui:error exception="<%= ContactLastNameException.class %>" message="please-enter-a-valid-last-name" />
<liferay-ui:error exception="<%= DuplicateUserEmailAddressException.class %>" message="the-email-address-you-requested-is-already-taken" />
<liferay-ui:error exception="<%= DuplicateUserIdException.class %>" message="the-user-id-you-requested-is-already-taken" />
<liferay-ui:error exception="<%= DuplicateUserScreenNameException.class %>" message="the-screen-name-you-requested-is-already-taken" />
<liferay-ui:error exception="<%= EmailAddressException.class %>" message="please-enter-a-valid-email-address" />
<liferay-ui:error exception="<%= NoSuchCountryException.class %>" message="please-select-a-country" />
<liferay-ui:error exception="<%= NoSuchListTypeException.class %>" message="please-select-a-type" />
<liferay-ui:error exception="<%= NoSuchRegionException.class %>" message="please-select-a-region" />
<liferay-ui:error exception="<%= PhoneNumberException.class %>" message="please-enter-a-valid-phone-number" />
<liferay-ui:error exception="<%= RequiredFieldException.class %>" message="please-fill-out-all-required-fields" />
<liferay-ui:error exception="<%= ReservedUserEmailAddressException.class %>" message="the-email-address-you-requested-is-reserved" />
<liferay-ui:error exception="<%= ReservedUserIdException.class %>" message="the-user-id-you-requested-is-reserved" />
<liferay-ui:error exception="<%= ReservedUserScreenNameException.class %>" message="the-screen-name-you-requested-is-reserved" />
<liferay-ui:error exception="<%= TermsOfUseException.class %>" message="you-must-agree-to-the-terms-of-use" />
<liferay-ui:error exception="<%= UserEmailAddressException.class %>" message="please-enter-a-valid-email-address" />
<liferay-ui:error exception="<%= UserIdException.class %>" message="please-enter-a-valid-user-id" />

<liferay-ui:error exception="<%= UserPasswordException.class %>">

<%
UserPasswordException upe = (UserPasswordException)errorException;
%>

<c:if test="<%= upe.getType() == UserPasswordException.PASSWORD_CONTAINS_TRIVIAL_WORDS %>">
<liferay-ui:message key="that-password-uses-common-words-please-enter-in-a-password-that-is-harder-to-guess-i-e-contains-a-mix-of-numbers-and-letters" />
</c:if>

<c:if test="<%= upe.getType() == UserPasswordException.PASSWORD_INVALID %>">
<liferay-ui:message key="that-password-is-invalid-please-enter-in-a-different-password" />
</c:if>

<c:if test="<%= upe.getType() == UserPasswordException.PASSWORD_LENGTH %>">
<%= LanguageUtil.format(pageContext, "that-password-is-too-short-or-too-long-please-make-sure-your-password-is-between-x-and-512-characters", String.valueOf(passwordPolicy.getMinLength()), false) %>
</c:if>

<c:if test="<%= upe.getType() == UserPasswordException.PASSWORD_TOO_TRIVIAL %>">
<liferay-ui:message key="that-password-is-too-trivial" />
</c:if>

<c:if test="<%= upe.getType() == UserPasswordException.PASSWORDS_DO_NOT_MATCH %>">
<liferay-ui:message key="the-passwords-you-entered-do-not-match-each-other-please-re-enter-your-password" />
</c:if>
</liferay-ui:error>

<liferay-ui:error exception="<%= UserScreenNameException.class %>" message="please-enter-a-valid-screen-name" />
<liferay-ui:error exception="<%= WebsiteURLException.class %>" message="please-enter-a-valid-url" />
<aui:model-context bean="address" model="<%= Address.class %>" />
<div class="lfr-form-row">
<div class="row-fields">
<aui:column columnWidth="50">
<aui:input name="addressId" type="hidden" value="" />

<aui:select label="country" name="addressCountryId" />

<aui:select label="region" name="addressRegionId" />
</aui:column>
</div>
</div>

<aui:script use="liferay-dynamic-select,aui-io-request">


new Liferay.DynamicSelect(
[
{
select: '<portlet:namespace />addressCountryId',
selectData: Liferay.Address.getCountries,
selectDesc: 'name',
selectId: 'countryId',
selectVal: ''
},
{
select: '<portlet:namespace />addressRegionId',
selectData: Liferay.Address.getRegions,
selectDesc: 'name',
selectId: 'regionId',
selectVal: ''
}
]
);
</aui:script>

</aui:form>



<liferay-util:include page="/html/portlet/login/navigation.jsp" />

<c:if test="<%= windowState.equals(WindowState.MAXIMIZED) %>">
<aui:script>
Liferay.Util.focusFormField(document.<portlet:namespace />fm.<portlet:namespace />firstName);
</aui:script>
</c:if>
thumbnail
Corentin R,修改在12 年前。

RE: Liferay.Address is undefined for anonymous user

Junior Member 帖子: 92 加入日期: 10-6-18 最近的帖子
Hi Carl,

Did you add liferay/address.js to the barebone in your portal-ext.properties?
Liferay.Address isn't load by default for unauthenticated users...
Carl Spangenberger,修改在12 年前。

RE: Liferay.Address is undefined for anonymous user

New Member 帖子: 2 加入日期: 12-2-24 最近的帖子
Corentin R:
Hi Carl,

Did you add liferay/address.js to the barebone in your portal-ext.properties?
Liferay.Address isn't load by default for unauthenticated users...



This is my protal.ext.properties file.

redirect.url.security.mode=ip
redirect.url.domains.allowed=
redirect.url.ips.allowed=127.0.0.1,192.168.1.82
dl.file.max.size=100000000

javascript.barebone.files=\
\
#
# YUI core
#
\
aui/yui/yui.js,\
\
#
# YUI modules
#
\
aui/attribute/attribute.js,\
aui/event-custom/event-custom.js,\
aui/loader/loader.js,\
aui/oop/oop.js,\
\
#
# Alloy core
#
\
aui/aui-base/aui-base.js,\
\
#
# Liferay module definitions
#
\
liferay/modules.js,\
liferay/address.js,\
#
# Liferay base utility scripts
#
\
liferay/dependency.js,\
liferay/language.js,\
liferay/liferay.js,\
liferay/util.js,\
\
#
# Liferay utility scripts
#
\
liferay/events.js,\
liferay/portal.js,\
liferay/portlet.js,\
liferay/dynamic_select.js,\
liferay/portlet_sharing.js

javascript.barebone.enabled=true
auth.pipeline.enable.liferay.check=false.

The file Liferay,Adress class is in the DOM when look at it through firebug.

Thanks for the help

Carl
thumbnail
Mayur Patel,修改在11 年前。

RE: Liferay.Address is undefined for anonymous user

Expert 帖子: 358 加入日期: 10-11-17 最近的帖子
In LF 6.1 error was coming for aui-io-request after adding same in aui:script mentioned by Corentin. It worked perfectly fine

Thanks a lot Corentin for the solution, Its really helpful emoticon
Michele Giacobazzi,修改在11 年前。

RE: Liferay.Address is undefined for anonymous user

Junior Member 帖子: 40 加入日期: 11-9-9 最近的帖子
Hi,
I implemented a login page with address required in Liferay 6.0.6 and ported it succesfully to 6.1.0.

Problems started with 6.1.1.

Now I have a problem with Liferay.Address.getCountries, but of a different kind.

The object is present in the JS console, and I can execute the query. But I receive the following exception as JSON answer:

Object {exception: "Please sign in to invoke this method"}


Obviously the user can't sign in because it does not exist yet.

Is there a workaround?
Michele Giacobazzi,修改在11 年前。

RE: Liferay.Address is undefined for anonymous user

Junior Member 帖子: 40 加入日期: 11-9-9 最近的帖子
To make getCountries and getRegions work for unregistered user you have to add the following two lines in porta-ext.properties:


#allow json access to some methods even if not logged
json.service.public.methods=getCountries,getRegions
jsonws.web.service.public.methods=getCountries,getReqions


The same for other methods you might need to call.
thumbnail
Jan Geißler,修改在11 年前。

RE: Liferay.Address is undefined for anonymous user

Liferay Master 帖子: 735 加入日期: 11-7-5 最近的帖子
Does this work for custom Webservices as well?