开发者

Richfaces 4 autocomplete component AJAX Value Update

开发者 https://www.devze.com 2023-03-16 04:58 出处:网络
Trying to migrate a Richfaces 3.3 project to 4. Got to a rich:suggestionBox component and converting it to a rich:autocomplete component, but having major troubles.

Trying to migrate a Richfaces 3.3 project to 4. Got to a rich:suggestionBox component and converting it to a rich:autocomplete component, but having major troubles.

Requirements are: fill in part of the autocomplete, it presents user with suitable options. When the user selects something from the dropdown, the component should update it's value, disable itself, and also calculate/update the default value in a seconda开发者_运维百科ry field, which the user is able to edit. So far I have this:

<a4j:jsFunction name="jsFunc"
    execute="autoComplete"
    render="species_name individualUserStr"
    actionListener="#{individualsBean.selectedIndividualElem.assignDefaultNickname}"/>


<rich:autocomplete
autocompleteMethod="#{individualsBean.speciesForBox}"
mode="cachedAjax"
layout="table"
var="sp"
id="species_name"
value="#{individualsBean.selectedIndividualElem.userCommonName}"
fetchValue="#{sp.commonName}"
disabled="#{individualsBean.selectedIndividualElem.userCommonName != null
    and individualsBean.selectedIndividualElem.userCommonName ne ''}"
onselectitem="jsFunc()"

>
...
</rich:autocomplete>

<h:inputText value="#{individualsBean.selectedIndividualElem.ssi.individualUserStr}"
id="individualUserStr"
maxlength="28"
styleClass="inputTextMediumRF">
</h:inputText>

Right now, when the user selects something the jsFunc is called, assignDefaultNickname is called and everything works fine, except for the fact that the calculation in assignDefaultNickname, used to determine the value of the secondary field, individualUserStr, depends upon the value of species_name, but species_name is not submitted until I submit the form, so the calculation done in assignDefaultNickname is incorrect.

I need to somehow call the setter on individualsBean.selectedIndividualElem.userCommonName, before assignDefaultNickname is called, but I cannot figure out how to do this. There seems to be problems with AJAX and this autocomplete function; that's part of the reason why I have to use this round-a-bout jsFunction component to even call the method in the first place.

Any suggestions on how to solve this?


Found the solution to my own question. Basically, needed to learn how to use the execute attribute. The lesson to any other JSF 2.0 n00bs out there is to use execute to selectively reprocess the page. With execute you can make a white-space separated list of component IDs that should have their values re-bound to the backing bean, in case they need to be used in the listener responding to an AJAX event. In my case, this meant changing the jsFunction tag as follows:

<a4j:jsFunction name="jsFunc"
execute="species_name individualUserStr"
render="species_name individualUserStr"
actionListener="#{individualsBean.selectedIndividualElem.assignDefaultNickname}"/>

As you can see, the jsFunction now, when it is calling the assignDefaultNickname function will first update the values bound to both the auto-complete and the inputText components and THEN run assignDefaultNickname.

0

精彩评论

暂无评论...
验证码 换一张
取 消