You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Yuri Kolesnikov <ir...@pskmill.com> on 2005/11/11 09:11:48 UTC
Forms problem with sumbit widgets (lost or mixed form instances ?)
Hello,
I have a problem which makes my current development unusefull.
Problem is with Forms block.
In the begining I get it on cocoon 2.1.5, after that I upgrade cocoon to
2.1.7 and fix my code.
Nothnig happend with problem.
There is a detailed description:
I made a combination from two forms
The first - list of person
The second - form to edit person's properties.
Form descriptions (labels, hints are skiped)
LIST OF ITEMS
<?xml version="1.0" encoding="UTF-8"?>
<fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition">
<fd:widgets>
<fd:booleanfield id="show-erased">
<fd:on-value-changed>
<javascript>
var form = event.source.getForm();
refreshDirectoryForm(form);
</javascript>
</fd:on-value-changed>
</fd:booleanfield>
<fd:repeater id="table-item" initial-size="0">
<fd:widgets>
<fd:booleanfield id="select"/>
<fd:output id="erased">
<fd:datatype base="string"/>
</fd:output>
<fd:output id="employee">
<fd:datatype base="string"/>
</fd:output>
<fd:submit id="editButton" action-command="edit">
<fd:on-action>
<javascript>
event.source.getForm().setAttribute("edit-item-id",event.source.getParent().getAttribute("item-id"));
</javascript>
</fd:on-action>
</fd:submit>
</fd:widgets>
</fd:repeater>
<fd:submit id="addButton" action-command="add"/>
<fd:action id="markButton" action-command="mark">
<fd:on-action>
<javascript>
markDirectoryItems(event.source.getForm());
</javascript>
</fd:on-action>
</fd:action>
</fd:widgets>
</fd:form>
ITEM (There is no many fields, but it has not effect on problem)
<fd:form xmlns:fd="http://apache.org/cocoon/forms/1.0#definition">
<fd:widgets>
<fd:output id="photo-output">
<fd:datatype base="string"/>
</fd:output>
<fd:lookup id="employee">
<fd:data-source>
<fd:param name="src" value="lookup"/>
<fd:param name="_path" value="/md/directory/employees"/>
</fd:data-source>
</fd:lookup>
<fd:upload id="photo" mime-types="image/jpeg"/>
<fd:submit id="submitOK" action-command="ok">
<fd:on-action>
<javascript>
loadPhoto(event.source.getForm());
</javascript>
</fd:on-action>
</fd:submit>
<fd:submit id="submitCancel" action-command="cancel"
validation="false"/>
</fd:widgets>
</fd:form>
and finally
JAVA SCRIPT (with many skips)
cocoon.load("resource://org/apache/cocoon/forms/flow/javascript/Form.js");
var messages = "";
var removingId = new ArrayList();
function editDirectory(name){
if(name==null) name = cocoon.request.getParameter("name");
var form = new Form("forms/xml/"+name+"-list.xml");
form.setAttribute("directory",name);
refreshDirectoryForm(form);
while(true)
{
form.showForm("show-form-"+name+"-list");
var submit = form.submitId;
if(submit=="addButton"){
addDirectoryItem(form);
continue;
}
if(submit=="editButton"){
changeDirectoryItem(form,form.getAttribute("edit-item-id"));
continue;
}
break;
}
}
function refreshDirectoryForm(listForm)
{
// fill form with data
}
function markDirectoryItems(listForm)
{
// mark selected items as erased, or clear erased mark if already
presents
}
function addDirectoryItem(listForm)
{
changeDirectoryItem(listForm,null);
}
function changeDirectoryItem(listForm,id)
{
var name = listForm.getAttribute("directory");
var form = new Form("forms/xml/"+name+"-item.xml");
// fill form with data here
form.showForm("show-form-"+name+"-item");
var submit_res = form.submitId;
if(submit_res == "submitOK")
{
// get data from form and store
refreshDirectoryForm(listForm);
}
}
At last THE PROBLEM
Then I work from on client everything is fine.
But if I use this form from two clients (for example two different
browsers on my computer)
I get java.lang.IllegalStateException: SubmitWidget can only be set once
after some cycles of press edirButtons on list forms, get Item form,
close it and return to list.
I traced cocoon code and find terrible things.
When I press editButton (submit widget) the Form.process starts.
It finds form_submit_id in http request and calls setSubmitWidget.
After that it calls readFromRequest for every widgets
And a submit widget calls form.setSubmitWidget to.
Sometimes they are not equal - sumbit widget which was found in the
Form.process() and submit widget which read itself from request.
There is one more demonstration of this problem.
Sometimes the values of attribute "edit-item-id" are not equal.
I press editButton for one person, but gt item form for other. And the
other is person which was edited right before.
I check value then I set it in on-action javascript and then get it for
calling changeDirectoryItem().
It means that form instances in this points are different. Am I right?
In cocoon 2.1.5 I found a comment (in
org/apache/cocoon/forms/flow/javascript/Form.js)
// FIXME: Theoretically, we should clone the form widget
(this.form) to ensure it keeps its
// value with the continuation. We don't do it since there
should me not much pratical consequences
// except a sudden change of repeaters whose size changed from a
continuation to another.
May be it is exactly my case? It it is, than how to clone form widget?
Anybody have ideas how to solve this problem?
With best regards,
Yuri Kilesnikov
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Forms problem with sumbit widgets (lost or mixed form instances
?)
Posted by Sylvain Wallez <sy...@apache.org>.
Yuri Kolesnikov wrote:
> Hello,
>
> I have a problem which makes my current development unusefull.
> Problem is with Forms block.
<snip/>
> <fd:lookup id="employee">
> <fd:data-source>
> <fd:param name="src" value="lookup"/>
> <fd:param name="_path" value="/md/directory/employees"/>
> </fd:data-source>
> </fd:lookup>
What is <fd:lookup>? A special widget of yours?
> At last THE PROBLEM
>
> Then I work from on client everything is fine.
> But if I use this form from two clients (for example two different
> browsers on my computer)
> I get java.lang.IllegalStateException: SubmitWidget can only be set once
> after some cycles of press edirButtons on list forms, get Item form,
> close it and return to list.
What do you mean by "return to list"? Are you using the back button on
the browser?
> I traced cocoon code and find terrible things.
LOL :-)
> When I press editButton (submit widget) the Form.process starts.
> It finds form_submit_id in http request and calls setSubmitWidget.
>
> After that it calls readFromRequest for every widgets
> And a submit widget calls form.setSubmitWidget to.
> Sometimes they are not equal - sumbit widget which was found in the
> Form.process() and submit widget which read itself from request.
What is the submit widget that was read from the request?
Sylvain
--
Sylvain Wallez Anyware Technologies
http://people.apache.org/~sylvain http://www.anyware-tech.com
Apache Software Foundation Member Research & Technology Director
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org