Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Forms 如何设计几个外观几乎相似的表单?_Forms_Gwt_Uibinder - Fatal编程技术网

Forms 如何设计几个外观几乎相似的表单?

Forms 如何设计几个外观几乎相似的表单?,forms,gwt,uibinder,Forms,Gwt,Uibinder,我用UIBinder设计了大约6个表单,它们看起来几乎一样,不同的是两个或三个字段。我在考虑构建一个包含所有可能字段的表单,并根据具体情况隐藏或显示字段 你觉得这个方法怎么样?它可以很好地工作。您可以使用UiBinder定义一个实现HasWidgets的BaseForm类,然后使用以下内容定义SpecificForm1.ui.xml <custom:BaseForm> <g:TextBox ui:field="componentSpecificToThisForm" /

我用UIBinder设计了大约6个表单,它们看起来几乎一样,不同的是两个或三个字段。我在考虑构建一个包含所有可能字段的表单,并根据具体情况隐藏或显示字段


你觉得这个方法怎么样?

它可以很好地工作。您可以使用UiBinder定义一个实现
HasWidgets
BaseForm
类,然后使用以下内容定义SpecificForm1.ui.xml

<custom:BaseForm>
    <g:TextBox ui:field="componentSpecificToThisForm" />
    <g:Button>A button!</g:button>
</custom:BaseForm>
<custom:BaseForm>
    <g:Label>Something totally different</g:Label>
    <g:Button>A button!</g:button>
</custom:BaseForm>

按钮!
以及SpecificForm2.ui.xml

<custom:BaseForm>
    <g:TextBox ui:field="componentSpecificToThisForm" />
    <g:Button>A button!</g:button>
</custom:BaseForm>
<custom:BaseForm>
    <g:Label>Something totally different</g:Label>
    <g:Button>A button!</g:button>
</custom:BaseForm>

完全不同的东西
按钮!

它工作得很好

它可以很好地工作。您可以使用UiBinder定义一个实现
HasWidgets
BaseForm
类,然后使用以下内容定义SpecificForm1.ui.xml

<custom:BaseForm>
    <g:TextBox ui:field="componentSpecificToThisForm" />
    <g:Button>A button!</g:button>
</custom:BaseForm>
<custom:BaseForm>
    <g:Label>Something totally different</g:Label>
    <g:Button>A button!</g:button>
</custom:BaseForm>

按钮!
以及SpecificForm2.ui.xml

<custom:BaseForm>
    <g:TextBox ui:field="componentSpecificToThisForm" />
    <g:Button>A button!</g:button>
</custom:BaseForm>
<custom:BaseForm>
    <g:Label>Something totally different</g:Label>
    <g:Button>A button!</g:button>
</custom:BaseForm>

完全不同的东西
按钮!

它工作得很好

我也尝试过类似的方法,构建一个表单,在其中隐藏/显示适当的字段是最简单的解决方案。另一个想法是创建一个工厂,然后根据需要构建表单

因此,您基本上创建表单所包含的组件,工厂通过构造函数依赖项注入将它们连接在一起。这对我来说非常好,而且还有一个额外的好处,那就是很容易扩展你的表单


(稍后我将添加一个示例)。

我尝试过类似的方法,构建一个表单,在其中隐藏/显示适当的字段是最简单的解决方案。另一个想法是创建一个工厂,然后根据需要构建表单

因此,您基本上创建表单所包含的组件,工厂通过构造函数依赖项注入将它们连接在一起。这对我来说非常好,而且还有一个额外的好处,那就是很容易扩展你的表单


(稍后我将添加一个示例)。

因此,如果我了解您的解决方案,在BaseForm类中,我可以将SpecificForm1.ui.xml中的文本框和SpecificForm2.ui.xml中的标签组合在一起?当然-添加您喜欢的任何小部件。当您从
haswidget
实现
add(IsWidget)
时,您可以确定将接受多少小部件,以及如何处理它们。您还可以实现
HasOneWidget
,只接受一个HTMLPanel或其他东西。因此,如果我了解您的解决方案,在BaseForm类中,我可以将SpecificForm1.ui.xml中的文本框和SpecificForm2.ui.xml中的标签组合在一起?当然-添加您喜欢的任何小部件。当您从
haswidget
实现
add(IsWidget)
时,您可以确定将接受多少小部件,以及如何处理它们。您还可以实现
HasOneWidget
,只接受一个HTMLPanel或其他东西。使用
HasWidgets
而不是构造函数可以增加使用UiBinder文件配置特定版本的好处,如果您的设计师不懂Java,这一点尤其好!使用
HasWidgets
而不是构造函数增加了使用UiBinder文件配置特定版本的好处,如果您的设计师不懂Java,这尤其好!