在我的view.jsp页面中,我从Eclipse中获得了重复的局部变量contact
错误。但是,不存在重复变量。当我运行portlet时出现此错误
An error occurred at line: 25 in the jsp file: /html/contact/view.jsp
Type mismatch: cannot convert from com.bcnet.portlet.biobank.model.Contact to com.liferay.portal.model.Contact
22: total="<%= ContactLocalServiceUtil.getContactsCount() %>"
23: />
我使用自己的联系人实体,view.jsp
的代码如下
<%@ include file="/html/init.jsp" %>
<%!
com.liferay.portal.kernel.dao.search.SearchContainer<Contact> searchContainer = null;
%>
<%
String redirect = PortalUtil.getCurrentURL(renderRequest);
%>
<aui:button-row>
<portlet:renderURL var="addContactURL">
<portlet:param name="mvcPath" value="/html/contact/edit_contact.jsp" />
<portlet:param name="redirect" value="<%= redirect %>" />
</portlet:renderURL>
<aui:button onClick="<%= addContactURL.toString() %>" value="add-contact" />
</aui:button-row>
<liferay-ui:search-container emptyResultsMessage="contact-empty-results-message">
<liferay-ui:search-container-results
results="<%= ContactLocalServiceUtil.getAllContacts(searchContainer.getStart(), searchContainer.getEnd()) %>"
total="<%= ContactLocalServiceUtil.getContactsCount() %>"
/>
<liferay-ui:search-container-row
className="com.bcnet.portlet.biobank.model.Contact"
keyProperty="contactId"
modelVar="contact" escapedModel="<%= true %>"
>
<liferay-ui:search-container-column-text
name="name"
value="<%= contact.getFirstName()+\" \"+contact.getLastName() %>"
/>
<liferay-ui:search-container-column-text
name="phone"
property="phone"
/>
<liferay-ui:search-container-column-text
name="email"
property="email"
/>
<liferay-ui:search-container-column-text
name="address"
property="address"
/>
<liferay-ui:search-container-column-text
name="zip"
property="zip"
/>
<liferay-ui:search-container-column-text
name="city"
property="city"
/>
<%
String country = "";
try {
country = CountryLocalServiceUtil.getCountry(contact.getCountry()).getName();
} catch (Exception e) {
}
%>
<liferay-ui:search-container-column-text
name="country"
value="<%= country %>"
/>
<%
String juristicPersonName = "";
try {
juristicPersonName = JuristicPersonLocalServiceUtil.getJuristicPerson
(contact.getJuristicPersonId()).getName();
}
catch (Exception e) {
}
%>
<liferay-ui:search-container-column-text
name="juristicPersonName"
value="<%= juristicPersonName %>"
/>
<liferay-ui:search-container-column-text
name="department"
property="department"
/>
<liferay-ui:search-container-column-text
name="orcId"
property="orcId"
/>
<liferay-ui:search-container-column-jsp
align="right"
path="/html/contact/contact_actions.jsp"
/>
</liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container>
答案 0 :(得分:1)
您似乎有两个进口。并且您正在尝试将liferay Contact对象转换为biobank Contact。 删除其中一个导入,然后重试。
答案 1 :(得分:0)
对于我的自定义联系人实体,init.jsp中的导入似乎都是正确的。
<%@ page import="com.bcnet.portlet.biobank.model.Contact" %>
<%@ page import="com.bcnet.portlet.biobank.service.ContactLocalServiceUtil"%>
可能是liferay的预定义联系类型com.liferay.portal.model.Contact
似乎也在同一范围内导入,这可能导致了问题。因此Type mismatch: cannot convert from com.bcnet.portlet.biobank.model.Contact to com.liferay.portal.model.Contact
。
解决方法是为modelVar
属性赋予contact
以外的biobankContact
以外的值<liferay-ui:search-container-row
className="com.bcnet.portlet.biobank.model.Contact"
keyProperty="contactId"
modelVar="contact" escapedModel="<%= true %>"
>
。所以改变这个
<liferay-ui:search-container-row
className="com.bcnet.portlet.biobank.model.Contact"
keyProperty="contactId"
modelVar="biobankContact" escapedModel="<%= true %>"
>
以强>
{{1}}
似乎解决了这个问题。