JSF复合组件属性不起作用 [英] Jsf composite components attribute doesn't work

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

问题描述

我正在尝试创建复合组件.我在composite:interface部分中定义了4个属性.这是代码

I am trying to create composite components. I defined 4 attributes in composite:interface section. Here is code

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

<composite:interface >
    <composite:attribute name="id" />
    <composite:attribute name="maxlength" />
    <composite:attribute name="required"/>
    <composite:attribute name="value" />
</composite:interface>

<composite:implementation  xmlns:kc="http://java.sun.com/jsf/composite/components/kaysComposite">
        <p:inputTextArea id="#{cc.attrs.id}" value="#{cc.attrs.value}" maxlength="#{cc.attrs.maxlength}" required="#{cc.attrs.required}" counterTemplate="{0} /  #{cc.attrs.maxlength}" counter="#{cc.attrs.id}_counter"/>

        <h:outputText id="#{cc.attrs.id}_counter"/>
</composite:implementation>
</html>

这是我使用组件的页面

     <kc:kaysInputTextArea id="gpAdres" value="#{someBean.variable}"   maxlength="250" required="true"/>
<p:message for="gpAdres" />

奇怪的部分为required属性不起作用,但其他属性可以正常工作.我找不到为什么它会这样.

The weird part is required attribute doesn't work, but others work fine. I couldn't find why it is behaving like this.

推荐答案

(不是正确的答案,但是评论太久.只想分享一些想法可能会有所帮助...请根据需要进行编辑或替换)

(Not a true answer, but too long for a comment. Just wanted to share some ideas which might help... please edit or replace if appropriate)

您没有描述遇到的行为,因此我猜测组件内部的值不会随着您传入的值而改变.

You did not describe the behavior you encountered, so I'm guessing the value inside the component does not change with the value you pass in.

在相同的设置下,我遇到了类似的问题,但是当我直接传递"true"或"false"时(如您的示例所做的那样),它起作用了.仅当我交出EL表达式时,无论表达式计算结果如何,都不再设置组件内部的值.就我而言,我在属性上设置了显式类型,例如type="java.lang.Boolean"删除此定义就可以了.

I had a similar problem with the same setup, but when I passed in "true" or "false" directly (as your example does), it worked. Only if I handed over an EL expression, the value inside the component is not set anymore, regardless of what the expression evaluates to. In my case I had an explicit type set on the attribute, e.g. type="java.lang.Boolean" Removing this definition did the trick.

我的猜测是,当强制属性期望布尔值时,它无法处理EL并将其解析为默认值Boolean(除非设置了default="false",否则它似乎是正确的).

My guess is that when forcing the attribute to expect boolean it can't handle an EL and resolves it to the default value of Boolean (which seems to be true, unless default="false" is set).

通过不设置类型,似乎组件可以保留EL并将其传递给下一个目标,例如任何h:tag的呈现属性.

By not setting a type it seems the component can retain the EL and passes it on to the next target, e.g. the rendered attribute of whatever h:tag.

这似乎不是您的确切问题,但也许可以帮助您查找问题?

Does not seem to be your exact problem, but maybe it helps in tracing the issue?

这篇关于JSF复合组件属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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