[Building Sakai] take the value of site_id

Steve Swinsburg s.swinsburg at lancaster.ac.uk
Wed May 20 09:25:33 PDT 2009


If you use the Sakai App Builder and generate a JSP project, you will  
see that in the tool/src/java folder there is an additional bean that  
is injected with your ExternalLogicImpl via tool/src/webapp/WEB-INF/ 
applicationContext.xml

This makes your ExternalLogicImpl visible to the bean. you then need  
to get that bean into the JSP. It's a bit of a roundabout way but  
necessary to get classes visible and injected.

You've already setup the injection of the Sakai dependencies in your  
Impl (ie toolManager et al) and that looks fine. The last step you  
need is the bean in your webapp to link your Impl to the JSP.

You'll then see in the sample JSP files included in the application it  
builds, how to get that bean into your JSP.

JSP:
<%
WebApplicationContext context =  
WebApplicationContextUtils.getWebApplicationContext(application);
BakedBean bean = (BakedBean) context.getBean("bakedBean");
%>

Hello, <%= bean.getCurrentUserDisplayName() %>

then tool/src/webapp/WEB-INF/applicationContext.xml
<bean id="bakedBean"
	class="org.sakaiproject.yourtool.tool.BakedBean" init-method="init">
	<property name="externalLogic"  
ref="org.sakaiproject.yourtool.logic.ExternalLogic" />
</bean>



cheers,
Steve

---
Steve Swinsburg
Portal Systems Developer
Centre for e-Science
Lancaster University
Lancaster
LA1 4YT

email: s.swinsburg at lancaster.ac.uk
phone: +44 (0) 1524 594870







On 20 May 2009, at 17:12, menjuanpablo wrote:

>
> HI,
> whath package I have to import for ComponentManager classes.
>
>
> Branden wrote:
>>
>> menjuanpablo,
>>
>>>>>> <%! String aaa;
>>>>>>      ExternalLogicImpl eli=new ExternalLogicImpl();%>
>>>>>> <% aaa = eli.getCurrentSiteId(); %>
>>>>>> <%=aaa %>
>>
>> I'm not sure that ExternalLogicImpl would be accessible from your  
>> JSP in
>> your webapp. Can you try something like this instead:
>>
>> <%!
>> String aaa;
>> ExternalLogic eli = ComponentManager.get("
>> org.sakaiproject.metodologiagw.logic.ExternalLogic");
>> %><%
>> aaa = eli.getCurrentSiteId();
>> %>
>> <%= aaa %>
>>
>> Don't forget to import your ExternalLogic, and the ComponentManager
>> classes.
>>
>> Also, please post the error you're receiving. Without the error  
>> we're just
>> taking shots in the dark.
>>
>> Best,
>> ------------------------------------------
>> Branden Visser
>> LMS Application Programmer - Information Systems Services
>> Information Technology Services
>> University of Windsor
>>
>> sakai-dev-bounces at collab.sakaiproject.org wrote on 20/05/2009  
>> 09:15:15 AM:
>>
>>> menjuanpablo <menjuanpablo at gmail.com>
>>> Sent by: sakai-dev-bounces at collab.sakaiproject.org
>>>
>>> 20/05/2009 09:15 AM
>>>
>>> To
>>>
>>> sakai-dev at collab.sakaiproject.org
>>>
>>> cc
>>>
>>> Subject
>>>
>>> Re: [Building Sakai] take the value of site_id
>>>
>>>
>>> Ok, this is my components.xml
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
>>>   "http://www.springframework.org/dtd/spring-beans.dtd">
>>>
>>> <!-- This file generated by Sakai App Builder -AZ -->
>>> <beans>
>>>
>>>    <!-- Bring in the hibernate related beans -->
>>>    <import resource="spring-hibernate.xml" />
>>>    <import resource="sakai-hibernate.xml" />
>>>
>>>    <!-- create an external logic bean which abstracts out the Sakai
>> bits
>> -->
>>>    <bean id="org.sakaiproject.metodologiagw.logic.ExternalLogic"
>>>         
>>> class="org.sakaiproject.metodologiagw.logic.ExternalLogicImpl"
>>>        init-method="init">
>>>        <property name="functionManager"
>>> ref="org.sakaiproject.authz.api.FunctionManager" />
>>>        <property name="securityService"
>>> ref="org.sakaiproject.authz.api.SecurityService" />
>>>        <property name="sessionManager"
>>> ref="org.sakaiproject.tool.api.SessionManager" />
>>>        <property name="siteService"
>>> ref="org.sakaiproject.site.api.SiteService" />
>>>        <property name="toolManager"
>>> ref="org.sakaiproject.tool.api.ToolManager" />
>>>        <property name="userDirectoryService"
>>>            ref="org.sakaiproject.user.api.UserDirectoryService" />
>>>    </bean>
>>>
>>>    <!-- create a logic bean, give it the dao from above -->
>>>    <bean  
>>> id="org.sakaiproject.metodologiagw.logic.MetodologiagwLogic"
>>> class="org.sakaiproject.metodologiagw.logic.MetodologiagwLogicImpl"
>>>        init-method="init">
>>>        <property name="dao"
>>>             
>>> ref="org.sakaiproject.metodologiagw.dao.MetodologiagwDao" />
>>>        <property name="externalLogic"
>>>             
>>> ref="org.sakaiproject.metodologiagw.logic.ExternalLogic" />
>>>    </bean>
>>>    <!-- create an entity provider bean -->
>>>    <bean
>>>
>> class 
>> = 
>> "org 
>> .sakaiproject 
>> .metodologiagw.logic.entity.MetodologiagwEntityProvider">
>>>        <property name="logic"
>>> ref="org.sakaiproject.metodologiagw.logic.MetodologiagwLogic" />
>>>        <property name="developerHelperService"
>>> ref="org.sakaiproject.entitybroker.DeveloperHelperService" />
>>>    </bean>
>>> </beans>
>>>
>>>
>>> Steve Swinsburg-2 wrote:
>>>>
>>>> That looks ok, but it's a two step setup. Do you have the  
>>>> toolManager
>>>> bean injected into your impl in your components.xml? Post
>>>> components.xml as well, or any other spring config you have in  
>>>> pack/
>>>> src/webapp/WEB-INF/*.xml
>>>>
>>>>
>>>> cheers,
>>>> Steve
>>>>
>>>>
>>>> On 20/05/2009, at 12:19 AM, menjuanpablo wrote:
>>>>
>>>>>
>>>>> my externallogicimpl is
>>>>>
>>>>> public class ExternalLogicImpl implements ExternalLogic {
>>>>>
>>>>>   private static Log log =
>> LogFactory.getLog(ExternalLogicImpl.class);
>>>>>
>>>>>   private FunctionManager functionManager;
>>>>>   public void setFunctionManager(FunctionManager  
>>>>> functionManager) {
>>>>>      this.functionManager = functionManager;
>>>>>   }
>>>>>
>>>>>   private ToolManager toolManager;
>>>>>   public void setToolManager(ToolManager toolManager) {
>>>>>      this.toolManager = toolManager;
>>>>>   }
>>>>>   public String getCurrentSiteId(){
>>>>>      return toolManager.getCurrentPlacement().getContext();
>>>>>      }
>>>>> i take the toolManager defined above, but i don't know if this
>>>>> function is
>>>>> ok, actually i don't know if this toolManager is ok
>>>>>
>>>>>
>>>>>
>>>>> Steve Swinsburg-2 wrote:
>>>>>>
>>>>>> Ok in ExternalLogicImpl, where/how have you defined what  
>>>>>> toolManager
>>>>>> actually is.
>>>>>>
>>>>>> What is the error you get? Can you have a look in catalina.out  
>>>>>> and
>>>>>> paste the appropriate lines here?
>>>>>>
>>>>>> cheers.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 20/05/2009, at 12:01 AM, menjuanpablo wrote:
>>>>>>
>>>>>>>
>>>>>>> Hi,
>>>>>>> in the externallogicimpl i created this function
>>>>>>>              public String getCurrentSiteId(){
>>>>>>>           return toolManager.getCurrentPlacement().getContext();
>>>>>>>      }
>>>>>>> and in my jsp page i created a externallogicimpl objetc to  
>>>>>>> show the
>>>>>>> siteid
>>>>>>>
>>>>>>> <%! String aaa;
>>>>>>>      ExternalLogicImpl eli=new ExternalLogicImpl();%>
>>>>>>> <% aaa = eli.getCurrentSiteId(); %>
>>>>>>> <%=aaa %>
>>>>>>> but, when I build and run tool in sakai this generated a error.
>>>>>>> I'm doing well?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Steve Swinsburg-2 wrote:
>>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> What was the problem? Was it a null pointer? If so, how have  
>>>>>>>> you
>>>>>>>> set
>>>>>>>> toolManager? Show us some code.
>>>>>>>>
>>>>>>>> cheers,
>>>>>>>> Steve
>>>>>>>>
>>>>>>>> On 19/05/2009, at 10:46 PM, menjuanpablo wrote:
>>>>>>>>
>>>>>>>>>
>>>>>>>>> hi,
>>>>>>>>> I tried with this function
>>>>>>>>>
>>>>>>>>> public String getCurrentSiteId(){
>>>>>>>>>   return toolManager.getCurrentPlacement().getContext();
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>> to return the actual siteId, but this generated a problem
>>>>>>>>> are there other form to return the siteid ?
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> -- 
>>>>>>>>> View this message in context:
>>>>>>>>> http://www.nabble.com/take-the-value-of-site_id-
>>> tp23525450p23624982.html
>>>>>>>>> Sent from the Sakai - Development mailing list archive at
>>>>>>>>> Nabble.com.
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> sakai-dev mailing list
>>>>>>>>> sakai-dev at collab.sakaiproject.org
>>>>>>>>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>>>>>>>>
>>>>>>>>> TO UNSUBSCRIBE: send email to
>>>>>>>>> sakai-dev-unsubscribe at collab.sakaiproject.org
>>>>>>>>> with a subject of "unsubscribe"
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> sakai-dev mailing list
>>>>>>>> sakai-dev at collab.sakaiproject.org
>>>>>>>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>>>>>>>
>>>>>>>> TO UNSUBSCRIBE: send email to
>>>>>>>> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
>>>>>>>> "unsubscribe"
>>>>>>>>
>>>>>>>
>>>>>>> -- 
>>>>>>> View this message in context:
>>>>>>>
>> http://www.nabble.com/take-the-value-of-site_id-tp23525450p23625987.html
>>>>>>> Sent from the Sakai - Development mailing list archive at
>>>>>>> Nabble.com.
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> sakai-dev mailing list
>>>>>>> sakai-dev at collab.sakaiproject.org
>>>>>>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>>>>>>
>>>>>>> TO UNSUBSCRIBE: send email to
>>>>>>> sakai-dev-unsubscribe at collab.sakaiproject.org
>>>>>>> with a subject of "unsubscribe"
>>>>>>
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> sakai-dev mailing list
>>>>>> sakai-dev at collab.sakaiproject.org
>>>>>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>>>>>
>>>>>> TO UNSUBSCRIBE: send email to
>>>>>> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
>>>>>> "unsubscribe"
>>>>>>
>>>>>
>>>>> -- 
>>>>> View this message in context:
>>>>>
>> http://www.nabble.com/take-the-value-of-site_id-tp23525450p23626208.html
>>>>> Sent from the Sakai - Development mailing list archive at  
>>>>> Nabble.com.
>>>>>
>>>>> _______________________________________________
>>>>> sakai-dev mailing list
>>>>> sakai-dev at collab.sakaiproject.org
>>>>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>>>>
>>>>> TO UNSUBSCRIBE: send email to
>>>>> sakai-dev-unsubscribe at collab.sakaiproject.org
>>>>> with a subject of "unsubscribe"
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> sakai-dev mailing list
>>>> sakai-dev at collab.sakaiproject.org
>>>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>>>
>>>> TO UNSUBSCRIBE: send email to
>>>> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
>>>> "unsubscribe"
>>>>
>>>
>>> -- 
>>> View this message in context: http://www.nabble.com/take-the-value-
>>> of-site_id-tp23525450p23635234.html
>>> Sent from the Sakai - Development mailing list archive at  
>>> Nabble.com.
>>>
>>> _______________________________________________
>>> sakai-dev mailing list
>>> sakai-dev at collab.sakaiproject.org
>>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>>
>>> TO UNSUBSCRIBE: send email to sakai-dev-
>>> unsubscribe at collab.sakaiproject.org with a subject of "unsubscribe"
>>
>> _______________________________________________
>> sakai-dev mailing list
>> sakai-dev at collab.sakaiproject.org
>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>
>> TO UNSUBSCRIBE: send email to
>> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
>> "unsubscribe"
>>
>
> -- 
> View this message in context: http://www.nabble.com/take-the-value-of-site_id-tp23525450p23638698.html
> Sent from the Sakai - Development mailing list archive at Nabble.com.
>
> _______________________________________________
> sakai-dev mailing list
> sakai-dev at collab.sakaiproject.org
> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>
> TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org 
>  with a subject of "unsubscribe"

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20090520/4d1dbe1f/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2437 bytes
Desc: not available
Url : http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20090520/4d1dbe1f/attachment.bin 


More information about the sakai-dev mailing list