论坛

主页 » Liferay Portal » English » 3. Development

组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
Alexey Kakunin
Liferay.Address is undefined for anonymous user
2010年5月23日 下午12:27
答复

Alexey Kakunin

等级: Expert

帖子: 370

加入日期: 2008年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:
 1
 2<%
 3themeDisplay.setIncludeServiceJs(true); // to enable dynamic selectors
 4%>
 5
 6<aui:script use="liferay-dynamic-select">
 7    new Liferay.DynamicSelect(
 8        [
 9            {
10                select: "<portlet:namespace />billing-countryId",
11                selectId: "countryId",
12                selectDesc: "name",
13                selectVal: "<%= address != null ? address.getCountryId() : 13 %>",
14                selectData: Liferay.Address.getCountries
15            },
16            {
17                select: "<portlet:namespace />billing-regionId",
18                selectId: "regionId",
19                selectDesc: "name",
20                selectVal: "<%= address != null ? address.getRegionId() : 0 %>",
21                selectData: Liferay.Address.getRegions
22            }
23        ]
24    );


Everything works fine for registered user, but for anonymous (this portlet should be used by anonymous) I've got javascript error in browser:
1
2Uncaught 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
Alexey Kakunin
RE: Liferay.Address is undefined for anonymous user
2010年5月23日 下午12:54
答复

Alexey Kakunin

等级: Expert

帖子: 370

加入日期: 2008年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
RE: Liferay.Address is undefined for anonymous user
2010年8月4日 上午4:54
答复

Carlos Llongo

等级: New Member

帖子: 10

加入日期: 2010年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!
Alexey Kakunin
RE: Liferay.Address is undefined for anonymous user
2010年8月4日 下午12:44
答复

Alexey Kakunin

等级: Expert

帖子: 370

加入日期: 2008年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
RE: Liferay.Address is undefined for anonymous user
2010年8月5日 上午3:27
答复

Carlos Llongo

等级: New Member

帖子: 10

加入日期: 2010年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!
Viktor Palai
RE: Liferay.Address is undefined for anonymous user
2010年11月5日 上午2:33
答复

Viktor Palai

等级: New Member

帖子: 20

加入日期: 2010年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
Corentin R
RE: Liferay.Address is undefined for anonymous user
2011年5月2日 上午9:32
答复

Corentin R

等级: Junior Member

帖子: 92

加入日期: 2010年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...
1aui/aui-base/aui-base.js,\
2        aui/aui-io/aui-io.js,\
3        aui/aui-io/aui-io-request.js,\
4        aui/aui-io/aui-io-plugin.js,\

Looks like I'm missing some Js librairies ? But which one ?
Corentin R
RE: Liferay.Address is undefined for anonymous user
2011年5月3日 上午1:04
答复

Corentin R

等级: Junior Member

帖子: 92

加入日期: 2010年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).
 1<aui:script use="liferay-dynamic-select,[color=#ff0000]aui-io-request[/color]">
 2                        new Liferay.DynamicSelect(
 3                            [
 4                                {
 5                                    select: '<portlet:namespace />addressCountryId',
 6                                    selectData: Liferay.Address.getCountries,
 7                                    selectDesc: 'name',
 8                                    selectId: 'countryId',
 9                                    selectVal: ''
10                                },
11                                {
12                                    select: '<portlet:namespace />addressRegionId',
13                                    selectData: Liferay.Address.getRegions,
14                                    selectDesc: 'name',
15                                    selectId: 'regionId',
16                                    selectVal: ''
17                                }
18                            ]
19                        );
20            </aui:script>
Tanweer .
RE: Liferay.Address is undefined for anonymous user
2011年5月15日 上午10:29
答复

Tanweer .

等级: Expert

帖子: 283

加入日期: 2010年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
Corentin R
RE: Liferay.Address is undefined for anonymous user
2011年5月15日 下午12:03
答复

Corentin R

等级: Junior Member

帖子: 92

加入日期: 2010年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.
Tanweer .
RE: Liferay.Address is undefined for anonymous user
2011年5月16日 上午10:48
答复

Tanweer .

等级: Expert

帖子: 283

加入日期: 2010年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
Corentin R
RE: Liferay.Address is undefined for anonymous user
2011年5月17日 上午2:23
答复

Corentin R

等级: Junior Member

帖子: 92

加入日期: 2010年6月18日

最近的帖子

Hello,
Hummm ... what else can I add emoticon
Did you insert
1themeDisplay.setIncludeServiceJs(true);
in the top of your jsp ?

Here is my portal-ext.properties :
 1javascript.barebone.files=\
 2        \
 3        #
 4        # YUI core
 5        #
 6        \
 7        aui/yui/yui.js,\
 8        \
 9        #
10        # YUI modules
11        #
12        \
13        aui/attribute/attribute.js,\
14        aui/event-custom/event-custom.js,\
15        aui/loader/loader.js,\
16        aui/oop/oop.js,\
17        \
18        #
19        # Alloy core
20        #
21        \
22        aui/aui-base/aui-base.js,\
23        \
24        #
25        # Liferay module definitions
26        #
27        \
28        liferay/modules.js,\
29        liferay/address.js,\
30        \
31        #
32        # Liferay base utility scripts
33        #
34        \
35        liferay/dependency.js,\
36        liferay/language.js,\
37        liferay/liferay.js,\
38        liferay/util.js,\
39        \
40        #
41        # Liferay utility scripts
42        #
43        \
44        liferay/events.js,\
45        liferay/portal.js,\
46        liferay/portlet.js,\
47        liferay/dynamic_select.js,\
48        liferay/portlet_sharing.js

Hope it will help you solve your problem.
Corentin
Carl Spangenberger
RE: Liferay.Address is undefined for anonymous user
2012年3月27日 上午7:05
答复

Carl Spangenberger

等级: New Member

帖子: 2

加入日期: 2012年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>
Corentin R
RE: Liferay.Address is undefined for anonymous user
2012年3月28日 上午3:31
答复

Corentin R

等级: Junior Member

帖子: 92

加入日期: 2010年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
RE: Liferay.Address is undefined for anonymous user
2012年3月28日 上午10:45
答复

Carl Spangenberger

等级: New Member

帖子: 2

加入日期: 2012年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
Mayur Patel
RE: Liferay.Address is undefined for anonymous user
2012年5月17日 上午7:20
答复

Mayur Patel

等级: Expert

帖子: 341

加入日期: 2010年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
RE: Liferay.Address is undefined for anonymous user
2012年12月6日 上午7:44
答复

Michele Giacobazzi

等级: Junior Member

帖子: 37

加入日期: 2011年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
RE: Liferay.Address is undefined for anonymous user
2012年12月10日 上午10:09
答复

Michele Giacobazzi

等级: Junior Member

帖子: 37

加入日期: 2011年9月9日

最近的帖子

To make getCountries and getRegions work for unregistered user you have to add the following two lines in porta-ext.properties:

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


The same for other methods you might need to call.
Jan Geißler
RE: Liferay.Address is undefined for anonymous user
2012年12月11日 上午1:26
答复

Jan Geißler

等级: Expert

帖子: 358

加入日期: 2011年7月5日

最近的帖子

Does this work for custom Webservices as well?