The only way I found to solve this is remove submitted values over the component tree by doing a call to 'refreshUIValues()':
public void refreshUIValues() {
refreshUIValues(null, true);
}
public void refreshUIValues(UIComponent component, boolean refreshChildren) {
if (component == null) {
component = facesContext.getViewRoot();
}
if (component instanceof EditableValueHolder) {
// force data load from bean instead of submittedValue
EditableValueHolder evh = (EditableValueHolder)component;
evh.setSubmittedValue(null);
}
if (refreshChildren && component.getChildCount() > 0) {
// call refreshState for every children
Iterator i = component.getChildren().iterator();
while (i.hasNext()) {
UIComponent child = (UIComponent)i.next();
refreshUIValues(child, refreshChildren);
}
}
}
Ricardo.
On 3/23/06, Dennie de Lange <[EMAIL PROTECTED]> wrote:
Hello,
I want to change some values of a backing bean through a
valueChangeListener, and then show the results to the user.
The use case is:
Address (Managed Bean - Session scope)
OrderView (Managed Bean - Request scope)
JSP snippet:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
<x:inputText value="#{address.searchcode}"
valueChangeListener="#{orderView.processSearchcodeChange}"
immediate="true"
>
<x:inputText value="#{ address.name}">
<f:validateLength minimum="5"/>
</x:inputText>
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- // End JSP Snippet
Code snippet:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-
public class OrderView..
private Address address;
public void processSearchcodeChange(ValueChangeEvent event){
String searchText = (String) event.getNewValue();
Address result = SomeAddressDAO.getAddress(searchText);
address.setName(result.getName());
// Go to the renderresponse phase, else the values will be
overwritten
// in the update model phase
FacesContext context = FacesContext.getCurrentInstance ();
context.renderResponse();
}
// Address is injected using managed properties! (faces-config.xml)
public void setAddress(Address address)..
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- // End code snippet
I want to use immediate = true, because the validation phase should not
occur (the name can be empty when searching an address).
The problem is: this doesn't work! The page doesn't display the new set
values on address. I can change them directly in the component by using
component binding, but I think this isn't an elegant solution. Something
like context.setModelUpdated(true) would be nice.
Maybe somebody has a simple solution for this problem? Many thanks in
advance.
Greetz,
Dennie

