tags:

views:

2162

answers:

2
<h:selectOneMenu id="selectOneMenu"  value="#{Bean1.val1}" >
    <f:selectItems value="#{Bean1.selectItems}"/>
    <a4j:support event="onchange" action="#{Bean1.onSelectOneMenuChange}" reRender="textbox1 , textbox2 , textbox3, textbox4"  />
 </h:selectOneMenu>

<h:inputText id="textbox1" value="#{Bean1.textbox1}"> </h:inputText>
<h:inputText id="textbox2" value="#{Bean1.textbox2}"> </h:inputText>
<h:inputText id="textbox3" value="#{Bean1.textbox3}"> </h:inputText>
<h:inputText id="textbox4" value="#{Bean1.textbox4}"> </h:inputText>

Bean1.onSelectOneMenuChange() will change the value of Bean1.textbox1 , Bean1.textbox2,Bean1.textbox3 and Bean1.textbox4 depending on the value selected (Bean1.val1) .Sometimes , it will change all the textbox value and sometimes it will only changes some textbox value.

When users change the value in the "selectOneMenu" drop down list control , the JSF framework will not call the update model values phase but call the Bean1.onSelectOneMenuChange() directly. After that , the all the textbox are reRender. Because the update model values phase is not called , the values entered by the user is never set the the Bean1 and the original value is shown in the textbox after reRender . So I want to ask:

  1. How can I manually call the update model values phase inside Bean1.onSelectOneMenuChange() ?How can I get the value input input by the users inside Bean1.onSelectOneMenuChange() and set it to the corresponding fields of the Bean1 ?

2.Another approach is that only reRender those textbox whose values are updated inside the Bean1.onSelectOneMenuChange() .However , there are many cases . For example , a value will change all the textbox value and a values may only change some textbox value.How can I reRender conditionally ? What method is more prefer for maintainability?

A: 

Update :

For point 2 , I find that the reRender preperties of the can accept the EL expression , so I tried to use

 <a4j:support event="onchange"  action="#{Bean1.onSelectOneMenuChange}" reRender="#{Bean1.reRenderIDList}"  /> .

Inside the Bean1.onSelectOneMenuChange(), I set the Bean1.reRenderIDList to a set of ID that required to be reRender based on the business requirement. The Bean1.getRenderIDList() runs when the page is refresh .However when I change the value of in the UI , Bean1.getRenderIDList() will never run again .Thus , the textbox cannot be reRender?Any idea?

A: 

Your code looks fine. There is no reason for Update Model phase not to happen (you don't use immediate=true). And if you had conversation/validation error, then the action would never be called. Check what phases you go through.

Max Katz
Yes ,there are some <h:inputText> that assign a java script function to the onblur properties to do some validation . How can I bypass the validation phase for those <a4j:support> onchange event ? I want to do such validation only when user fill in all data and press submit button.Thanks!