Best practice for relatively simple plugin

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

Best practice for relatively simple plugin

g.nikacevic@levi9.com
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Best practice for relatively simple plugin

Frank van Lankvelt
You're probably best off defining your own nodetype.  Then, in the template, you should replace the collection of (list, field) plugins by your own plugin.  It will receive a javax.jcr.Node model as its (Wicket) model which you can use to retrieve and modify properties.  You can take a look at hippostd:html for an example of a template for a compound type.

There are a few examples on the forge that you could check out to look at the plugin code.  The tagging and related docs plugins each have a mixin type; since you don't seem to be dealing with meta-data, I would not recommend doing the same.  Instead, use a compound type (primary jcr node type that doesn't descend from hippo:document).  It then even appears automatically in the list of field types in the template builder!

Hope this helps, Frank

On Mon, Nov 16, 2009 at 4:22 PM, gnikacevic <[hidden email]> wrote:

Hello,

I am trying to create plugin that has more than just 1 input field.

I looked at examples on Forge, but plugins like Rating and YouTube plugin
only have 1 input field. Rating plugin, for example, has only 1 field to
enter number, and in VIEW mode that number is represented by stars. This is
fine, I went through those examples and I understand how to create those
kind of plugins.

What I need is just a bit more complicated than those plugins on forge. Let
me explain a simplified version of a plugin that I would like to create. For
example, this plugin should have 3 fields. First 2 fields should be text
fields and user would enter numbers in those fields. Third field should be a
list of radio buttons with operations: "+", "-", "*" and "/". In EDIT mode,
user would enter 2 numbers and choose operation from radio buttons list. In
VIEW mode (when document is saved and user is done editing) plugin should
display result of an operation. So, in EDIT mode this plugin should have 3
fields while in VIEW mode it should only display 1 value.

This, of course, is not a plugin that I am trying to create. This is
simplified version that in my opinion illustrates my problem and some
directions on how to create this plugin would really help me in solving my
real problem.

Could someone give me some pointers and best practice on how this should be
done?
--
View this message in context: http://n2.nabble.com/Best-practice-for-relatively-simple-plugin-tp4012582p4012582.html
Sent from the Plugin Development and Customization mailing list archive at Nabble.com.
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html


_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html
Reply | Threaded
Open this post in threaded view
|

Re: Best practice for relatively simple plugin

g.nikacevic@levi9.com
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Best practice for relatively simple plugin

Frank van Lankvelt
Hi Goran,

it seems like you're almost there, just need to be a bit more ruthless!

You have a template (showing just the plugin.class properties):
- ListViewPlugin
- PropertyFieldPlugin
- PropertyFieldPlugin
- ...
- MyFancyPlugin

Now, you can replace that by
- MyFancyPlugin

The thing to look out for are the properties wicket.id and wicket.model.  The wicket.id property of the fancy plugin configuration should receive the value that is specified in the ListViewPlugin config.  The wicket.model property should be the same as that in the PropertyFieldPlugin configs.  Then, your plugin is the only one in the template and you can display however you want.

I think that the solution you're describing would be most easily implemented by having separate templates.  I've created issue http://issues.onehippo.com/browse/HREPTWO-3386 for it.  Scheduling is unknown, but you might be able to create a patch yourself(?)

cheers, Frank

On Tue, Nov 17, 2009 at 10:08 AM, gnikacevic <[hidden email]> wrote:

Hello Frank,

Thanks for help. Yes, that is exactly what I did. I created compound type
through CMS, exported it and changed XML. I created my own plugin class (it
extends "RenderPlugin") and changed "plugin.class" property of fields from
"PropertyFieldPlugin" to my plugin class. As you said, that plugin class
receives node as model object and I managed to read data from node and save
data to that node.

In short, in EDIT mode everything is ok, I created everything I needed. I
pretty much did everything you described and it works fine :) What I am
having trouble with is VIEW mode. Currently, in VIEW mode every text field
(or radio button group) is rendered as label (or how ever I choose to render
it in HTML file for that field). What I need now is a way to render 1 value
instead of all input fields.

Here is what I tried:
I see in my XML for namespace that every field has "plugin.class" attribute,
and at beggining value of that attribute was "PropertyFieldPlugin". Only 1
node has "ListViewPlugin" as a value for "plugin.class". I assumed that node
with that plugin is responsible for rendering list of all fields. So, I
created new class that extends "ListViewPlugin" class and set this new class
as a "plugin.class" of that node. I was hoping that this class will also
receive node as a model object, and that I will be able to see if it is VIEW
or EDIT mode. In EDIT mode I wanted to leave everything as it is, but in
VIEW mode I was hoping to stop rendering of all fields, and instead of that
to display just 1 label that uses information from all fields. But when I
called method "getModelObject()" in my class that extends "ListViewPlugin",
I got null. And I also don't know how to tell if I am in VIEW or EDIT mode
since way I was using in field plugin "config.getString("mode")" also
returns null.

So, my problem is how to display just 1 value in VIEW mode? Is extending
"ListViewPlugin" a way to do it or would you suggest some other way?

One solution that comes to my mind is to say to all fields not to render
anything in VIEW mode. Then, I would create one additional field that would
be the only one that renders in VIEW mode. That one field would not render
at all in EDIT mode, but will be the only one that renders in VIEW mode so I
would use it to render that 1 value I need. What do you think about this
solution? It seems a bit dirty to me, I was wondering if there is some
cleaner solution?

Thanks for your time,
Goran
--
View this message in context: http://n2.nabble.com/Best-practice-for-relatively-simple-plugin-tp4012582p4017383.html
Sent from the Plugin Development and Customization mailing list archive at Nabble.com.
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html


_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/community.html