如何检查复合组件中是否存在可选属性

时间:2012-12-04 12:17:45

标签: jsf-2 attributes composite-component

我需要验证我的复合组件中是否传递了可选属性。我怎样才能做到这一点?

<composite:interface>
    <composite:attribute name="attr1" />
    <composite:attribute name="attr2" required="false" /> <!-- means OPTIONAL -->
</composite:interface>
<composite:implementation>
    <!-- How I can verify here whether attr2 is present or not whenever this component is used? -->
</composite:implementation>

default设置xxx属性为<composite:attribute>并不是我想要的。

3 个答案:

答案 0 :(得分:10)

您只需检查#{not empty cc.attrs.attr2}是否评估为true

E.g。在任意组件的rendered属性中:

<composite:implementation>
    <h:panelGroup rendered="#{not empty cc.attrs.attr2}">
        Attribute attr2 is not empty!
    </h:panelGroup>
</composite:implementation>

答案 1 :(得分:3)

您可以使用以下方法检查表达式是否存在:

  

cc.getValueExpression(&#39; someAttribute&#39)

CpG.T.Test  <- function(betam, pheno){
  R = 50000
  t = numeric(R)
  p = numeric(R)

  for (i in 1:R){
    beta.v <- betam[i, ]
    pheno.v <- pheno

    test <- t.test (beta.v ~ pheno.v)
    t[i] = test$statistic
    p[i] = test$p.value
  }
}

答案 2 :(得分:2)

您可以通过以下方式有条件地向组件添加属性:

<c:if><f:attribute>

样品:

<composite:interface>
    <composite:attribute name="label" />
    <composite:attribute name="required" default="false" />
    <composite:attribute name="readonly" default="false" />
    <composite:attribute name="value" />
    <composite:attribute name="title" />
    <composite:attribute name="placeholder" />
    <composite:attribute name="maxlength" type="java.lang.Integer"/>
</composite:interface>
<composite:implementation>
    <p:inputText
      id="field"
      value="#{cc.attrs.value}">
        <c:if test="#{empty cc.attrs.maxLength}">
           <f:attribute name="maxlength" value="#{cc.attrs.maxlength}" />
        </c:if>
    </p:inputText>
</composite:implementation>

我找到了答案:

How not to set an attribute of a component inside a composite component if it is empty?