掲示板

VM exception in Custom Navigation.vm file

thumbnail
13年前 に Chris Becker によって更新されました。

VM exception in Custom Navigation.vm file

Regular Member 投稿: 112 参加年月日: 10/06/11 最新の投稿
Hi all

I have developed a custom theme that attempts to provide a single navigation bar that represents all organizations in a corporate intranet. The top level navigation pages use page types of "URL", each pointing to the home page of each organization. I am using LayoutLocalServiceUtil and GroupLocalServiceUtil to get the pages for the top group, then iterate through each to get the list of pages and sub-pages for each of the organizations.

Here is the code in navigation.vm:
#set ($LayoutLocalService = $portal.getClass().forName("com.liferay.portal.service.LayoutLocalServiceUtil").getMethod("getService", null).invoke(null, null))
#set ($GroupLocalService =  $portal.getClass().forName("com.liferay.portal.service.GroupLocalServiceUtil").getMethod("getService", null).invoke(null, null))
#set($localLayouts = $LayoutLocalService.getLayouts($GroupLocalService.getGroup($company_id, "Optimum Lightpath").getGroupId(), false, $getterUtil.getLong("0")))


	    
  <ul id="menu">
        #foreach ($page in $localLayouts)
	        #set ($page_name = $page.getName($locale))
			<!-- Begin 4 columns Item -->
	        <li class="drop">&nbsp;<a href="$page.getRegularURL($request)" target="$page.getTarget()"><span>$page_name</span></a>
               #if(${page_name}!= "Welcome")
    			<div class="dropdown_4columns">			     
    				#set($myIterator1 = $LayoutLocalService.getLayouts($GroupLocalService.getFriendlyURLGroup($company_id, "/${page_name}").getGroupId(), false, $getterUtil.getLong("0")))

                         #foreach($page1 in $myIterator1)
     				     <div class="col_1">
							#set($page1_name = $page1.getName($locale))    						
    							<a href="$page1.getRegularURL($request)" target="$page1.getTarget()"><h3>$page1_name</h3></a>
    						  ## Next menu level
    						  #set ($nav_count = $page1.getChildren())
    						    #if($nav_count.size() &gt; 0)
    						    

    							<ul class="col_1">
    								#foreach ($page2 in $nav_count)
    							   <li>
    								<a href="$page2.getRegularURL($request)" target="$page2.getTarget()" ">$page2.getName()</a>
    						      </li>
    								#end
                                </ul>

    						   #end
	                     </div>
    					 #end
			   </div></li>
			  #else
              
			  #end
        #end

  </ul>


This approach works fine as long as the organization exists first and the menu name matches the organization name. If the menu gets added first, the following line in navigation.vm causes an error and nothing is displayed:

#set($myIterator1 = $LayoutLocalService.getLayouts($GroupLocalService.getFriendlyURLGroup($company_id, "/${page_name}").getGroupId(), false, $getterUtil.getLong("0")))


Could anyone suggest a way to keep this from occurring? Velocity does not have exception handling, as far as I know. Any thoughts or suggestions would be appreciated - thanks!

Regards,

--Chris
thumbnail
13年前 に Chris Becker によって更新されました。

RE: VM exception in Custom Navigation.vm file

Regular Member 投稿: 112 参加年月日: 10/06/11 最新の投稿
OK, found a Wiki article, Access Liferay Service Locator that makes reference to a second method, named findExceptionSafeService, that, according to the article, "which wraps the underlying service with a proxy which catches any exceptions and simply returns null." This sounded like a possible approach, but I am unable to locate said method, which I guess is no longer present. I looked in the VelocityVariables.java file and found the following method that sets the $serviceLocator velocity variable:
 _insertHelperUtility( velocityContext, restrictedVariables, "serviceLocator", serviceLocator);
with serviceLocator having a findService method, but no findExceptionSafeService method. Was this removed? Anybody know? Thoughts and/or possible solutions/approaches appreciated, as always. --Chris
thumbnail
12年前 に Richard Gibson によって更新されました。

RE: VM exception in Custom Navigation.vm file

Junior Member 投稿: 30 参加年月日: 10/02/19 最新の投稿
Did you find out anything about the availability of the findExceptionSafeService call?

Cheers

Richard