[Building Sakai] JSF - error in gettin g current user

Steve Swinsburg s.swinsburg at lancaster.ac.uk
Wed Jun 3 10:24:26 PDT 2009


Your JSF backing bean shouldn't deal with the Sakai API's. You should  
create some sort of SakaiProxy or ExternalLogic API and IMPL setup  
with the Sakai APi's injected via Spring, and then your backing bean  
should call the methods of that proxy.

In the App Builder, the JSF backing bean has this:

public String getCurrentUserDisplayName() {
	return  
externalLogic.getUserDisplayName(externalLogic.getCurrentUserId());
}

private ExternalLogic externalLogic;
public void setExternalLogic(ExternalLogic externalLogic) {
	this.externalLogic = externalLogic;
}


Note how it delegates to externalLogic. This is a wrapper you create  
to make the calls.

Your externalLogic bean is then setup with the Sakai API's injected  
like so, in components.xml in your pack:
<!-- create an external logic bean which abstracts out the Sakai bits  
-->
     <bean id="org.sakaiproject.examplejsf.logic.ExternalLogic"
         class="org.sakaiproject. examplejsf.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>


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 3 Jun 2009, at 17:44, m_yaghmaie at modares.ac.ir wrote:

> Hi,
> I am using JSF for my new tool. I am using the AppBuilder and it has  
> generated the following JSP. When I try to load the jsp from portal,  
> the following exception is thrown:
>
> Stacktrace:
>     at  
> org 
> .apache 
> .myfaces 
> .application 
> .jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211)
> caused by: org.apache.jasper.JasperException: Exception in JSP: / 
> adaptivelearningsystem/welcome.jsp:14
>
> 11:
> 12:             <sakai:view_content>
> 13:
> 14:                     <sakai:view_title value="Hello,  
> #{AdaptiveSiteBean.getCurrentUserDisplayName}"/>
> 15:                     <h:outputText value="It is now  
> #{AdaptiveSiteBean.currentDate}"/>
> 16:                     <!--<sakai:button_bar_item id="getSites"  
> value="getSites"
> 17:                                      
> action="#{AdaptiveSiteBean.getSites}"/>-->
>
>
> Stacktrace:
>     at  
> org 
> .apache 
> .jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
> caused by: javax.faces.FacesException: Could not get property value  
> of component _idJsp2
>     at  
> javax 
> .faces 
> .component._ComponentAttributesMap.get(_ComponentAttributesMap.java: 
> 235)
> caused by: java.lang.reflect.InvocationTargetException
>     at  
> sun 
> .reflect 
> .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> caused by: javax.faces.el.EvaluationException: Cannot get value for  
> expression 'Hello, #{AdaptiveSiteBean.getCurrentUserDisplayName}'
>     at javax.faces.component.UIOutput.getValue(UIOutput.java:80)
> caused by: javax.faces.FacesException: Cannot coerce  
> org.sakaiproject.user.impl.DbUserService$$EnhancerByCGLIB$$c29618e6  
> to org.sakaiproject.user.api.UserDirectoryService
>     at  
> org 
> .apache 
> .myfaces 
> .config 
> .ManagedBeanBuilder.initializeProperties(ManagedBeanBuilder.java:188)
> caused by: javax.servlet.jsp.el.ELException: Attempt to coerce a  
> value of type "
> org.sakaiproject.user.impl.DbUserService$$EnhancerByCGLIB$$c29618e6"  
> to type "org.sakaiproject.user.api.UserDirectoryService"
>
> The part of My faces bean about user directory is as follows:
>
>    private UserDirectoryService userDirectoryService;
>    public void setUserDirectoryService(UserDirectoryService  
> userDirectoryService) {
>       this.userDirectoryService = userDirectoryService;
>    }
>
>
>     public AdaptiveSiteBean() {
>     }
>
>     public Date getCurrentDate() {
>         log.debug("Returning current date...");
>         return new Date();
>     }
>
>     public String getCurrentUserDisplayName() {
>         return userDirectoryService.getCurrentUser().getDisplayName();
>     }
>
> Would you please help me with this issue?
> --Tnx, Mak
> _______________________________________________
> 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/20090603/4e57bcd3/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/20090603/4e57bcd3/attachment.bin 


More information about the sakai-dev mailing list