例子, 为注册用户信息(create account)添加字段comanyname,telephone
1.在liferay的数据库(ltcncportal)中的user_表中加入companyname varchar,telephone varchar 字段
2.把liferay-portal-src-4.3.4导入eclipse下
3.把liferay-portal-src-4.3.4改成portal
4.找到/portal/portal-impl/classes/META-INF/portal-hbm.xml文件,此文件类似于hibernate的##.hbm.xml文件,找到表user_对应的配置部分,红字为新添部分
<class name="com.liferay.portal.model.impl.UserImpl" table="User_">
<cache usage="read-write" />
<id name="userId" type="long">
<generator class="assigned" />
</id>
<property name="companyId" type="com.liferay.util.dao.hibernate.LongType" />
<property name="createDate" />
<property name="modifiedDate" />
<property name="companyname" type="com.liferay.util.dao.hibernate.StringType" />
<property name="telphone" type="com.liferay.util.dao.hibernate.StringType" />
<property name="defaultUser" type="com.liferay.util.dao.hibernate.BooleanType" />
<property name="contactId" type="com.liferay.util.dao.hibernate.LongType" />
<property name="password" column="password_" type="com.liferay.util.dao.hibernate.StringType" />
<property name="passwordEncrypted" type="com.liferay.util.dao.hibernate.BooleanType" />
<property name="passwordReset" type="com.liferay.util.dao.hibernate.BooleanType" />
<property name="passwordModifiedDate" />
<property name="graceLoginCount" type="com.liferay.util.dao.hibernate.IntegerType" />
<property name="screenName" type="com.liferay.util.dao.hibernate.StringType" />
<property name="emailAddress" type="com.liferay.util.dao.hibernate.StringType" />
<property name="portraitId" type="com.liferay.util.dao.hibernate.LongType" />
<property name="languageId" type="com.liferay.util.dao.hibernate.StringType" />
<property name="timeZoneId" type="com.liferay.util.dao.hibernate.StringType" />
<property name="greeting" type="com.liferay.util.dao.hibernate.StringType" />
<property name="comments" type="com.liferay.util.dao.hibernate.StringType" />
<property name="loginDate" />
<property name="loginIP" type="com.liferay.util.dao.hibernate.StringType" />
<property name="lastLoginDate" />
<property name="lastLoginIP" type="com.liferay.util.dao.hibernate.StringType" />
<property name="lastFailedLoginDate" />
<property name="failedLoginAttempts" type="com.liferay.util.dao.hibernate.IntegerType" />
<property name="lockout" type="com.liferay.util.dao.hibernate.BooleanType" />
<property name="lockoutDate" />
<property name="agreedToTermsOfUse" type="com.liferay.util.dao.hibernate.BooleanType" />
<property name="active" column="active_" type="com.liferay.util.dao.hibernate.BooleanType" />
</class>
|
5.找到/portal/portal-impl/classes/META-INF/portal-model-hints.xml文件,似乎属于spring的配置文件,找到user_的配置部分,红字为新添部分
<model name="com.liferay.portal.model.User">
<default-hints>
<hint name="display-width">150</hint>
</default-hints>
<field name="userId" type="long" />
<field name="companyId" type="long" />
<field name="createDate" type="Date" />
<field name="modifiedDate" type="Date" />
<field name="defaultUser" type="boolean" />
<field name="contactId" type="long" />
<field name="password" type="String" />
<field name="companyname" type="String" />
<field name="telphone" type="String" />
<field name="passwordEncrypted" type="boolean" />
<field name="passwordReset" type="boolean" />
<field name="passwordModifiedDate" type="Date" />
<field name="graceLoginCount" type="int" />
<field name="screenName" type="String" />
<field name="emailAddress" type="String" />
<field name="portraitId" type="long" />
<field name="languageId" type="String" />
<field name="timeZoneId" type="String" />
<field name="greeting" type="String" />
<field name="comments" type="String">
<hint-collection name="TEXTAREA" />
</field>
<field name="loginDate" type="Date" />
<field name="loginIP" type="String" />
<field name="lastLoginDate" type="Date" />
<field name="lastLoginIP" type="String" />
<field name="lastFailedLoginDate" type="Date" />
<field name="failedLoginAttempts" type="int" />
<field name="lockout" type="boolean" />
<field name="lockoutDate" type="Date" />
<field name="agreedToTermsOfUse" type="boolean" />
<field name="active" type="boolean" />
</model>
|
6.在tomcat下找到此文件C:/ltcnctomcat/webapps/ROOT/html/portlet/my_account/create_account.jsp,打开create_account.jsp文件在上面添上input表单(略)。
7.然后找这个表单提交后用的类,根据create_account.jsp中的
<form action="<portlet:actionURL windowState="<%= WindowState.MAXIMIZED.toString() %>"><portlet:param name="struts_action" value="/my_account/create_account" /></portlet:actionURL>" method="post" name="<portlet:namespace />fm">
|
到struts-config.xml中查找
<action path="/my_account/create_account" type="com.liferay.portlet.myaccount.action.AddUserAction">
<forward name="portlet.my_account.create_account" path="portlet.my_account.create_account" />
</action>
|
说明用AddUserAction进行的添加找到com.liferay.portlet.myaccount.action.AddUserAction,在/portal/portal-impl/src/com/liferay/portlet/myaccount/action/AddUserAction.java中,在eclipse打开,红色字体为重点部分
//addUser edit zy
protectedvoidaddUser(ActionRequest req, ActionResponse res)
throws Exception {
ThemeDisplay themeDisplay =
(ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
Company company = themeDisplay.getCompany();
boolean autoPassword = true;
String password1 = null;
String password2 = null;
boolean autoScreenName = false;
String screenName = ParamUtil.getString(req, "screenName");
String emailAddress = ParamUtil.getString(req, "emailAddress");
String firstName = ParamUtil.getString(req, "firstName");
String middleName = ParamUtil.getString(req, "middleName");
String lastName = ParamUtil.getString(req, "lastName");
int prefixId = ParamUtil.getInteger(req, "prefixId");
int suffixId = ParamUtil.getInteger(req, "suffixId");
boolean male = ParamUtil.get(req, "male", true);
int birthdayMonth = ParamUtil.getInteger(req, "birthdayMonth");
int birthdayDay = ParamUtil.getInteger(req, "birthdayDay");
int birthdayYear = ParamUtil.getInteger(req, "birthdayYear");
String jobTitle = ParamUtil.getString(req, "jobTitle");
long organizationId = ParamUtil.getLong(req, "organizationId");
long locationId = ParamUtil.getLong(req, "locationId");
//edit zy begin
String companyname = ParamUtil.getString(req, "companyname");
String telphone = ParamUtil.getString(req, "telphone");
//edit zy end
boolean sendEmail = true;
CaptchaUtil.check(req);
//edit zy begin
//addUser(,companyname,telphone)
User user = UserServiceUtil.addUser(
company.getCompanyId(), autoPassword, password1, password2,
autoScreenName, screenName, emailAddress, themeDisplay.getLocale(),
firstName, middleName, lastName, prefixId, suffixId, male,
birthdayMonth, birthdayDay, birthdayYear, jobTitle, organizationId,
locationId, sendEmail,companyname,telphone);
|
把UserServiceUtil.addUser(
company.getCompanyId(), autoPassword, password1, password2,
autoScreenName, screenName, emailAddress, themeDisplay.getLocale(),
firstName, middleName, lastName, prefixId, suffixId, male,
birthdayMonth, birthdayDay, birthdayYear, jobTitle, organizationId,
locationId, sendEmail);
改成UserServiceUtil.addUser(
company.getCompanyId(), autoPassword, password1, password2,
autoScreenName, screenName, emailAddress, themeDisplay.getLocale(),
firstName, middleName, lastName, prefixId, suffixId, male,
birthdayMonth, birthdayDay, birthdayYear, jobTitle, organizationId,
locationId, sendEmail,companyname,telphone);
改完后发现此有错误还需要到UserServiceUtil.java中修改它的addUser,就这样
需要修改如下java文件
Com.liferay.portal.action.OpenIdResponseAction (portal-impl.jar)
Com.liferay.portal.model.impl.UserImpl (portal-impl.jar)
Com.liferay.portal.security.auth.OpenSSOAuologin (portal-impl.jar)
Com.liferay.portal.service.impl.UserLocalServiceImpl (portal-impl.jar)
Com.liferay.portlet.myaccount.action.AddUserAction (portal-impl.jar)
Com.liferay.portal.model.UserModel (portal-service.jar)
Com.liferay.portal.service.UserLocalService (portal-service.jar)
Com.liferay.portal.service.UserLocalServiceUtil (portal-service.jar)
Com.liferay.portal.service.UserService (portal-service.jar)
Com.liferay.portal.service.UserServiseUtil (portal-service.jar)
Com.liferay.test.spring.remoting.portal.PortalHttpTest(liferay测试用,不属于任何包)
Com.liferay.portal.service.impl.UserServiceImpl (portal-impl.jar)
Com.liferay.portal.model.impl.UserModelImpl (portal-impl.jar)
Com.liferay.portal.model.impl.UserImpl (portal-impl.jar)
Com.liferay.portal.service.http.UserServiseJSON (portal-impl.jar)
Com.liferay.portal.service.impl.CompanyLocalServiceImpl (portal-impl.jar)
Com.liferay.portal.service.http.UserServiceSoap (portal-impl.jar)
Com.liferay.portal.servicesecurity.ldap.PortalLDAPUtil (portal-impl.jar)
Com.liferay.portal.enterpriseadmin.admin.EditUserAction (portal-impl.jar)
Com.liferay.portal.service.http.UserServiceHttp (portal-impl.jar)
Com.liferay.test.spring.remoting.PortalHttpTest (liferay测试用,不属于任何包)
Com.liferay.portal.model.User (portal-impl.jar)
Com.liferay.portal.service.http.UserJSONSeriolizer (portal-impl.jar)
Com.liferay.test.http.portal.PortalHttpTest (liferay测试用,不属于任何包)
|
8.修改完成后在eclipse下编译,然后把对应的class文件拷到portal-impl.jar和portal-service.jar中,替换tomcat下的这两个包,重启tomcat,这么多class文件我是通过手工一个一个拷贝替换的,我想通过ant build.xml应该可以自动生成新的portal-impl.jar,portal-service.jar
======================================================================================================完=====================================================
修改完注册,那么就必须让用户能够修改这两个新添字段的信息,因此需要修改my account 处的代码/webapps/ROOT/html/portlet/enterprise_admin/edit_user_profile.jspfm和第一个例子一样查找发现需要修改com.liferay.portlet.enterpriseadmin.action. EditUserAction的updateUser方法,这样,跟第一个例子类似需要修改如下java文件
Com.liferay.portlet.enterpriseadmin.action.EditUserAction
Com.liferay.portal.service.UserServiceJSON
Com.liferay.portal.service.http.UserServiceSoap
Com.liferay.portal.service.impl.UserServiceImpl
Com.liferay.portal.service.UserLocalServiceUtil
Com.liferay.portal.serviceLocalService
Com.liferay.portal.service.impl.UserLocalServiceImpl
Com.liferay.portal.security.ldap.PortalLDAPUtil
Com.liferay.portlet.adminUtil
Com.liferay.portlet.Lanaguage.action.ViewAcion
|