How to design several forms with almost similar look? - forms

I have about 6 forms to design with UIBinder that look almost the same, the difference is two or three fields. I was thinking about building one form with all the possible fields and hide or show fields depending on the case.
What do you think about this method?

It can work well. You can define a BaseForm class with UiBinder that implements HasWidgets, and then define SpecificForm1.ui.xml with something like
<custom:BaseForm>
<g:TextBox ui:field="componentSpecificToThisForm" />
<g:Button>A button!</g:button>
</custom:BaseForm>
and SpecificForm2.ui.xml with something like
<custom:BaseForm>
<g:Label>Something totally different</g:Label>
<g:Button>A button!</g:button>
</custom:BaseForm>
it works great!

I've tried something similar, and building one form where I hid/show the appropriate fields was the most simple solution. Another idea would be create a factory, which then builds your form according to your needs.
So, you basically create the components your form is composed of, and the factory wires them together via constructor dependency injection. Worked very well for me, and also has the added benefit that it is very easy to extend your form.
(I'll add an example later).

Related

Template Toolkit: Extracting a part of a template

I was assigned the task to rewrite our home-made templates with Perl Template Toolkit.
Our templates have the possibility to extract a fragment of the template (and then make HTML from it) instead of using the entire template.
How to do it with Template Toolkit?
The best solution I came with is the following:
Let we have a template x.html with fragment A.
The fragment should be extracted into new file. (I am to name it like x/A.html for consistency.) In the original template x.html it should be replaced with [% INCLUDE 'x/A.html' %]. So I could be able to use either the entire template x.html or its fragment x/A.html. Probably we may have several levels of inclusion like x/A/B.html.
Are there other ways to do it? (I don't like to idea to split it in subdirectories as described above, but haven't come up with a better solution.)
Are you asking whether there's a better way to extract the fragment from the parent template?
(Answer is: no, that's probably the best way.)
Or are you asking is there a better way to organize the extracted fragements?
(Answer is: no real best answer, everywhere will have their own house style - you aren't going to go too far wrong by picking any convention.)
Most common conventions for naming I've seen are subdirectories x/A.html and prefixes x_A.html. Whether you use the name of the parent template for x or you choose to group by functionality as simbabque suggested is another matter of taste: grouping by functionality scales better on larger and more complicated layouts where you have a great deal of reuse of components, but grouping by use case is conceptually simpler in smaller use cases with little or no component reuse.

LiveBindings or OOP?

I have a question regarding OOP. I'm not new to Delphi, but I learned it by myself, mostly from the internet and didn't learned it the "correct" way. I just started to take a look at OOP some weeks ago. So this is my problem:
I have an own Class called "Session". This class is connected with Edits through Visual LiveBindings. I want to fill my class with data from a TClientDataset (there is a reason why I don't bind the dataset with the edits directly). Now I have 2 ideas:
1. I build another class which implements the Dataset and handles the opening of files and Navigation.
2. I Drag and drop the ClientDataset one my Form and connect it to my class with Livebindings, like this: DataSet <---> Class <---> Edit
I hope you understand my description. So: Which idea is better? I have the feeling that LiveBindings "destroy" the Concept of OOP. On the other hand I don't need to write Code and typecast, because the live bindings do that for me.
So which way would you choose and why? Or has somebody another idea?
I hope you understand what I mean and can help me :)
With LiveBindings it is perfectly possible to bind to objects instead of datasets.
See: http://www.malcolmgroves.com/blog/?p=1084
In summary: take look at TAdapterBindSource component. It is designed for creating LiveBindings between existing controls and custom objects. In it's onCreateAdapter event you can return a TObjectBindSourceAdapter as aBindSourceAdapter in case you want to bind one specific object, or return a TListBindSourceAdapter for binding list of objects.
LiveBindings and OOP does not bite each other!

Does ZF have a filter for nl2br?

Does Zend Framework have a nl2br filter? I can't see it - am I just missing it?
I imagine I could do the same thing with PregReplace...
When we have an existing PHP function nl2br it really begs the question: "do we really need to wrap a ZF filter class around a function?"
There are a few filters that actually do that.
In terms of forms for injecting a filter (and maybe other cases) I would say yes or when we need some more flexibility with additional options; basically extending the PHP function. I don't really see a need for this particular function and you should be fine to simply use PHP out of the box.
No, Zend Framework dos't have nl2br filter. If you want to use it then you should put it in your code where you want.
You can use any other methods also similar to that for achieving this.

CMFWorkflow and Marker Interfaces

I'm currently prototyping a small project in Plone and trying to KISS as much as possible while the requirements are still in flux. To that end, I've resisted creating any custom content types for now and have been using marker interfaces to distinguish between "types" of content.
Now that I'm looking at workflow, I've realised that they're bound to types, and there doesn't seem to be a mechanism for assigning them to markers. I think I could wrap portal_workflow with my own version that looks for markers and returns the appropriate workflow if found, however, this doesn't feel like a tenable approach.
Is there a way of assigning workflow to markers that I've missed, or should I just bite the bullet and create some lightweight custom content types instead?
There's not really a built-in feature to use markers, but at http://www.martinaspeli.net/articles/dcworkflows-hidden-gems, Martin Aspeli hints that it is possible:
Note that in Plone, the workflow chain of an object is looked up by
multi-adapting the object and the workflow to the IWorkflowChain
interface. The adapter factory should return a tuple of string
workflow names (IWorkflowChain is a specialisation of IReadSequence,
i.e. a tuple). The default obviously looks at the mappings in the
portal_workflow tool, but it is possible to override the mapping, e.g.
in resopnse to some marker interface.

(How) can I provide a custom class to set up pages in Wicket?

I would like to change the way Wicket instantiates my Page instance for a subset of URLs. Normally, I would map a class to a URL with mount(), in which case Wicket chooses one of the available constructors on that class and instantiates it.
A part of my application are simple CRUD operations that have a lot in common between different entity types. I have factored out the common aspects into some factory and helper classes and now I'm left with a class hierarchy for my pages which looks like this:
TemplatePage
|
AbstractEntityPage
| |
AbstractVenuePage AbstractEventPage
| | | |
ViewVenuePage EditVenuePage ViewEventPage EditEventPage
I would like to cut the last two levels, because the hierarchy starts to sprawl as more entity types are added and there's very little code left in those classes which could be factored out easily to more generic objects.
It's rather easy to transform AbstractEntityPage into a class EntityPage that gets specific components plugged in place as needed. I would normally use a Builder to do this, but I'm not sure how I would tell Wicket to use it? I couldn't find a hook for that in the API docs.
You can replace the default IPageFactory with org.apache.wicket.settings.ISessionSettings.setPageFactory(IPageFactory) and use different strategy of instantiating the page if it is special one.
You could use an EntityPage and implement the differences within your panels, but then you'd need a lot of similar panels (or a few generic panels if they don't really differ). Or you could take a look at one of the rapid prototyping libraries for wicket like wicketopia. I wouldn't consider any of them (the ones I found and tested) to be production-ready but they can be salvaged for ideas g.