我有一个自定义组件,它扩展了 HtmlInputText + 自定义渲染器来编写 Twitter Bootstrap html 标记。例如:
<bf:inputText id="a" label="L1" value="#{dummyMB.str}" formLayout="horizontal" labelSize="2" inputSize="6"/>
它呈现:
<div id="form:a-componente" class="form-group ">
<label for="form:a" class=" control-label col-md-2">L1</label>
<div class="col-md-3 ">
<input id="form:a" type="text" name="form:a" class="form-control form_a" dir="ltr">
</div>
</div>
在我需要通过 ajax 渲染属性更新这个特定组件之前,一切都很好。该组件丢失了 html 标记。
ajax之后:
<div id="form:a-componente" class="form-group ">
<label for="form:a" class=" control-label col-md-2">L1</label>
<div class="col-md-6 ">
<input id="form:a" class="form-group " dir="">
</div>
</div>
如果我尝试 ajax 更新整个表单。有用。如果我将它嵌套在 ah:panelGroup 中,它就可以工作。
仅当我尝试使用 render 属性中的 id 专门更新我的组件时,它才起作用。
这是我的自定义组件上 getStyleClass() 的覆盖:
@Override
public String getStyleClass() {
String styleClass = super.getStyleClass();
if(StringUtils.isEmpty(styleClass)) {
styleClass = "";
}
if(!styleClass.contains(BFConstantes.DEFAULT_STYLE_CLASS)) {
styleClass += BFConstantes.DEFAULT_STYLE_CLASS;
}
if(!styleClass.contains(FaceletsFunctions.styleClassId(this))) {
// O JSF usa o caracter ":" para identificar o componente
// O jQuery usa o caracter ":" como reservado
// Para evitar o conflito, eu substituo os ":" do id do componente por "_" e adiciono como classe CSS
// Assim o jQuery o código referenciar os componentes JSF individualmente.
styleClass += FaceletsFunctions.styleClassId(this);
}
setStyleClass(styleClass);
return super.getStyleClass();
}