使用Java控制器类和自定义控件属性

使用Java控制器类和自定义控件属性,java,xpages,xpages-ssjs,Java,Xpages,Xpages Ssjs,将来我几乎只想使用JAVA,而不是SSJS。因此,我为每个XPage使用一个对应的Java类作为“XPage控制器”,类似于Jesse Gallagher项目。 这种方法的另一个例子是,他们正在使用代码隐藏文件 现在我有一些关于自定义控件属性的体系结构问题 请查看以下代码段: Szenario 1:“使用自定义控件属性” XPage: <xp:view xmlns:xp="http://www.ibm.com/xsp/core"> ... <xc:act

将来我几乎只想使用
JAVA
,而不是
SSJS
。因此,我为每个XPage使用一个对应的Java类作为“XPage控制器”,类似于Jesse Gallagher项目。 这种方法的另一个例子是,他们正在使用代码隐藏文件

现在我有一些关于自定义控件属性的体系结构问题

请查看以下代码段:

Szenario 1:“使用自定义控件属性” XPage:

<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons showSaveButton="true"></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{compositeData.showSaveButton}" />
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{documentController.showSaveButton}" 
    actionListener="#{documentController.actionSavePerformed}"/>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons showSaveButton="#{documentController.showSaveButton}"></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{compositeData.showSaveButton}" 
    actionListener="#{documentController.actionSavePerformed}"/>

...
...
自定义控件:

<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons showSaveButton="true"></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{compositeData.showSaveButton}" />
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{documentController.showSaveButton}" 
    actionListener="#{documentController.actionSavePerformed}"/>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons showSaveButton="#{documentController.showSaveButton}"></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{compositeData.showSaveButton}" 
    actionListener="#{documentController.actionSavePerformed}"/>


Szenario 2:“不要使用自定义控件属性,只使用控制器类” 这意味着控制器类(在视图范围内)可以处理所有属性

XPage:

<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons showSaveButton="true"></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{compositeData.showSaveButton}" />
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{documentController.showSaveButton}" 
    actionListener="#{documentController.actionSavePerformed}"/>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons showSaveButton="#{documentController.showSaveButton}"></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{compositeData.showSaveButton}" 
    actionListener="#{documentController.actionSavePerformed}"/>

...
...
自定义控件:

<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons showSaveButton="true"></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{compositeData.showSaveButton}" />
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{documentController.showSaveButton}" 
    actionListener="#{documentController.actionSavePerformed}"/>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons showSaveButton="#{documentController.showSaveButton}"></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{compositeData.showSaveButton}" 
    actionListener="#{documentController.actionSavePerformed}"/>


Szenario 3:“同时使用自定义控件属性和控制器类” XPage:

<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons showSaveButton="true"></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{compositeData.showSaveButton}" />
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{documentController.showSaveButton}" 
    actionListener="#{documentController.actionSavePerformed}"/>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons showSaveButton="#{documentController.showSaveButton}"></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{compositeData.showSaveButton}" 
    actionListener="#{documentController.actionSavePerformed}"/>

...
...
自定义控件:

<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons showSaveButton="true"></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{compositeData.showSaveButton}" />
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{documentController.showSaveButton}" 
    actionListener="#{documentController.actionSavePerformed}"/>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">    
    ...
    <xc:actionButtons showSaveButton="#{documentController.showSaveButton}"></xc:actionButtons>
    ...
</xp:view>
<xp:button id="btnSave" value="Save" themeId="Button.Command.FormButton" 
    rendered="#{compositeData.showSaveButton}" 
    actionListener="#{documentController.actionSavePerformed}"/>


更新 在上面的三个场景中,我试图用一种通用的方式描述我的观点,即如何将自定义控件与控制器类结合使用

现在我的问题是,当我尝试使用
控制器类时,我应该如何处理
自定义控件属性

我认为所有相关代码(例如,处理按钮的可见性等)都应该放在控制器类中。因此,没有必要拥有自定义控件属性(例如,场景1:compositeData.showSaveButton与场景2:documentController.showSaveButton),但另一方面,使用自定义控件属性可以使控件更加独立。在场景3中,我尝试给出一个简短的示例,将自定义控件属性与控制器类的优点相结合(例如showSaveButton=“#{documentController.showSaveButton}”),但这种方法似乎设计过度

我不确定哪种技术方法最好


欢迎提出改进意见(赞成和反对意见)或更好的体系结构方法

NotesIn9上有很多关于使用控制器类的节目。那里可能有一些有趣的例子。但要回答你的问题,这真的取决于你。自定义控件可以很容易地进入控制器,但它并不像您所说的那样“独立”,然而,因为您使用的是控制器,所以我认为这不是一个问题,因为您可以假设控制器将具有支持自定义控件所需的代码。根据自定义控件,控制器可以扩展内置自定义控件支持的其他控制器。那么,这是一个既定的工作。 但是如果您想通过compositeData传入值,您可以。只需创建一个自定义属性并将类型设置为“java.lang.Object”。然后你可以传递任何你真正想要的东西。
取决于控制,我个人倾向于让它取决于控制器。

你的问题是什么?@SvenHasselbach:对不起,你说得对,昨天是漫长的一天,现在我更新了我的问题。