thanks for returning my post at the cocoon users group. I would like to qualify this email by saying first that I have, until 2 weeks ago, never touched unix or open source, hence my somewhat infantile questions ;-)
Now, in terms of what I am looking to achieve it goes as so:
1. Create an Action which would take in a password and username, and return user details if the user existed. If not return user to the login page:
1.a Action (Snippet)
public Map act ( Redirector redirector, SourceResolver resolver,
Map objectModel, String source, Parameters param) throws Exception
{
Request request = ObjectModelHelper.getRequest(objectModel);
Map map = new HashMap();
DataSourceComponent dataSource = getDataSource("postgresql");
Connection conn = null;
try
{
conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
String userName = param.getParameter("user");
String userPassword = param.getParameter("pass");
String cmd = "Select user_id, first_name, last_name, address1, address2, address3, postcode, country, email, " +
"home_telephone, mobile_telephone, date_joined from usertbl where username = '" + userName + "'" +
"and userpassword = '" + userPassword + "'";
ResultSet rs = stmt.executeQuery(cmd);
if (rs.next())
{
map.put("user_id", rs.getString(1));
map.put("first_name", rs.getString(2));
map.put("last_name", rs.getString(3));
map.put("address1", rs.getString(4));
map.put("address2", rs.getString(5));
map.put("address3", rs.getString(6));
map.put("postcode", rs.getString(7));
map.put("country", rs.getString(8));
map.put("email", rs.getString(9));
map.put("home_telephone", rs.getString(10));
map.put("mobile_telephone", rs.getString(11));
map.put("date_joined", rs.getString(12));
}else
{
map = null;
}
rs.close();
stmt.close();
}catch (Exception e){
getLogger().error("Query failed: ", e);
}finally
{
try
{
if (conn != null) conn.close();
}catch (SQLException sqe)
{
getLogger().warn("Error closing the datasource", sqe);
}
}
return(map);
}
public void dispose()
{
this.manager.release(dbselector);
}
1.b Pipeline
<map:match pattern="user-details">
<map:act type="get-detail2">
<map:parameter name="user" value="{request-param:user}" />
<map:parameter name="pass" value="{request-param:pass}" />
<map:generate type="file" src="content/main.xml" />
<map:transform src="style/main.xsl">
<map:parameter name="user_id" value="{user_id}" />
<map:parameter name="first_name" value="{first_name}" />
<map:parameter name="last_name" value="{last_name}" />
<map:parameter name="address1" value="{address1}" />
<map:parameter name="address2" value="{address2}" />
<map:parameter name="address3" value="{address3}" />
<map:parameter name="postcode" value="{postcode}" />
<map:parameter name="country" value="{country}" />
<map:parameter name="email" value="{email}" />
<map:parameter name="home_telephone" value="{home_telephone}" />
<map:parameter name="mobile_telephone" value="{mobile_telephone}" />
<map:parameter name="date_joined" value="{data_joined}" />
</map:transform>
<map:serialize type="html" />
</map:act>
<map:redirect-to uri="login.html" />
</map:match>
2. At this point I wanted to do a little more, as you do!, and at the Action stage populate a JavaBean (if possible) with user details which would then enable me to re-call these values from the bean as and when I chose. So the scenario you have described to me for how your operation works is exactly what I am trying to do, but I am stuck!
3a. Ok, so I create a JavaBean (my first ever I might add), where do I place the compiled bean (which directory)? Would I be right in saying that when I have place it into the correct directory that I need to re-start tomcat?
3b. From the action, how do I instantiate the bean and populate the bean fields with user data (syntax) ?
3c. How do I then save this in a request attribute?
'What we do is use an action to
invoke an EJB that returns a Data Transfer Object (a Java bean). The actionAgain the syntax at this juncture of the action using my snippet as action snippet as an example.
saves the DTO into a request attribute.'
3d. Betwixt???
1. I have downloaded commons-betwixt-1.0-alpha-1.jar, which directory does this live in?Would I be right in saying that when I have place it into the correct directory that I need to re-start tomcat?
2. After the action successfully
completes our pipeline aggregates a couple of piplelines; the first invokes
a generator that uses Betwixt's SAXWriter to convert our DTO into SAX
events. The second pipeline invokes a generator that gets the stylesheet
parameter data and converts it into XML. The aggregated XML is then
transformed via XSLT into XHTML.
Again syntax, what does it look like? What shape would my pipeline look like after it has been amended?
thanks for you time and help on this issue
Andrew
On 19 Jan 2004, at 08:01, Ralph Goers wrote:
This looks ok except you probably want
<map:parameter name="user" value="{request-param:user}/>
<map:parameter name="pass" value="{request-param:pass}/>
This will pass the userid from the login form to the transform.
However, I'm not sure what you are trying to do here? Weren't you trying to
perform authentication?
As to your question regarding how to aggregate from an action, An action
returns a Map. A pipeline requires SAX events. You can't inject stuff from
the Map into the pipeline from the Action. What we do is use an action to
invoke an EJB that returns a Data Transfer Object (a Java bean). The action
saves the DTO into a request attribute. After the action successfully
completes our pipeline aggregates a couple of piplelines; the first invokes
a generator that uses Betwixt's SAXWriter to convert our DTO into SAX
events. The second pipeline invokes a generator that gets the stylesheet
parameter data and converts it into XML. The aggregated XML is then
transformed via XSLT into XHTML.
Ralph
-----Original Message-----
From: beyaNet Consultancy
To: [EMAIL PROTECTED]
Sent: 1/18/2004 3:02 PM
Subject: Re: Actions, pipelines, javabeans...
Ok Ralph and Morley,
so i have a sitemap that does the following (aggregation):
<map:match pattern="support/home">
<map:aggregate element="home">
<map:part
src="cocoon:/support/beya-menu" />
<map:part
src="cocoon:/support/contract-summary" />
<map:part
src="context://beyarecords/content/adv-xyz-01.xml" />
<map:part
src="context://beyarecords/content/site_title.xml" />
</map:aggregate>
<map:transform type="xslt"
src="style/home-page.xsl">
<map:parameter
name="user" value="{../1}" />
<map:parameter
name="pass" value="{../1}" />
</map:transform>
<map:serialize type="html" />
</map:match>
Now in terms of session persistence and passing parameters around
(shopping cart), how would I aggregate the parameters from my action
into my xsl document and avoid the pitfalls of the approach i was taking
before?
Andrew
On 18 Jan 2004, at 22:47, beyaNet Consultancy wrote:
Ralph and Morley,
as I have stated in my earlier message the approach i am currently
taking leaves much to be desired, hence the request about JavaBeans. As
I am completely new to this cocoon arena, could you please show me an
example of what you mean in terms of 'use aggregation and turn your
parameters into XML that are aggregated into the document processed by
your transform'?
Andrew
On 18 Jan 2004, at 19:35, Ralph Goers wrote:
When I first started using Cocoon I too was coding things like
you are. It
soon became apparent that this was not a good approach because
every time a
new data element had to be added too many things needed to be
modified. In
addition, I believe passing parameters from the sitemap impacts
Cocoon's
caching of your transforms.
A better approach is to use aggregation and turn your parameters
into XML
that are aggregated into the document processed by your
transform. Thus, you
won't have to see the parameters in the sitemap at all.
Furthermore, you can
use Betwixt or Castor to automatically convert any Java Bean
into XML. We
are doing exactly that to retrieve data from our business tier.
Ralph
-----Original Message-----
From: beyaNet Consultancy
To: [EMAIL PROTECTED]
Sent: 1/18/2004 6:44 AM
Subject: Actions, pipelines, javabeans...
Hi,
I have created an action which returns parameters to a pipeline
based on
a users login details. I want these details to persist for the
du ration
of a user session and wanted to know how to store the values
passed into
the pipeline into a JavaBean instead. At the moment I have the
parameters coming into my action as so:
1. pipeline
<map:match pattern="user-details">
<map:act type="get-detail2">
<map:parameter name="user"
value="{request-param:user}" />
<map:parameter
name="pass"
value="{request-param:pass}" />
<map:generate
type="file"
src="content/main.xml" />
<map:transform
src="style/main.xsl">
<map:transform
src="style/main.xsl">
<map:parameter
name="first_name" value="{first_name}" />
<map:parameter
name="last_name" value="{last_name}" />
<map:parameter
name="address1" value="{address1}" />
<map:parameter
name="address2" value="{address2}" />
<map:parameter
name="address3" value="{address3}" />
<map:parameter
name="postcode" value="{postcode}" />
<map:parameter
name="country" value="{country}" />
<map:parameter
name="email" value="{email}" />
<map:parameter
name="home_telephone" value="{home_telephone}" />
<map:parameter
name="mobile_telephone" value="{mobile_telephone}" />
<map:parameter
name="date_joined" value="{data_joined}" />
</map:transform>
<map:serialize
type="html" />
</map:act>
and are passed into the pipeline from the Action as so:
2. Action
map.put("user_id",
rs.getString(1));
map.put("first_name",
rs.getString(2));
map.put("last_name",
rs.getString(3));
map.put("address1",
rs.getString(4));
map.put("address2",
rs.getString(5));
map.put("address3",
rs.getString(6));
map.put("postcode",
rs.getString(7));
map.put("country",
rs.getString(8));
map.put("email",
rs.getString(9));
map.put("home_telephone",
rs.getString(10));
map.put("mobile_telephone",
rs.getString(11));
map.put("date_joined",
rs.getString(12));
and then into my xsl page as so
3. xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="user_id"/>
<xsl:param name="first_name"/>
<xsl:param name="last_name"/>
<xsl:param name="address1"/>
<xsl:param name="address2"/>
<xsl:param name="address3"/>
<xsl:param name="postcode"/>
<xsl:param name="country"/>
<xsl:param name="email"/>
<xsl:param name="home_telephone"/>
<xsl:param name="mobile_telephone"/>
<xsl:param name="date_joined"/>
Could I call and update the javabean from the within the
transform:
<map:transform src="style/main.xsl">
instatiate javabean
javabean.user_id = <map:transform src="style/main.xsl">
</map:transform>
Or would it be better to do it from within the Action and then
just call
the call javabean from within the xsl page itself? ultimately I
want to
be able to call the javebean parameters into my xsl or xsp
pages. What
is the best way to go about doing this? Is there any example
code out
there I can have a look at?
Andrew
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
