小编MyF*_*ist的帖子

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

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

<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>
Run Code Online (Sandbox Code Playgroud)

default属性设置为xxxfor <composite:attribute>不是我正在寻找的.

attributes composite-component jsf-2

11
推荐指数
1
解决办法
5515
查看次数

如何摆脱复合组件中自动生成的j_idt ID

我正在使用下面的复合组件:

<composite:interface>
    <composite:attribute name="inputId" />
</composite:interface>
<composite:implementation>
    <h:panelGrid id="myTableId">
        <h:inputText id="#{cc.attrs.inputId}" value="..." />
        ...
    </h:panelGrid>
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)

我在我的表单中使用它如下:

<h:form id="myForm">
    <myCompositeComp:test inputId="myInputTextBoxId" />
<h:form>
Run Code Online (Sandbox Code Playgroud)

我已经验证了页面的视图源,这就是它的生成方式:

<table id="myForm:j_idt90:myTableId">
    ...
    <input type="text" id="myForm:j_idt90:myInputTextBoxId" />
</table>
Run Code Online (Sandbox Code Playgroud)

我怎么能摆脱j_idt90这里?它id是我的复合组件吗?我从BalusC的一篇文章中读到,如果我声明id为静态,这个问题将得到解决.但我无法确定在我的代码中声明它的位置.我还可以假设<h:panelGrid>是一种UINamingContainer

composite-component jsf-2

3
推荐指数
1
解决办法
4798
查看次数

无法从复合组件执行ajax刷新

这是我的复合组件:

<composite:interface>
    <composite:attribute name="attr1" />
    <composite:clientBehavior name="xyz" event="valueChange" targets="chkbox" />
</composite:interface>
<composite:implementation>
    <h:panelGrid>
    <h:panelGroup>
        <h:selectBooleanCheckbox id="chkbox"
                value="#{cc.attrs.attr1}">
            </h:selectBooleanCheckbox>
    </h:panelGroup>
</h:panelGrid>
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)

我的页面:

<h:form id="myForm">
  <cc:myComp attr1="#{myBean.someAttr}">
    <f:ajax render="myform:grid1" event="xyz" listener="{myBean.listenerMethod}"/>
  </cc:myComp>

  <h:panelGrid id="grid1">
      <h:panelGroup>
         <h:inputTextarea id="rationale" rows="4" cols="70"
                value="#{myBean.rationale}" />
      </h:panelGroup>
  </h:panelGrid>
</h:form>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

<f:ajax> 包含一个未知的id'myForm:grid1' - 无法在组件chkbox的上下文中找到它

如果我render="myform:grid1"从我的代码中删除,那么ajax调用工作正常.基本上从我的复合组件我不能引用另一个OUTSIDE组件.这是怎么造成的,我该如何解决?

jsf-2

2
推荐指数
1
解决办法
1556
查看次数

如何从servlet获取JSF2.0 sessionMap引用

下面的代码片段就是我正在使用的内容.

ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
  Map<String, Object> sessionMap = externalContext.getSessionMap();
  sessionMap.put("User",user);
Run Code Online (Sandbox Code Playgroud)

现在我怎么能从普通的"servlet"获得"sessionMap" - "key"值?这样的代码是否(User)session.getAttribute("User");可以通过我的servlet工作?

servlets jsf-2

1
推荐指数
1
解决办法
2749
查看次数

标签 统计

jsf-2 ×4

composite-component ×2

attributes ×1

servlets ×1