掲示板

Search Container simple example question

11年前 に Dimitris Papadopoulos によって更新されました。

Search Container simple example question

New Member 投稿: 10 参加年月日: 12/08/13 最新の投稿
Hello,

I am trying to get familiar with the search container in order to display some data from a MySQL database. For start, i don't care about pagination, sorting, etc... I just want to make it work emoticon

I have a very simple table, take a look to my service.xml:

<namespace>Student</namespace>
    <entity name="Student" local-service="true" remote-service="true">
        <column name="id" type="int" primary="true"></column>
        <column name="name" type="String"></column>
        <column name="eponymo" type="String"></column>
    </entity>


In my StudentLocalServiceImpl.java file i have the

public List<student> getAllStudents () throws SystemException
{
		List<student> stud = studentPersistence.findAll();
		return stud;
}
</student></student>

that returns (i suppose) a List of all my students from the MySQL table

Finally, in my view.jsp i have the following:

<liferay-ui:search-container delta="10" emptyresultsmessage="no-users-were-found">
	<liferay-ui:search-container-results results="<%= StudentLocalServiceUtil.getAllStudents()
		%>" />

	<liferay-ui:search-container-row classname="id" keyproperty="id" modelvar="id">
		<liferay-ui:search-container-column-text name="name" property="name" />
	</liferay-ui:search-container-row>

	<liferay-ui:search-iterator />

</liferay-ui:search-container>

and i have also included the
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
and
<%@ page import="com.liferay.samples.service.StudentLocalServiceUtil" %>

I am expecting to have a simple table with only one column and the all the rows from my data. But i deploy my portlet and i get "HelloTest is temporarily unavailable."

Any help?? emoticon
thumbnail
11年前 に Sagar A Vyas によって更新されました。

RE: Search Container simple example question

Liferay Master 投稿: 679 参加年月日: 09/04/17 最新の投稿
I am expecting to have a simple table with only one column and the all the rows from my data. But i deploy my portlet and i get "HelloTest is temporarily unavailable."


What is an error in console ?
11年前 に Dimitris Papadopoulos によって更新されました。

RE: Search Container simple example question

New Member 投稿: 10 参加年月日: 12/08/13 最新の投稿
Thanks for your replies! emoticon

Here it is what i get to the console:

17:28:37,892 ERROR [PortletRequestDispatcherImpl:108] org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 29 in the jsp file: /view.jsp
id cannot be resolved to a type
26: 		%&gt;"
27: 	/&gt;
28: 
29: 	<liferay-ui:search-container-row 30: classname="id" 31: keyproperty="id" 32: modelvar="id" an error occurred at line: 252 in the generated java file id cannot be resolved to a type < code></liferay-ui:search-container-row>
<br><br>The truth is that i didn't know that i can get useful debugging info from the console..
11年前 に Dimitris Papadopoulos によって更新されました。

RE: Search Container simple example question

New Member 投稿: 10 参加年月日: 12/08/13 最新の投稿
I read to the Liferay wiki for the liferay-ui:search-container-row
className - The type of Object in your List. In this case, we have a List of User objects.
keyProperty - Primary Key
modelVar - The name of the variable to represent your model. In this case the model is the User object.

http://www.liferay.com/community/wiki/-/wiki/Main/SearchContainer

I am not sure what i have to fill in my portlet...

edit: I made a guess and i tried something like:
<liferay-ui:search-container-row classname="[b]com.liferay.samples.model.impl.StudentModelImpl[/b]" keyproperty="id" modelvar="student"></liferay-ui:search-container-row>

I can get the results from the db but when i insert a new record to the db i have to re-deploy the portlet in order to display the new records. It's clear that i am missing something :p
thumbnail
11年前 に Sagar A Vyas によって更新されました。

RE: Search Container simple example question

Liferay Master 投稿: 679 参加年月日: 09/04/17 最新の投稿
I can get the results from the db but when i insert a new record to the db i have to re-deploy the portlet in order to display the new records. It's clear that i am missing something :p


Yes, you have mentioned impl instead of Model, please refer above answer.

Hope that will help you.

Thanks,
Sagar Vyas
11年前 に Dimitris Papadopoulos によって更新されました。

RE: Search Container simple example question

New Member 投稿: 10 参加年月日: 12/08/13 最新の投稿
Thanks again for your time emoticon

According to the example i have modified my source code

<liferay-ui:search-container delta="10" emptyresultsmessage="no-users-were-found">
	<liferay-ui:search-container-results results="<%= StudentLocalServiceUtil.getAllStudents()
		%>" [b]total="<%= StudentLocalServiceUtil.getStudentsCount()[/b]
		%>" />

	<liferay-ui:search-container-row classname="[b]com.liferay.samples.model.Student[/b]" keyproperty="id" modelvar="student">
		<liferay-ui:search-container-column-text name="name" property="name" />
		
		<liferay-ui:search-container-column-text name="eponymo" property="eponymo" />
		
	</liferay-ui:search-container-row>

	<liferay-ui:search-iterator />

</liferay-ui:search-container>


All data appears OK. But when a new row is added to the MySQL table and i refresh the page i can't get the new rows to my results... I have to re-deploy the portlet (edit: or to restart the Tomcat)!
It's seems that the portlet works like a "static" page...???
thumbnail
11年前 に Sagar A Vyas によって更新されました。

RE: Search Container simple example question

Liferay Master 投稿: 679 参加年月日: 09/04/17 最新の投稿
Please refer my code you will get idea..Just try to keep total and result as per my code.

And inform me whether it is working or not.

Thanks,
Sagar Vyas
11年前 に Dimitris Papadopoulos によって更新されました。

RE: Search Container simple example question

New Member 投稿: 10 参加年月日: 12/08/13 最新の投稿
Based on your example code everything is fine now! emoticon The problem was to getStart(), getEnd() methods.
Thanks again for your patient and your help ;)

Regards,
A php expert but a java n00b
thumbnail
11年前 に Sagar A Vyas によって更新されました。

RE: Search Container simple example question

Liferay Master 投稿: 679 参加年月日: 09/04/17 最新の投稿
Dimitris Papadopoulos:
Based on your example code everything is fine now! emoticon The problem was to getStart(), getEnd() methods.
Thanks again for your patient and your help ;)

Regards,
A php expert but a java n00b


Good See its finally working for you emoticon

Enjoy Liferay !!

Please mark answer.

Thanks,
Sagar Vyas
11年前 に Dimitris Papadopoulos によって更新されました。

RE: Search Container simple example question

New Member 投稿: 10 参加年月日: 12/08/13 最新の投稿
Finally it's not working 100%... emoticon

I initialize the search container according your example:

<liferay-ui:search-container-results results="<%= StudentLocalServiceUtil.getStudents(searchContainer.getStart(), searchContainer.getEnd()) %>" total="<%=StudentLocalServiceUtil.countstudents() %>" />


I have also put some "debug" code:

System.out.println("Total:");
System.out.println(searchContainer.getTotal());
System.out.println("Start:");
System.out.println(searchContainer.getStart());
System.out.println("End:");
System.out.println(searchContainer.getEnd());


Now, let's say that i have 8 records. Everything appears OK.
If i delete one record, everything works OK, total updates to 7
But, if i add one record the Total is not updating to 9!!! On the other hand i can see the 9th record to my results...
I have to re-deploy the portlet or restart tomcat

Any idea?
This is the way i get the total:

public int countstudents () throws SystemException
	{
		long stud = studentPersistence.countAll();
		int count = (int) stud;
		return count;
		
	}
thumbnail
11年前 に Sagar A Vyas によって更新されました。

RE: Search Container simple example question

Liferay Master 投稿: 679 参加年月日: 09/04/17 最新の投稿
Hi,


<liferay-ui:search-container-row
className="id"
keyProperty="id"
modelVar="id"
>


Soooooo Obvious it will throw error emoticon.

Please find sample searchContainer code. (Working)


<liferay-ui:search-container delta="10" emptyresultsmessage="book-empty-results-message">
	<liferay-ui:search-container-results results="<%= BookLocalServiceUtil.getBooksByGroupId(scopeGroupId, searchContainer.getStart(), searchContainer.getEnd()) %>" total="<%= BookLocalServiceUtil.getBooksCountByGroupId(scopeGroupId) %>" />

	<liferay-ui:search-container-row classname="com.liferay.training.library.model.Book" model class name keyproperty="bookId" primary key of your table modelvar="book" variable>
		
		<liferay-ui:search-container-column-text name="author-name" property="authorName" />
	     
               <liferay-ui:search-container-column-text name="title" value="<%= book.getTitle() %>" />

	</liferay-ui:search-container-row>

	<liferay-ui:search-iterator />
</liferay-ui:search-container>

thumbnail
11年前 に Hitoshi Ozawa によって更新されました。

RE: Search Container simple example question

Liferay Legend 投稿: 7942 参加年月日: 10/03/24 最新の投稿
As Sagar asked, when temporary unavailable message appears, there's something wrong with your portlet and there should be some error messages in your liferay console or log file. Sometimes, it's just a typo error or a syntax error. It's very difficult to answer your question without knowing the error messages.