动态获取数据库中表的字段的名:
public static void getPrefenceColumn(PortletRequest portletRequest) throws NumberFormatException, PortalException, SystemException { PortletPreferences preferences = portletRequest.getPreferences();
//这个值是需要setValue(); String columnsIds = preferences.getValue("default.display.columns", ""); List<CompanyColumnDefinition> tableHeader = null; if (!columnsIds.equals(StringPool.BLANK)) { String[] columnIdsArray = columnsIds.split(StringPool.COMMA); tableHeader = new ArrayList<CompanyColumnDefinition>(); for (int i = 0; i < columnIdsArray.length; i++) { CompanyColumnDefinition companyColumn = CompanyColumnDefinitionLocalServiceUtil .getCompanyColumnDefinition(Long.valueOf(columnIdsArray[i])); tableHeader.add(companyColumn); } } portletRequest.setAttribute("tableHeader", tableHeader); }
2:就是setValue
public void defaultDisplayColumn(PortletRequest renderRequest) throws ReadOnlyException, SystemException, ValidatorException, IOException, NumberFormatException, PortalException { long companyId = PortalUtil.getCompanyId(renderRequest); PortletPreferences preferences = renderRequest.getPreferences(); String columnsIds = preferences.getValue("default.display.columns", ""); // 这些字段是不是直接在页面上显示。 String columns = "employeeNo,employeeName,positionId,employeeSex,employeeAge,mobilePhone"; if (columnsIds.equals("")) { String tableName = TableConst.CRM_Employee; String[] columnsArray = columns.split(StringPool.COMMA); StringBuffer columnIds = new StringBuffer(); for (int i = 0; i < columnsArray.length; i++) { CompanyColumnDefinition companyColumn = CompanyColumnDefinitionLocalServiceUtil .searchByColumnName(companyId, tableName, columnsArray[i]); columnIds.append( String.valueOf(companyColumn .getCompanyColumnDefinitionId())).append( StringPool.COMMA); } preferences.setValue("default.display.columns", columnIds.toString()); if (SessionErrors.isEmpty(renderRequest)) { preferences.store(); } } }
怎么动态获得字段的值:
public static Map<String, String> getEmployeeValue(PortletRequest portletRequest, Long employeeId) throws PortalException, SystemException { Map<String, String> entityValueMap = null; long companyId = PortalUtil.getCompanyId(portletRequest); if (employeeId > 0){ Employee employee = EmployeeLocalServiceUtil.getEmployee(employeeId); if (employee != null){ List<CompanyColumnDefinition> companyColumns = CompanyColumnDefinitionLocalServiceUtil .searchByTableName(companyId, TableConst.CRM_Employee, true); entityValueMap = new HashMap<String, String>(); for (CompanyColumnDefinition companyColumn : companyColumns) { String columnName = companyColumn.getColumnName(); if (columnName.equals("employeeName")) { entityValueMap.put(columnName, employee.getEmployeeName()); } else if (columnName.equals("employeeNo")) { entityValueMap.put(columnName, employee.getEmployeeNo()); } else if (columnName.equals("employeeAge")) { entityValueMap.put(columnName, employee.getEmployeeAge() != 0 ? String.valueOf(employee.getEmployeeAge()) : ""); } else if (columnName.equals("employeeSex")) { entityValueMap.put(columnName, employee.getEmployeeSex()); } else if (columnName.equals("identityCard")) { entityValueMap.put(columnName, employee.getIdentityCard()); } else if (columnName.equals("nation")) { entityValueMap.put(columnName, employee.getNation()); } else if (columnName.equals("category")) { entityValueMap.put(columnName, employee.getCategory()); } else if (columnName.equals("policitalStatus")) { entityValueMap.put(columnName, employee.getPolicitalStatus()); } else if (columnName.equals("isMarry")) { entityValueMap.put(columnName, employee.getIsMarry()); } else if (columnName.equals("employeeType")) { entityValueMap.put(columnName, employee.getEmployeeType()); } else if (columnName.equals("mobilePhone")) { entityValueMap.put(columnName, employee.getMobilePhone()); } else if (columnName.equals("workPhone")) { entityValueMap.put(columnName, employee.getWorkPhone()); } else if (columnName.equals("email")) { entityValueMap.put(columnName, employee.getEmail()); } else if (columnName.equals("QQ")) { entityValueMap.put(columnName, employee.getQQ()); } else if (columnName.equals("MSN")) { entityValueMap.put(columnName, employee.getMSN()); } else if (columnName.equals("zodiac")) { entityValueMap.put(columnName, employee.getZodiac()); } else if (columnName.equals("constellation")) { entityValueMap.put(columnName, employee.getConstellation()); } else if (columnName.equals("microblog")) { entityValueMap.put(columnName, employee.getMicroblog()); } else if (columnName.equals("interest")) { entityValueMap.put(columnName, employee.getInterest()); } else if (columnName.equals("homePhone")) { entityValueMap.put(columnName, employee.getHomePhone()); } else if (columnName.equals("emergencyPhone")) { entityValueMap.put(columnName, employee.getEmergencyPhone()); } else if (columnName.equals("educationlevel")) { entityValueMap.put(columnName, employee.getEducationlevel()); } else if (columnName.equals("degree")) { entityValueMap.put(columnName, employee.getDegree()); } else if (columnName.equals("graduatedUniversity")) { entityValueMap.put(columnName, employee.getGraduatedUniversity()); } else if (columnName.equals("specialty")) { entityValueMap.put(columnName, employee.getSpecialty()); } else if (columnName.equals("householdRegister")) { entityValueMap.put(columnName, employee.getHouseholdRegister()); } else if (columnName.equals("technicalTitle")) { entityValueMap.put(columnName, employee.getTechnicalTitle()); } else if (columnName.equals("dimissionType")) { entityValueMap.put(columnName, employee.getDimissionType()); } else if (columnName.equals("recruitmentResource")) { entityValueMap.put(columnName, employee.getRecruitmentResource()); } else if (columnName.equals("wageAccount")) { entityValueMap.put(columnName, employee.getWageAccount()); } else if (columnName.equals("healthCareAccount")) { entityValueMap.put(columnName, employee.getHealthCareAccount()); } else if (columnName.equals("accumulationFundAccount")) { entityValueMap.put(columnName, employee.getAccumulationFundAccount()); } else if (columnName.equals("unemploymentInsurance")) { entityValueMap.put(columnName, employee.getUnemploymentInsurance()); } else if (columnName.equals("socialInsurance")) { entityValueMap.put(columnName, employee.getSocialInsurance()); } else if (columnName.equals("endowmentInsurance")) { entityValueMap.put(columnName, employee.getEndowmentInsurance()); } else if (columnName.equals("homeAddress")) { entityValueMap.put(columnName, employee.getHomeAddress()); } else if (columnName.equals("archivesAddress")) { entityValueMap.put(columnName, employee.getArchivesAddress()); } else if (columnName.equals("workAddress")) { entityValueMap.put(columnName, employee.getWorkAddress()); } else if (columnName.equals("employeeStatus")) { entityValueMap.put(columnName, employee.getEmployeeStatus()); } else if (columnName.equals("workAddress")) { entityValueMap.put(columnName, employee.getWorkAddress()); } else if (columnName.equals("dimissionReason")) { entityValueMap.put(columnName, employee.getDimissionReason()); } else if (columnName.equals("workAddress")) { entityValueMap.put(columnName, employee.getWorkAddress()); } else if (columnName.equals("birthDate")) { entityValueMap.put(columnName, DateUtil.formatDateNoHour(employee.getBirthDate())); } else if (columnName.equals("internshipStart")) { entityValueMap.put(columnName, DateUtil.formatDateNoHour(employee.getInternshipStart())); } else if (columnName.equals("internshipEnd")) { entityValueMap.put(columnName, DateUtil.formatDateNoHour(employee.getGraduatedDate())); } else if (columnName.equals("graduatedDate")) { entityValueMap.put(columnName, DateUtil.formatDateNoHour(employee.getInternshipEnd())); } else if (columnName.equals("contractStart")) { entityValueMap.put(columnName, DateUtil.formatDateNoHour(employee.getContractStart())); } else if (columnName.equals("contractEnd")) { entityValueMap.put(columnName, DateUtil.formatDateNoHour(employee.getContractEnd())); } else if (columnName.equals("onTrialDate")) { entityValueMap.put(columnName, DateUtil.formatDateNoHour(employee.getOnTrialDate())); } else if (columnName.equals("offTrialDate")) { entityValueMap.put(columnName, DateUtil.formatDateNoHour(employee.getOffTrialDate())); } else if (columnName.equals("entryDate")) { entityValueMap.put(columnName, DateUtil.formatDateNoHour(employee.getEntryDate())); } else if (columnName.equals("dimissionDate")) { entityValueMap.put(columnName, DateUtil.formatDateNoHour(employee.getDimissionDate())); } else if (columnName.equals("createDate")) { entityValueMap.put(columnName, DateUtil.formatDateNoHour(employee.getCreateDate())); } else if (columnName.equals("positionId")) { long positionId = employee.getPositionId(); if (positionId > 0) { Position position = PositionLocalServiceUtil.getPosition(positionId); entityValueMap.put(columnName, position.getPosition()); } else { entityValueMap.put(columnName, StringPool.BLANK); } } else if (columnName.equals("departmentId")) { long departmentId = employee.getDepartmentId(); if (departmentId > 0) { Department department = DepartmentLocalServiceUtil.getDepartment(departmentId); entityValueMap.put(columnName, department.getDepartmentName()); } else { entityValueMap.put(columnName, StringPool.BLANK); } } else if (columnName.equals("createUserId")) { long createUserId = employee.getCreateUserId(); if (createUserId > 0) { User user = UserLocalServiceUtil.getUser(createUserId); entityValueMap.put(columnName, user.getScreenName()); } else { entityValueMap.put(columnName, StringPool.BLANK); } } else if (columnName.equals("strField1")){ entityValueMap.put(columnName, employee.getStrField1()); } else if (columnName.equals("strField2")){ entityValueMap.put(columnName, employee.getStrField2()); } else if (columnName.equals("strField3")){ entityValueMap.put(columnName, employee.getStrField3()); } else if (columnName.equals("strField4")){ entityValueMap.put(columnName, employee.getStrField4()); } else if (columnName.equals("strField5")){ entityValueMap.put(columnName, employee.getStrField5()); } else if (columnName.equals("strField6")){ entityValueMap.put(columnName, employee.getStrField6()); } else if (columnName.equals("strField7")){ entityValueMap.put(columnName, employee.getStrField5()); } else if (columnName.equals("strField8")){ entityValueMap.put(columnName, employee.getStrField6()); } else if (columnName.equals("textareaField1")){ entityValueMap.put(columnName, employee.getTextareaField1()); } else if (columnName.equals("textareaField2")){ entityValueMap.put(columnName, employee.getTextareaField2()); } else if (columnName.equals("textareaField3")){ entityValueMap.put(columnName, employee.getTextareaField1()); } else if (columnName.equals("textareaField4")){ entityValueMap.put(columnName, employee.getTextareaField2()); } else if (columnName.equals("floatField1")){ entityValueMap.put(columnName, String.valueOf(employee.getFloatField1() == 0 ? "" : employee.getFloatField1())); } else if (columnName.equals("floatField2")){ entityValueMap.put(columnName, String.valueOf(employee.getFloatField2() == 0 ? "" : employee.getFloatField2())); } else if (columnName.equals("floatField3")){ entityValueMap.put(columnName, String.valueOf(employee.getFloatField3() == 0 ? "" : employee.getFloatField3())); } else if (columnName.equals("floatField4")){ entityValueMap.put(columnName, String.valueOf(employee.getFloatField4() == 0 ? "" : employee.getFloatField4())); } else if (columnName.equals("dateField1")){ entityValueMap.put(columnName, DateUtil.formatDateNoHour(employee.getDateField1())); } else if (columnName.equals("dateField2")){ entityValueMap.put(columnName, DateUtil.formatDateNoHour(employee.getDateField2())); } else if (columnName.equals("dateField3")){ entityValueMap.put(columnName, DateUtil.formatDateNoHour(employee.getDateField3())); } else if (columnName.equals("dateField4")){ entityValueMap.put(columnName, DateUtil.formatDateNoHour(employee.getDateField4())); } } } } return entityValueMap; }