【发布时间】:2014-01-27 17:08:28
【问题描述】:
使用 Primefaces,我将用户刚刚单击的组件的 ID 传递给 bean。我希望 bean 改变这个组件的样式。 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");
}
}
修改没有出现在屏幕上。我错过了什么?
[编辑] 用户界面代码: (其他组件在初始化阶段动态创建在“tiles”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"。
标签: jsf jsf-2 primefaces