I have a context menu in itemComp.xhtml , if i click on any item in the context menu action itemDisplay.refreshItems
will be called and on complete of this action JavaScript function showPanel()
will be called
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>
In refreshItems()
of itemDisplayBean.java, I am setting all the variables as true.
itemDisplayBean.java
private boolean availableBags = false;
public boolean getAvailableBags() {
return this.availableBags;
}
public void setAvailableBags(boolean availableBags) {
this.availableBags = availableBags;
}
private boolean availableBags = false;
public boolean getAvailableBags() {
return this.availableBags;
}
public void setAvailableBags(boolean availableBags) {
this.availableBags = availableBags;
}
private boolean availableChairs = false;
public boolean getAvailableChairs() {
return this.availableChairs;
}
public void setAvailableChairs(boolean availableChairs) {
this.availableChairs = availableChairs;
}
private boolean availableTables = false;
public boolean getAvailableTables() {
return this.availableTables;
}
public void setAvailableTables(boolean availableTables) {
this.availableTables = availableTables;
}
public String refreshItems() {
setAvailableBags(true);
setAvailableChairs(true);
setAvailableTables(true);
}
and in itemDisplay.xhtml, I have the JavaScript function showPanel()
as follows.
function showPanel(item, itemId) {
if (item == 'Bags Report') {
if (#{itemDisplay.availableBags})
Richfaces.showModalPanel('bags');
else
alert('No bags Found');
} else if (item == 'Chairs Report') {
if (#{itemDisplay.availableChairs})
Richfaces.showModalPanel('chairs');
else
alert('No Chairs Found');
} else if (item == 'Tables Report') {
if (#{itemDisplay.availableTables})
Richfaces.showModalPanel('tables');
else
alert('No Tables Found');
}
}
and the problem here is -- in JavaScript function, I am not getting the updated backing bean values, hence availableBags ( if( #{itemDisplay.availableBags} ))
is false
(even though it is set to true in backing bean), and the panel is not shown. If I refresh the page then i will get the updated value from backing bean ( if( #{itemDisplay.availableBags} )
as true and the panel is shown.Any one can help me why i am getting the updated value only by refreshing the page.
#{}
things) won't be evaluated with the new values unless you render therich:menuItem
again. That's why you don't have the them updated. – Xtreme Biker