You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Garvin Riensche <g....@gmx.net> on 2003/11/20 21:31:30 UTC
database actions
Hi there,
I want to figure out how database actions work and therefore i created a
small example where i only want to store a number from a form field into my
database. Although cocoon is connected correctly to my mysql database i
can't make coocon write something into it. Instead it always displays
error.html (look at sitemap). My configuration: Windows XP, Cocoon 2.1m2,
MySQL Ver 11.18 Distrib 3.23.54
the sitemap:
<?xml version="1.0"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
<map:components>
<map:actions>
<map:action name="add-number"
src="org.apache.cocoon.acting.DatabaseAddAction"/>
<map:action name="form"
src="org.apache.cocoon.acting.FormValidatorAction"/>
</map:actions>
</map:components>
<map:pipelines>
<map:pipeline>
<map:match pattern="hello">
<map:read src="number.html" mimy-type="text/html"/>
</map:match>
<map:match pattern="send">
<map:act type="form" action="add-number">
<map:parameter name="validate-set" value="add"/>
<map:parameter name="descriptor" value="context://db/number.xml"/>
<map:parameter name="form-descriptor" value="context://db/number.xml"/>
<map:act type="add-number">
<map:read src="confirm.html" mimy-type="text/html"/>
<map:serialize/>
</map:act>
</map:act>
<map:read src="error.html" mimy-type="text/html"/>
<map:serialize/>
</map:match>
</map:pipeline>
</map:pipelines>
</map:sitemap>
If i understood it right, confirm.html should be processed if the action was
executed correctly and error.html if the action failed. But confirm.html is
never executed in this case.
I couldn't use an action-set here like in the examples (webapp) because i
always got an error which seems to be an known cocoon bug. The sample webabb
didn't work correctly either.
number.xml:
<root>
<parameter name="number" type="int"/>
<constraint-set name="add">
<validate name="number"/>
</constraint-set>
<number>
<connection>MySQL</connection>
<table name="test">
<keys>
<key param="number" dbcol="number" type="int" mode="manual"/>
</keys>
<values>
<value param="number" dbcol="number" type="int"/>
</values>
</table>
</number>
</root>
number.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test</title>
</head>
<body>
<form action="send" method="post">
<p>
Number:
<input name="number" type="int"/>
</p>
<input type="submit" value="OK"/>
</form>
</body>
</html>
It would be nice if someone could help.
regards,
Garvin
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: database actions
Posted by Christian Haul <ha...@informatik.tu-darmstadt.de>.
Garvin Riensche wrote:
> Hi there,
>
> I want to figure out how database actions work and therefore i created a
> small example where i only want to store a number from a form field into my
> database. Although cocoon is connected correctly to my mysql database i
> can't make coocon write something into it. Instead it always displays
> error.html (look at sitemap). My configuration: Windows XP, Cocoon 2.1m2,
> MySQL Ver 11.18 Distrib 3.23.54
>
> the sitemap:
>
> <?xml version="1.0"?>
> <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
> <map:components>
> <map:actions>
> <map:action name="add-number"
> src="org.apache.cocoon.acting.DatabaseAddAction"/>
> <map:action name="form"
> src="org.apache.cocoon.acting.FormValidatorAction"/>
> </map:actions>
> </map:components>
>
> <map:pipelines>
> <map:pipeline>
> <map:match pattern="hello">
> <map:read src="number.html" mimy-type="text/html"/>
> </map:match>
> <map:match pattern="send">
> <map:act type="form" action="add-number">
Sure this @action attribute is used?
> <map:parameter name="validate-set" value="add"/>
> <map:parameter name="descriptor" value="context://db/number.xml"/>
> <map:parameter name="form-descriptor" value="context://db/number.xml"/>
Off head, "form-descriptor" is unknown to the action.
> <map:act type="add-number">
It appears you haven't passed the descriptor file to the "add-number"
action. In addition, you should pass a table-set name to it, too. This
is not required but let's you keep multiple table definitions in one
file.
> <map:read src="confirm.html" mimy-type="text/html"/>
> <map:serialize/>
> </map:act>
> </map:act>
> <map:read src="error.html" mimy-type="text/html"/>
> <map:serialize/>
> </map:match>
> </map:pipeline>
> </map:pipelines>
> </map:sitemap>
>
> If i understood it right, confirm.html should be processed if the action was
> executed correctly and error.html if the action failed. But confirm.html is
Yes, this is right.
> never executed in this case.
>
> I couldn't use an action-set here like in the examples (webapp) because i
> always got an error which seems to be an known cocoon bug. The sample webabb
> didn't work correctly either.
Action-sets were long unsupported in 2.1 -- don't know if they were ever
fixed. Personally, I don't like them :-)
> It would be nice if someone could help.
I'd like to add two additional hints: You might be better off using flow
+ a OR-bridge like Hibernate or OJB. There are samples for this included
in the distribution and on the wiki. However, if you still would like to
use the above approach, I would highly recommend using the "modular"
database actions. They are a lot more versatile and have a more
consistent use.
When using the actions, you should not aim for a lot more than insert /
modify data straight away with just light syntactic checks. If you plan
complex validation or error handling, you should *really* look into flow
+ OJB or even the simple javascript DB layer contained in the petshop
sample.
Please check out the GetTogether'03 presentation on databases (cf wiki).
HTH
Chris.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org