liferay里如何让用户名支持中文

liferay里默认是不支持中文的,也没有什么办法通过修改配置达到支持中文的目的,原因是它需要根据用户的screenname即昵称来生成friend url,个人主页等,所以故意不支持,但对于中文项目,支持中文却是个必须的东西,经过调研,发现修改两个文件即可达到支持的目的,且至今没发现有什么负面影响。

注掉如下类的几处代码

1.UserLocalServiceImpl

    

	if (Validator.isNumber(screenName)) {
			if (!PropsValues.USERS_SCREEN_NAME_ALLOW_NUMERIC) {
				throw new UserScreenNameException();
			}

			if (!screenName.equals(String.valueOf(userId))) {
				Group group = groupPersistence.fetchByPrimaryKey(
					GetterUtil.getLong(screenName));

				if (group != null) {
					throw new UserScreenNameException();
				}
			}
		}

		for (char c : screenName.toCharArray()) {
			if (!Validator.isChar(c) && !Validator.isDigit(c) &&
				(c != CharPool.DASH) && (c != CharPool.PERIOD) &&
				(c != CharPool.UNDERLINE)) {

				throw new UserScreenNameException();
			}
		}

 

		int exceptionType = LayoutImpl.validateFriendlyURL(friendlyURL);

		if (exceptionType != -1) {
			throw new UserScreenNameException(
				new GroupFriendlyURLException(exceptionType));
		}

 2.GroupLocalServiceImpl

		int exceptionType = LayoutImpl.validateFriendlyURL(friendlyURL);

		if (exceptionType != -1) {
			throw new GroupFriendlyURLException(exceptionType);
		}

 

编译后生成的class复制到root项目的web-inf下的classes目录,重启即可生效,如果有朝一日不需要支持中文,删掉这些类重启即可。

猜你喜欢

转载自theoffspring.iteye.com/blog/2094296
今日推荐