cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tino Breddin <s9600...@inf.tu-dresden.de>
Subject Re: How to access the session context with flowscript?
Date Mon, 16 Jan 2006 23:31:57 GMT
Hi,

i am using the authentication framework ofrom cocoon with a custom 
Authenticator. The xml fragment <authentication><ID>.... is still put 
into the session, when a user logs in.

Well, now i tried this one:

function callTest() {
    importClass(org.apache.cocoon.components.CocoonComponentManager);
    importClass(org.apache.cocoon.webapps.session.SessionManager);
     var componentManager = 
CocoonComponentManager.getSitemapComponentManager();
    var sessionManager = componentManager.lookup(SessionManager.ROLE);
    var user = sessionManager.getContextFragment( 
"authentication","/authentication/ID").getFirstChild().getNodeValue();
    cocoon.sendPage("dynamictest",{"user":user});     <---- line 17
    }


The error:

Description: org.apache.avalon.framework.CascadingRuntimeException: 
"file:/Users/Tino/Documents/workspace/Prototyp/protected/scripts/nav-access.js", 
line 17: uncaught JavaScript exception: at callTest 
(file:/Users/Tino/Documents/workspace/Prototyp/protected/scripts/nav-access.js, 
Line 17): java.lang.NullPointerException

Thanks for your help,
Tino

philguillard schrieb:
> Hi,
>
> It seems your cocoon.session.getAttribute("ID") returns null. Did you 
> set previously the ID in the session ?
> Just in case (take it as suggestion) :
> If you are working on auth-framework or portal (cause i see here the 
> "ID" term), all is put inside the session in XML format, then you 
> would need something like that to get it:
> var user = sessionManager.getContextFragment( 
> "authentication","/authentication/ID").getFirstChild().getNodeValue();
>
> Phil
>
> Tino Breddin wrote:
>
>> Hi,
>>
>> i tried a littlebit, but all i get is a "uncaught 
>> NullPointerException" error in line 14. My code is simple, i wanted 
>> to test, if the forwarding and getting the session information work, 
>> but they don't. Any help?
>>
>> Thanks,
>> Tino
>>
>> My js code:
>>
>> function callTest() {
>>    var user = null;
>>    user = cocoon.session.getAttribute("ID");
>>    cocoon.sendPage("dynamictest",{"user":user});   <--- line 14
>>    }
>>
>> My sitemap code:
>>
>>    <map:pipeline>
>>            <map:match pattern="main">
>>                 <map:call function="callTest">
>>                 </map:call>
>>             </map:match>
>>             <map:match pattern="dynamictest">
>>                 <map:generate type="jx" source="resources/test.jx"/>
>>                 <map:serialize type="xhtml"/>
>>             </map:match>
>>        </map:pipeline>
>>
>> My jx code:
>>
>> <jx:template xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
>>   <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
>>            <head>
>>                <link rel="stylesheet" media="screen" 
>> href="screen.css" />
>>            </head>
>>            <body>
>>                <p>The current user is ${user}</p>
>>            </body>
>>        </html>
>> </jx:template>
>> Armaz Mellati schrieb:
>>
>>> Your idea is almost right as far as I can see.
>>>
>>> Just some small modifications needed.
>>>
>>>  function callGetCode() {
>>>       var user = cocoon.session.getAttribute("ID");
>>>     var csc = new CodeSnippetCreator();
>>>       var code = csc.getCode(user);
>>>       
>>> cocoon.sedPage("name-of-a-pileline-with-a-jx-template",{"code":code});
>>>      }
>>> All flow functions MUST return a response. They can't just returne a 
>>> code.
>>>
>>>
>>> Regards,
>>> Armaz
>>>
>>>
>>>  
>>>
>>>> -----Original Message-----
>>>> From: Tino Breddin [mailto:s9600916@inf.tu-dresden.de] Sent: 16. 
>>>> januar 2006 10:20
>>>> To: users@cocoon.apache.org
>>>> Subject: How to access the session context with flowscript?
>>>>
>>>> Hi,
>>>>
>>>> this is my first approach to flowscript, so i am confronted with 3 
>>>> questions right now.
>>>> I want to read the id of the current user from the session context, 
>>>> pass it to a java method and get the returned object and forward it 
>>>> to the pipeline.
>>>>
>>>>
>>>> flowtest.js:
>>>>
>>>> importClass(my.package.CodeSnippetCreator);
>>>>
>>>> function callGetCode() {
>>>>     var user = cocoon.session.getAttribute("ID");
>>>>     CodeSnippetCreator csc = new CodeSnippetCreator();
>>>>     var code = csc.getCode(user);
>>>>     return code;
>>>>     }
>>>> --------------------------
>>>>
>>>> The requested code shall be xml, so that i can forward it to the 
>>>> pipeline, were the code will be aggregated with other parts. The 
>>>> java method getCode(String user) gets some information about the 
>>>> user and then creates a specific xml snippet.
>>>> Is this way to access the session and call java right? Currently i 
>>>> can not test it, it is just a idea i had to write down :-)
>>>>
>>>> Thanks,
>>>> Tino
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>>> For additional commands, e-mail: users-help@cocoon.apache.org
>>>>
>>>>
>>>>     
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>> For additional commands, e-mail: users-help@cocoon.apache.org
>>>   
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message