我需要验证我的复合组件中是否已传递可选属性.我怎样才能做到这一点?
<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>不是我正在寻找的.
我正在使用下面的复合组件:
<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: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组件.这是怎么造成的,我该如何解决?
下面的代码片段就是我正在使用的内容.
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工作?