[daisy] Custom part editor - first attempt
Paul Focke
paul at outerthought.org
Wed Jul 23 11:31:24 CEST 2008
Valerie
Lets see you are having trouble putting the part data into a custom part
editor. You can probably best do this in the load method of the part
editor and not spend too much time looking into trying to use the cocoon
binding.
>From what I gather you are trying to fill up multiple cocoon form fields
from the content with data found in one part. So I'm also guessing
you're parsing the data and then splitting it up into little bits that
are supposed to be put in the different fields.
I haven't tried this approach before but I'll give it a shot anyway. So
in your definition you'll have a number of fields (don't forget to put
them in the template too). When you are in the load method of your part
editor class you will parse and split up the data. Since you have the
form object in that method you simply get the fields you want and fill
them up. Like this
List<PartBit> bits = valeriesPartParser.parseToBits(part.getData());
if (bits.size() > 0) {
Field field = (Field)form.getChild("field1");
field.setValue(bits.get(0).getData();
}
When saving you'll have to aggregate the data from the different fields.
You won't be able to use the PartEditorHelper.save() function here since
this deals with only one field but you can base yourself on it. Not
really like I'm showing here since I cut out all the necessary
checks ;-)
byte[] data = aggregateFieldData(form); // this function runs over the
fields and puts all the data in a byte array
long partTypeId = ((PartType)form.getAttribute("partType")).getId();
document.setPart(partTypeId, "yourMimeTypeHere" data);
Oh and I still have one more remark. You started out trying to do this
with a field editor. I don't know what the best choice is for putting
your data in field or a part since I have no idea what you are trying
do. Actually don't really have to know what the plan is just take this
into account. If you are dealing with document meta data or strongly
typed data put that in fields. This method will prove to be very
valuable when you want to search documents. If the data is pure content
that has an arbitrary structure then go ahead an put it in a part.
Search for the content in a part will prove to be a bit harder then
searching in fields.
Paul
On Wed, 2008-07-23 at 10:18 +0200, Valerie Nyre wrote:
> Hello
>
> Can you spend just a few words, and only indicate in short - whether it
> is possible - and which methods might make sense to use?
>
>
> The problem at hand:
>
> I plan to use the forms binding to "stream" the contents of a Daisy part
> into a Cocoon form. The part should be of text/xml.
> In my first attempt, I see that the Daisy load operations only load
> single fields - that is: the complete contents of the part is totally
> filled into each field.
> The reason might be that Daisy only provides a method that loads the
> complete part data into one form field.
>
> I hope it is possible to use the Cocoon forms binding framework, but I
> do not know yet how to activate this from within a custom part editor...
>
>
> Can you indicate the necessary actions to take - or at least what I
> should be aware of?
>
> Or do I have to use flow control and then pass the part data to the
> Cocoon pipeline to get the forms binding to work?
>
> But then again: How can I communicate or use some binding manager to
> 1. fill the form fields (do I have to parse the part content myself or
> can I let the Cocoon forms binding do it? )
> 2. get validation results from the binding framework
> 3. tell Daisy to save each form into a part if no validation problems
> remain.
>
>
>
> thank you
>
> Valerie Nyre
>
>
> _______________________________________________
> daisy community mailing list
> Professional Daisy support: http://outerthought.org/en/services/daisy/support.html
> mail to: daisy at lists.cocoondev.org
> list information: http://lists.cocoondev.org/mailman/listinfo/daisy
More information about the daisy
mailing list