使用Primefaces我將bean傳遞給用戶剛剛單擊的組件的id。我想讓這個bean改變這個組件的風格。豆的相關部分:無法更新動態創建的組件
public void passIdClicked() {
FacesContext context = FacesContext.getCurrentInstance();
Map map = context.getExternalContext().getRequestParameterMap();
String idClicked = (String) map.get("idClicked");
UIComponent tile = FindComponent.doFind(context, idClicked);
Iterator<UIComponent> it = tile.getChildren().iterator();
UIComponent comp = it.next();
if (comp.getId().equals(idClicked)) {
HtmlOutputText labelDone = (HtmlOutputText) comp;
labelDone.setValue("heyyyyyyyyy");
labelDone.setStyleClass("myStyleClass");
}
}
修改沒有出現在屏幕上。我錯過了什麼?
[編輯] UI代碼: (。附加組分得到在「磚」 panelGroup中動態地在初始化階段所創建的passIdClicked方法修改這些部件中的一個 - 的一個用戶點擊)
<h:head>
</h:head>
<h:body>
<h:form id="form">
<h:commandButton actionListener="#{bean.createNewTile()}" title="new" value="new"/>
<p:remoteCommand name="sendNameClicked" actionListener="#{bean.passIdClicked}"/>
</h:form>
<h:panelGroup layout="block" id="tiles">
</h:panelGroup>
<script type="text/javascript">
$(document).ready(function() {
$('.tile').click(function() {
sendNameClicked([{
name: 'idClicked',
value: $(this).attr('id')
}]);
});
});
</script>
</h:body>
你能告訴你的UI代碼?如果你使用ajax,你可以使用update =「@ this」。 – Yamada
添加了UI代碼! – seinecle