Wednesday, April 22, 2015

Configure tomcat for remote debugging:

Tomcat can be configured to allow a program such as eclipse to connect remotely using JPDA and see debugging information.
To configure tomcat to allow remote debugging, start tomcat using the catalina startup script (from your tomcat home) instead of the normal startup script like so (tomcat must be stopped before you can change over):
WIN:
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
bin/catalina.bat jpda start
UNIX:
export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket
bin/catalina.sh jpda start
We recommend adding this stuff to your startup script so that you are always running tomcat in debug mode.
  1. Open the startup script in (your_tomcat_home)/bin (WIN: startup.bat, UNIX: startup.sh)
  2. Add the following lines at the first blank line in the file (around line 8)
    WIN:
    set JPDA_ADDRESS=8000
    set JPDA_TRANSPORT=dt_socket
    UNIX:
    export JPDA_ADDRESS=8000
    export JPDA_TRANSPORT=dt_socket
  3. Change the execute line at the end to include jpda start
    WIN:
    call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
    UNIX:
    exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"
  4. Run the startup script when starting tomcat to run tomcat in debug mode
If you're concerned about opening up the known port for debugging, you can change the port on which JPDA listens by setting the JPDA_ADDRESS environment variable to something else (e.g. 38000).
Once you have tomcat configured and started, you can connect to your running tomcat instance using a number of debugging tools. For example, Eclipse has a debugging view that can help you work with tomcat via remote control.
Icon
NOTE:
If you are using Eclipse to debug tomcat remotely so in a Windows environment, you may want to prevent tomcat from launching as a separate process, which will prevent the console output from being captured by the Eclipse debugging view. To do so edit the file TOMCAT_HOME/bin/catalina.bat and change:
:doStart
shift
if not "%OS%" == "Windows_NT" goto noTitle
set _EXECJAVA=start "Tomcat" %_RUNJAVA%
goto gotTitle
:noTitle
set _EXECJAVA=start %_RUNJAVA%
to:
:doStart
shift
if not "%OS%" == "Windows_NT" goto noTitle
set _EXECJAVA= %_RUNJAVA%
goto gotTitle
:noTitle
set _EXECJAVA= %_RUNJAVA%

Thursday, August 21, 2014

Liferay's Search Container #
Here's a basic example that will help get you started:
<liferay-ui:search-container delta="10" emptyResultsMessage="no-users-were-found">
        <liferay-ui:search-container-results
               results="<%= UserLocalServiceUtil.search(
                       company.getCompanyId(), searchTerms.getKeywords(), searchTerms.getActiveObj(),
                       userParams, searchContainer.getStart(), searchContainer.getEnd(),
                       searchContainer.getOrderByComparator()); %>"
               total="<%= UserLocalServiceUtil.searchCount(
                       company.getCompanyId(), searchTerms.getKeywords(), searchTerms.getActiveObj(),
                       userParams); %>"
        />

        <liferay-ui:search-container-row
               className="com.liferay.portal.model.User"
               keyProperty="userId"
               modelVar="user"
        >
               <liferay-ui:search-container-column-text
                       name="name"
                       value="<%= user.getFullName() %>"
               />

               <liferay-ui:search-container-column-text
                       name="first-name"
                       property="firstName"
               />
        </liferay-ui:search-container-row>

        <liferay-ui:search-iterator />

</liferay-ui:search-container>

<liferay-ui:search-container delta="10" emptyResultsMessage="no-users-were-found">
This is the container. It performs a lot of set up work behind the scenes like instantiating the searchContainer object.
·         delta - The number of results per page
·         emptyResultsMessage - The message shown where there aren't results (it can be a key from your language.properties)
        <liferay-ui:search-container-results
               results="<%= UserLocalServiceUtil.search(
                       company.getCompanyId(), searchTerms.getKeywords(), searchTerms.getActiveObj(),
                       userParams, searchContainer.getStart(), searchContainer.getEnd(),
                       searchContainer.getOrderByComparator()); %>"
               total="<%= UserLocalServiceUtil.searchCount(
                       company.getCompanyId(), searchTerms.getKeywords(), searchTerms.getActiveObj(),
                       userParams); %>"
        />
·         results - This is where you input the results. results should be of type List. The important part is to make sure that your method supports some way to search from a beginning index to an end index in order to provide a good performance pagination. Note how we use searchContainer.getStart() for the first index and searchContainer.getEnd() for the second index. As mentioned above, the searchContainer object is available because it has been instantiated already. Some other methods you can use:
o    searchContainer.getStart() - gets starting index of current results page.
o    searchContainer.getResultsEnd() - gets ending index of current results page or index of last result (i.e. will return 3 if delta is 5 but there are only 3 results).
o    searchContainer.getEnd() - gets last index of current results page regardless of size of actually results (i.e. will return 5 if delta is 5 even if there is only 3 results. Will throw out of bounds errors).
o    searchContainer.getCur() - gets number of current results page.
o    searchContainer.setTotal() - must be set so getResultsEnd() knows when to stop.
·         total - This is where you input the total number of items in your list:
<liferay-ui:search-container-row className="com.liferay.portal.model.User" keyProperty="userId" modelVar="user">
·         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.
<liferay-ui:search-container-column-text name="name" value="<%= user.getFullName() %>" />
·         <liferay-ui:search-container-column-text> - Text column
o    name - Name of the column
o    value - Value of the column
o    href - the text in this coulmn will be a link the this URL
o    orderable - allows the user to order the list of items by this column:
<liferay-ui:search-container-column-text name="first-name" property="firstName" />
·         property - This will automatically look in the User object for the "firstName" property. It's basically the same thing as user.getFirstName().
Important to note here; regardless of attribute capitalisation in your service.XML, the property value must always start lower case. After that it seems to follow what you defined.
<liferay-ui:search-iterator />
·         <liferay-ui:search-iterator /> - This is what actually iterates through and displays the List
Hopefully, this gives you a jump start on how to use Liferay's SearchContainer in your own portlets.