开发者

How to design several forms with almost similar look?

开发者 https://www.devze.com 2023-04-03 13:55 出处:网络
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 pos开发者_StackOverflow社区sible fiel

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 pos开发者_StackOverflow社区sible 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号