JSF2.0复合组件actionListener [英] JSF2.0 Composite Component actionListener

查看:125
本文介绍了JSF2.0复合组件actionListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助来使我的复合组件正常运行.我仍在学习JSF中的技巧,因此,请原谅本文中可能出现的任何无知之处.

I am in need of some assistance in getting my Composite Component to behave. I am still learning the ropes in JSF, so please excuse any ignorance that might be displayed in this post.

因此,我正在使用JSF 2.0,并决定构建一个复合组件以使此特定代码段可重复使用.该组件可以完美显示所有内容,但是在尝试添加actionListener时完全不起作用.

So, I am working with JSF 2.0 and decided to build a composite component to make this particular code snippet reusable. The component displays everything perfectly, but will not behave at all when trying to add the actionListener.

这是我组件的代码

<ui:composition
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html"  
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:composite="http://java.sun.com/jsf/composite">

    <composite:interface displayName="columnUpdate">
        <composite:attribute name="id" 
            required="true" 
            displayName="id"
            shortDescription="Id to apply to this control and its child components">
        </composite:attribute>
        <composite:attribute 
            name="value" 
            displayName="value"
            required="true" 
            shortDescription="Field that will hold the new updated value.">
        </composite:attribute>

        <composite:attribute 
            name="columnName" 
            displayName="columnName"
            required="true" 
            shortDescription="Value that will be applied as the column header">
        </composite:attribute>
        <composite:attribute 
            name="text"
            displayName="text"
            shortDescription="Text to be displayed above the field">
        </composite:attribute>

        <composite:actionSource name="actionEvent" targets="saveEvent"></composite:actionSource>
    </composite:interface>

    <composite:implementation>
        <h:outputLabel value="#{cc.attrs.columnName}" onclick="showWindow('#{cc.attrs.id}')"></h:outputLabel>

        <div id="#{cc.attrs.id}" class="ccColumnUpdate">
        <div id="windowClose" onclick="closeWindow('#{cc.attrs.id}');" style="top: -10px;" title="Close this window">CLOSE</div>
            <div>
                <h:outputLabel id="lblTitle" value="#{cc.attrs.text}"></h:outputLabel>
            </div>
            <div>
                <h:inputText id="txtValue" value="#{cc.attrs.value}"></h:inputText>
            </div>
            <div style="text-align:right;">
                <h:commandButton id="saveEvent" value="Save"></h:commandButton>
            </div>
        </div>
    </composite:implementation>
</ui:composition>

这是我页面中使用该组件的代码:

Here is the code in my page that uses the component:

<al:columnUpdate id="cuExpenseAmount" value="#{expense.columnValue}" columnName="Expense Amount" text="Set Expense Amount to:">
  <f:actionListener for="actionEvent" binding="#{expense.updateColumnValue}">
    <f:ajax execute="@form"></f:ajax>
  </f:actionListener>
</al:columnUpdate>

这是我在Backing Bean上的代码:

and here is my code on the Backing Bean:

public void updateColumnValue(ActionEvent event) throws ParseException{
    //Got HERE

}

我没有收到任何错误,也没有遇到我在备用Bean上设置的任何断点.任何帮助或指向正确方向的指针都将不胜感激.

I am not receiving any errors or hit any breakpoints I set on the backing bean. Any help, or pointers in the right direction would be appreciated.

此致

迈克

推荐答案

经过反复搜索和更多搜索,我找到了答案.

I found the answer after playing around a little bit and more searching.

更改为复合组件: 发件人:

Changes to the composite component: FROM:

<composite:actionSource name="actionEvent" targets="saveEvent"></composite:actionSource> 

<h:commandButton id="saveEvent" value="Save"></h:commandButton>  

收件人:

<composite:attribute name="registerButtonActionListener" method-signature="void actionListener(javax.faces.event.ActionEvent)" />

<h:commandButton id="saveEvent" value="Save" actionListener="#{cc.attrs.registerButtonActionListener}">
                    <f:ajax execute="@this" event="click"></f:ajax>
                </h:commandButton>

使用复合组件切换到页面:

Changes to the page using the composite component:

<al:columnUpdate id="cuExpenseAmount" value="#{expense.columnValue}" registerButtonActionListener="#{expense.updateColumnValue}" columnName="Expense Amount">
                            </al:columnUpdate>

最大的变化是在Composite属性中定义了方法签名.

The big change was defining the method signature in the composite attribute.

此致

迈克

这篇关于JSF2.0复合组件actionListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆