通过JSF中的JavaScript从bean获取更新值
我在itemComp.xhtml中有一个上下文菜单,如果我单击上下文菜单action通过JSF中的JavaScript从bean获取更新值,javascript,jsf,richfaces,Javascript,Jsf,Richfaces,我在itemComp.xhtml中有一个上下文菜单,如果我单击上下文菜单actionitemDisplay中的任何项目。将调用refreshItems,此操作完成后,将调用JavaScript函数showPanel() itemComp.xhtml <rich:contextMenu disableDefaultMenu="true" event="oncontextmenu" submitMode="ajax"> <rich:menuItem disabled="tr
itemDisplay中的任何项目。将调用refreshItems
,此操作完成后,将调用JavaScript函数showPanel()
itemComp.xhtml
<rich:contextMenu disableDefaultMenu="true" event="oncontextmenu" submitMode="ajax">
<rich:menuItem disabled="true" style="color:black; font-weight:bold;" value="Items"/>
<rich:menuSeparator/>
<c:forEach items="#{itemDisplay.componentTypeMap.keySet}" var="itemValue">
<rich:menuItem value="#{itemValue}"
rendered="#{(itemValue == 'Bags Report') or
(itemValue == 'Chairs Report') or
(itemValue == 'Tables Report')}"
action="#{itemDisplay.refreshItems}"
oncomplete="showPanel( '#{itemValue}','#{item.id}')">
</rich:menuItem>
</c:forEach>
</rich:contextMenu>
在itemDisplay.xhtml中,我有JavaScript函数showPanel()
,如下所示
功能显示面板(项目,项目ID){
如果(项目==‘行李报告’){
if(#{itemsplay.availableBags})
Richfaces.showModalPanel(“袋子”);
其他的
警报(“未发现行李”);
}否则,如果(项目==‘主席报告’){
if(#{itemsplay.availableChairs})
Richfaces.showModalPanel(“椅子”);
其他的
警报(“未找到椅子”);
}else if(项==‘表报告’){
if(#{itemsplay.availableTables})
Richfaces.showModalPanel(“表格”);
其他的
警报(“未找到表”);
}
}
这里的问题是——在JavaScript函数中,我没有得到更新后的backingbean值,因此availableBags(
if(#{itemDisplay.availableBags}))
是false
(即使在backingbean中它被设置为true),并且没有显示面板。如果我刷新页面,那么我将从backingbean(If(#{itemsdisplay.availableBags})
中获得更新后的值,并显示面板。任何人都可以帮助我为什么只通过刷新页面来获得更新后的值。如前所述,EL表达式在页面呈现并成为静态文本时进行计算
您可以使用@data
,例如:
<rich:menuItem data="#{itemDisplay.availableBags}"
oncomplete="showPanel('#{itemValue}', event.data)" … >
event.data
将包含属性的当前值(您甚至可以将其指向对象)
编辑:在RichFaces 3.x中,JS参数只是
数据
我搞不懂,你能详细解释一下EL表达式吗(那种{}
东西)除非再次呈现rich:menuItem
,否则将不会使用新值进行求值。这就是为什么您不更新它们。我已向嵌入此rich:menuItem的a4j:Panel添加了一个id,并尝试重新呈现它…………rerender=“testPanel”……但我收到以下错误消息:已为元素“a4j:outputPanel”指定了“属性”id“.event.data在showPanel javascriptfunction中未定义,我使用alertevent.data
打印它。您使用的RichFaces版本是什么?最好下次再提及,否则我希望您使用最新版本。:)
<rich:menuItem data="#{itemDisplay.availableBags}"
oncomplete="showPanel('#{itemValue}', event.data)" … >