Foros de discusión
Duplicate local variable contact
Suyesh Amatya, modificado hace 9 años.
Duplicate local variable contact
Junior Member Mensajes: 61 Fecha de incorporación: 22/08/14 Mensajes recientes
In my view.jsp page I am getting the above mentioned error from Eclipse. However there is no duplicate variable present. When I run the portlet I get this error
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: />
I am using my own Contact entity the code for view.jsp is as below
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: />
I am using my own Contact entity the code for view.jsp is as below
<%@ 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-column-text></liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container></contact>
Mayur Patel, modificado hace 9 años.
RE: Duplicate local variable contact
Expert Mensajes: 358 Fecha de incorporación: 17/11/10 Mensajes recientes
Can you try this?
<liferay-ui:search-container-row
className="com.liferay.portal.model.Contact"
keyProperty="contactId"
modelVar="contact" escapedModel="<%= true %>">
<liferay-ui:search-container-row
className="com.liferay.portal.model.Contact"
keyProperty="contactId"
modelVar="contact" escapedModel="<%= true %>">
Suyesh Amatya, modificado hace 9 años.
RE: Duplicate local variable contact
Junior Member Mensajes: 61 Fecha de incorporación: 22/08/14 Mensajes recientesMayur Patel:
Can you try this?
<liferay-ui:search-container-row
className="com.liferay.portal.model.Contact"
keyProperty="contactId"
modelVar="contact" escapedModel="<%= true %>">
When I use this, the eclipse flags the same duplicate variable error. And also other errors that the methods are undefined for type Contact.
Pankaj Kathiriya, modificado hace 9 años.
RE: Duplicate local variable contact
Liferay Master Mensajes: 722 Fecha de incorporación: 5/08/10 Mensajes recientes
Well, you have set results of search-container as list of Contact objects(com.liferay.portal.model.Contact) and in search-container-row you are referring com.bcnet.portlet.biobank.model.Contact.
It seems you are having custom entity named as Contact, please use service API of that entity instead of liferay's Contact entity.
It seems you are having custom entity named as Contact, please use service API of that entity instead of liferay's Contact entity.
Suyesh Amatya, modificado hace 9 años.
RE: Duplicate local variable contact
Junior Member Mensajes: 61 Fecha de incorporación: 22/08/14 Mensajes recientesPankaj Kathiriya:
Well, you have set results of search-container as list of Contact objects(com.liferay.portal.model.Contact) and in search-container-row you are referring com.bcnet.portlet.biobank.model.Contact.
It seems you are having custom entity named as Contact, please use service API of that entity instead of liferay's Contact entity.
In my init.jsp page
I am using
<%@ page import="com.bcnet.portlet.biobank.model.Contact" %>
<%@ page import="com.bcnet.portlet.biobank.service.ContactLocalServiceUtil"%>
And in my view I have
<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-row></liferay-ui:search-container>
Does not it mean I am referring to my own ContactLocalServiceUtil and not of liferay's?
Mayur Patel, modificado hace 9 años.
RE: Duplicate local variable contact
Expert Mensajes: 358 Fecha de incorporación: 17/11/10 Mensajes recientes
Right ! it's referring to liferay's ContactLocalServiceUtil. Please check import stmt and see it is referring to custom entity.
Suyesh Amatya, modificado hace 9 años.
RE: Duplicate local variable contact
Junior Member Mensajes: 61 Fecha de incorporación: 22/08/14 Mensajes recientes
I have following imports
<%@ page import="com.bcnet.portlet.biobank.model.Contact" %>
<%@ page import="com.bcnet.portlet.biobank.service.ContactLocalServiceUtil"%>
which means I am referring to the custom classes, no? What I am missing here?
<%@ page import="com.bcnet.portlet.biobank.model.Contact" %>
<%@ page import="com.bcnet.portlet.biobank.service.ContactLocalServiceUtil"%>
which means I am referring to the custom classes, no? What I am missing here?
Mayur Patel, modificado hace 9 años.
RE: Duplicate local variable contact
Expert Mensajes: 358 Fecha de incorporación: 17/11/10 Mensajes recientes
imports are correct. this will only conflict when you are having two different jars having same model class inside same package.
Suyesh Amatya, modificado hace 9 años.
RE: Duplicate local variable contact
Junior Member Mensajes: 61 Fecha de incorporación: 22/08/14 Mensajes recientesMayur Patel:
imports are correct. this will only conflict when you are having two different jars having same model class inside same package.
New to liferay so dont quite know how to resolve this. How can i get over this issue?
Suyesh Amatya, modificado hace 9 años.
RE: Duplicate local variable contact (Respuesta)
Junior Member Mensajes: 61 Fecha de incorporación: 22/08/14 Mensajes recientes
The problem seems to be the contact variable in modelVar="contact" is already in use by Liferay and of type com.liferay.portal.model.Contact. So when I try to define the contact variable as com.bcnet.portlet.biobank.model.Contact it was showing the mentioned error.
The solution was to give the modelVar attribute some value other than contact say like "biobankContact". So something like this
Then it resolves the issue.
The solution was to give the modelVar attribute some value other than contact say like "biobankContact". So something like this
<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="biobankContact" escapedmodel="<%= true %>"></liferay-ui:search-container-row></liferay-ui:search-container>
Then it resolves the issue.
Mayur Patel, modificado hace 9 años.
RE: Duplicate local variable contact
Expert Mensajes: 358 Fecha de incorporación: 17/11/10 Mensajes recientes
Good to know this, Thanks for the info Suyesh