关于JSF里面的Composite Components

今天学习了 JSF的Composite Components。

这个Composite Components是一个特别的模板可以做component,其他的都还好理解,就是这个composite:editableValueHolder, Oracle的官方文档写的英文非常的绕口,读了半天也没有完全明白。

composite:editableValueHolder

Declares that the composite component whose contract is declared by the composite:interface in which this element is nested exposes an implementation of EditableValueHolder suitable for use as the target of attached objects in the using page.

看了例子,大概理解如下。 首先这个editableValueHolder是用来指向 composite implementation,

        <composite:interface>
            <composite:attribute name="namePrompt" default="Username: "/>
            <composite:attribute name="passwordPrompt" default="Password: "/>

            <composite:attribute name="loginButtonText" default="Log In"/>
            <composite:attribute name="loginAction"
                                 method-signature="java.lang.String action()"/>
            <composite:attribute name="myLoginBean"/>
            <composite:editableValueHolder name="vals" targets="form:name"/>
            <composite:editableValueHolder name="passwordVal" targets="form:password"/>

        </composite:interface>

注意,target是指向implementation的,这里有个form:,我查了很多文档没有提到,我把form:拿掉,就会报错,后来发现是下面implementation是在form里面,如果我把implementation从form里面拿出来,就没有错了。注意这个target接受多个,用逗号分开,但是因为我们需要在using page验证这两个field,合在一起无法分开验证。

下面是implementation

 <composite:implementation>
            <h:form id="form">
                <h:outputStylesheet library="css" name="default.css" 
                                    target="head"/>
                <h:panelGrid columns="2" role="presentation">
                    <h:outputLabel for="name" 
                                   value="#{cc.attrs.namePrompt}"/>
                    <h:inputText id="name" 
                                 value="#{cc.attrs.myLoginBean.name}" 
                                 required="true"/>

                    <h:outputLabel for="password" 
                                   value="#{cc.attrs.passwordPrompt}"/>
                    <h:inputSecret id="password" 
                                   value="#{cc.attrs.myLoginBean.password}" 
                                   required="true"/>

                </h:panelGrid>
                <p>
                    <h:commandButton id="loginButton" 
                                     value="#{cc.attrs.loginButtonText}"
                                     action="#{cc.attrs.loginAction}"/>
                </p>
            </h:form>
            <div class="messagecolor">
                <h:messages showSummary="true" 
                            showDetail="false"
                            errorStyle="color: #d20005" 
                            infoStyle="color: blue"/>
            </div>
        </composite:implementation>

然后呢, 这个可以在using page里被用到

                <ez:LoginPanel myLoginBean="#{myLoginBean}" 
                               loginAction="#{myLoginBean.login}">
                    <f:validateLength maximum="10" minimum="4" for="vals" />
                    <f:validateRegex pattern="((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,10})"
                                     for="passwordVal"/>
                </ez:LoginPanel>

以上就是我今天学习心得。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值