Not all components reRendered
gatz Sep 18, 2007 4:27 AMHi All.
I'm pretty new to RichFaces and also to JSF, but my fastest and only way to test some technology is to force myself to apply it to a new project :)
I know the basics of ajax and implemented something from scratch in the past.
Getting down to the problem, I have this couple of selectOneMenu components that are meant to customize a view, by realoding it through ajax calls.
I have three components and a table, but only the table gets updated...
The funny thing is. If I hard-refresh the page, the view gets refreshed and also the three components, since the bean has a session-scope, and from there on, I always see the fields changed that way. Like I had to hard-refresh every time.
Looks like I'm skipping some JSF lifecycle step...
Thanks in advance
Here is the code.
<f:view> <f:loadBundle basename="com.maserati.gtcc.messages" var="msg" /> <rich:panel header="#{msg['priceconf.title']}"> <h:form id="priceForm"> <h:panelGrid> <h:messages /> </h:panelGrid> <rich:panel> <h:panelGrid columns="2"> <h:outputLabel value="#{msg['priceconf.market']}" for="selMarket" /> <h:outputLabel value="#{msg['priceconf.model']}" for="selModel" /> <h:selectOneMenu id="selMarket" value="#{priceconfBean.marketCode}"> <a4j:support action="#{priceconfBean.updateDetail}" event="onchange" ajaxSingle="true" reRender="detail" /> <f:selectItems value="#{priceconfBean.availableMarkets}" /> </h:selectOneMenu> <h:selectOneMenu id="selModel" value="#{priceconfBean.modelCode}"> <a4j:support action="#{priceconfBean.updateDetail}" event="onchange" ajaxSingle="true" reRender="detail" /> <f:selectItems value="#{priceconfBean.availableModels}" /> </h:selectOneMenu> </h:panelGrid> </rich:panel> <rich:spacer height="4" /> <rich:panel> <a4j:outputPanel id="detail"> <h:panelGrid columns="3"> <h:outputLabel value="#{msg['priceconf.priceMask']}" for="selMask" /> <h:outputLabel value="#{msg['priceconf.available']}" for="chkAvailable" /> <h:outputText value="#{msg['priceconf.car.baseprice']}" /> <h:selectOneMenu id="selMask" value="#{priceconfBean.priceMask}"> <f:selectItems value="#{priceconfBean.priceMasks}" /> </h:selectOneMenu> <h:selectBooleanCheckbox id="chkAvailable" value="#{priceconfBean.available}" /> <h:inputText id="txtBasePrice" value="#{priceconfBean.basePrice}" /> </h:panelGrid> <rich:spacer height="4" /> <rich:dataTable id="tblDetailOpts" onRowMouseOver="this.style.backgroundColor='#F1F1F1'" onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'" cellpadding="0" cellspacing="0" width="700" border="0" value="#{priceconfBean.optList}" var="row"> <rich:column> <h:outputText value="#{row[0]}" /> </rich:column> <rich:column> <h:outputText value="#{row[1]}" /> </rich:column> <rich:column> <h:outputText value="#{row[2]}" /> </rich:column> <rich:column> <h:outputText value="#{row[3]}" /> </rich:column> <rich:column> <h:outputText value="#{row[4]}" /> </rich:column> </rich:dataTable> </a4j:outputPanel> </rich:panel> </h:form> </rich:panel> </f:view>
public class PriceconfBean implements InitializingBean { protected final Log logger = LogFactory.getLog(getClass()); private ConfigService configService; private HashMap<String, Integer> marketIds; private SelectItem[] availableMarkets; private SelectItem[] availableModels; private SelectItem[] priceMasks; private String marketCode; private String modelCode; private String priceMask; private Boolean available; private BigDecimal basePrice; private Collection optList; public void afterPropertiesSet() throws Exception { // get available markets ArrayList<SelectItem> items = new ArrayList<SelectItem>(); marketIds = new HashMap<String, Integer>(); Collection mkts = configService.getCountriesWithMarket(); Iterator mktsIt = mkts.iterator(); while (mktsIt.hasNext()) { Country c = (Country) mktsIt.next(); SelectItem item = new SelectItem(c.getCodmercato(), c.getDescEn()); marketIds.put(c.getCodmercato(), c.getId()); items.add(item); } availableMarkets = (SelectItem[]) items.toArray(new SelectItem[items.size()]); // get available models SelectItem[] models = { new SelectItem("7398040", "GT42AU") }; availableModels = models; // numeric masks SelectItem[] masks = { new SelectItem("", "-"), new SelectItem("#.##0,00", "1.234,56") }; priceMasks = masks; // populate values marketCode = (String) availableMarkets[0].getValue(); modelCode = (String) availableModels[0].getValue(); updateDetail(); } public String updateDetail() { optList = configService.getOptsByModelVersion(modelCode, marketCode); Country c = configService.getCountryById(marketIds.get(marketCode)); priceMask = c.getPricemask(); available = c.isAvailable(); basePrice = configService.getCarPrice(modelCode, marketCode); return null; } public void setConfigService(ConfigService configService) { this.configService = configService; } public SelectItem[] getAvailableMarkets() { return availableMarkets; } public SelectItem[] getAvailableModels() { return availableModels; } public SelectItem[] getPriceMasks() { return priceMasks; } ... }