Using Scope Generator and accessing results in a view

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Scope Generator and accessing results in a view

chary-2
Erik,

I am trying to do the following steps: 1. take login information from
user, 2. validate login, 3. show results.

The input screen (step 1 above) is working correctly. It submits the
input credentials to a pipeline processor for validation.

Validation is done using delegation. The results of this are stored in a
Java object (called Results).

I would like to show the contents of the Results object to the user.

I have questions on steps 2 and 3..
     I am trying to use Scope generator with Castor mapping to convert
the Results Java object to XML.
     I want to show the resulting XML in browser.

Here is the Scope generator I have defined:

Code Excerpts(only):

1. login.xpl:
<!-- generate xml from the Results java object -->
   <p:processor name="oxf:scope-generator">
   <p:input name="config">            <config>
               <key>resultkey</key>
               <scope>session</scope>
           </config>
       </p:input>
   <p:input name="mapping">      
           <mapping>mapresults.xml</mapping>
   </p:input>
        <p:output name="data" id="session"/>    </p:processor>

   The Java Object (Results) used in mapping above contains the
following two fields:
          boolean valid
          String reason


Questions:
 1. What is the best way to organize the pipleine for the above scenario?
 2.  How does the output of scope generation look? I expect it to be:
              <Results>
                 <valid/>
                 <reason/>
              </Results>
  3.  Do I need to use a Scope Serializer right after the scope generator?
  4.. How do I access the results in a view?  What model do I need to
define in the View.xhtml to show the results object?

Finally, is there an example I can look at?

Thanks,
Chary
                 




--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Using Scope Generator and accessing results in a view

Erik Bruchez
Administrator
Chary,

 > I am trying to do the following steps: 1. take login information from
 > user, 2. validate login, 3. show results.
 >
 > The input screen (step 1 above) is working correctly. It submits the
 > input credentials to a pipeline processor for validation.
 >
 > Validation is done using delegation. The results of this are stored in a
 > Java object (called Results).
 >
 > I would like to show the contents of the Results object to the user.
 >
 > I have questions on steps 2 and 3..
 >     I am trying to use Scope generator with Castor mapping to convert
 > the Results Java object to XML.
 >     I want to show the resulting XML in browser.
 >
 > Here is the Scope generator I have defined:
 >
 > Code Excerpts(only):
 >
 > 1. login.xpl:
 > <!-- generate xml from the Results java object -->
 >   <p:processor name="oxf:scope-generator">
 >   <p:input name="config">            <config>
 >               <key>resultkey</key>
 >               <scope>session</scope>
 >           </config>
 >       </p:input>
 >   <p:input name="mapping">
<mapping>mapresults.xml</mapping>
 >   </p:input>
 >        <p:output name="data" id="session"/>    </p:processor>

One comment about the above: when you store your Java object into the
Servlet session, you use something like:

   setAttribute("myname", object)

Right? Of course "myname" is a placeholder for the actual name you are
using. "myname" is the Scope generator key you must use to retrieve
that object. In other words, you should make sure that you have
something like:

   <key>myname</key>

in the oxf:scope-generator configuration.

 >   The Java Object (Results) used in mapping above contains the following
 > two fields:
 >          boolean valid
 >          String reason
 >
 >
 > Questions:

 > 1. What is the best way to organize the pipleine for the above scenario?

It depends what kind of pipeline your pipeline is. It can be:

o A PFC action pipeline
o A PFC page model pipeline

In your case, I would implement this as a PFC action pipeline,
i.e. with something like:

<page ...login page...>
   <action action="my-credentials-validation-pipeline.xpl">
     <result when="/Results/valid = 'true'">
       ...
     </result>
     <result>
       ...
     </result>
   </action>
</page>

Create the action pipeline with a single step: the oxf:scope-generator
which produces the XML serialization of your Java object. Then return
that XML document to the "data" output of the action pipeline. Hence,
the result of your action pipeline is an XML document containing the
XML serialization of your Java object.

 > 2.  How does the output of scope generation look? I expect it to be:
 >              <Results>
 >                 <valid/>
 >                 <reason/>
 >              </Results>

I believe you should first give it a try and check what the output
looks like. For more information, check this:

   http://www.castor.org/xml-mapping.html

(Of course it would be nice to include the basics in the OPS doc.)

 >  3.  Do I need to use a Scope Serializer right after the scope generator?

The scope serializer allows you to store XML documents into the
request, session or application scope. Unless you need to do that, you
do not need the Scope serializer.

 >  4.. How do I access the results in a view?  What model do I need to
 > define in the View.xhtml to show the results object?

Based on point #1 above, we now have an action pipeline which returns
an XML document. It is important to understand what happens after an
action is executed. If there are <result> elements, the conditions on
those are evaluated, and you can decide what to do with the action
result. For example, you can submit it to another page.

Doing so would be my preferred way: create a second page called
"view-result" for example, and do something like this in the login
page:

   <result when="/Results/valid = 'true'" page="view-result"
transform="oxf:xslt">
     <Result xsl:version="2.0" xmlns="">
       <xsl:copy-of select="doc('input:instance')/*/*"/>
     </Result>
   </result>

In the resulting page, you can use a simple XSLT page view to format
the XML submission data, which is available on the XSLT page view's
doc('input:instance') input.

The above assumes OPS 3.0 beta.

 > Finally, is there an example I can look at?

Now I should mention overall that usually you don't do manual
authentication like this: you use J2EE's (in fact, Java servlets')
built-in authentication mechanisms, if necessary by writing your own
authentication realm.

So if you are asking about such an authentication example in OPS, the
answer is no. But there is an example showing the use of Servlet
authentication.

As far as examples showing how to produce data from one page and
displaying it in another, the "BizDoc NG" example is a good one: the
summary page retrieves a particular document from the database, and
then passes it to the detail page.

BTW, a good read about the PFC and XML submissions is the PFC
reference documentation:

   http://www.orbeon.com/ops/doc/reference-page-flow

-Erik




--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws