I have a JSF form that consists of a grid and some detail fields. The detail fields contain the data of the first row in the grid. I have a backing bean that listens to the grid row selection and updates the detail fields' backing beans to represent the new values. Here comes the problem: I update the detail fields as needed (the listener is invoked in the ApplyRequestValuesPhase), but later the JSF framework reassings the old values to them in the UpdateModelValuesPhase.
My question is how to fix it? How could I assign new values to some JSF components from the grid selection change event?
Note: this is about the very the same thing as in JSF component doesn't update if changes came from grid click but I see the problem more clearly now I think, that's why I posted a new question.
It's not normal that a listener is invoked during apply request values phase. Perhaps you've set immediate="true" somewhere which will cause the actions to be performed during apply request values phase. You need to make sure that the listener is invoked during the invoke action phase which runs right after the update model values phase. Set immediate="false" or just remove the attribute altogether, it's the default behaviour already.
As per the comments, you seem to indeed have set the immediate="true" on the row selector, you'd need to remove it.
Related
We're using JSF 1.2 for our application. There is a selectBooleanCheckbox on on of the screens that represents a field in the backing bean. When loading the JSP, the value is shown correctly. There are three command buttons on the page; one calls a save function in the backing bean and then navigates to another screen. The other two are used to call utility methods in the backing bean before refreshing the screen. If the checkbox is unchecked, all three buttons function correctly. If the checkbox is checked, only the first functions as intended.
When the checkbox is selected, the backing bean is initialized but before the methods are called, a noSuchElementException is thrown from the generated servlet. The exception has a null message and no stack trace, so it's not incredibly helpful.
I've verified that the values of each field remain consistent with those that the screen is originally populated with. Dropdown inconsistencies are the only times I've ever seen this before, so any pointers on what else to check would be greatly appreciated. Unfortunately, I'm unable to post the code here but I will answer any questions if I am able.
Take a closer look at your buttons , and how is the working one being different from the non working ones.
I have a JSF/IceFaces application where there is a screen divided into 3 sections. Search fields, a grid and some details fields below. Currently if I enter some data into the search fields and click on a Search button (!) the grid shows the results and a certain method is called that puts the first result record's details into the backing beans of the details fields below the grid. This shows that there is no problem with the way I put data into the details fields.
However I have a gridclicklistener method as well that would like to change the detail fields according to the selection. After the click the same method gets called with the correct parameters that works well if invoked after the click on the Search button. The data is updated in the backing beans but the changes are not rendered even if I click the refresh button in the browser.
I found that if I click on the search button, the data-updating-method gets called from InvokeApplicationPhase.execute. When I get to this line after the grid click then it is from the ApplyRequestValuesPhase.
Do you have any ideas what could make this difference and how to get this work?
Update:
I can clearly see the updated value in the backing bean but it is not reflected on screen at all, even after F5.
I don't know what is causing your original problem.
With the icefaces push renderer however you could force an update:
http://wiki.icefaces.org/display/ICE/Getting+Started+with+ICEfaces+2#GettingStartedwithICEfaces2-icepush
I am implementing comboboxes in an application where IceFaces forms are being built dynamically. There are no xhtmls around, we put together everything from Java code. This works nice so far, but I am stucked at HtmlSelectOneListbox. In my code I create one that appears on the form as well correctly, but I don't know how to add the SelectItems to it.
HtmlSelectOneListbox combo = new HtmlSelectOneListbox();
combo.setId(id);
combo.setDisabled(readOnlyWindow);
/* parent is the UIComponent instance around us*/
parent.getChildren().add(combo);
I can create instances of SelectItems or even SelectItemsTag but the combo has no methods to set them. It has only a setValue/setValueExpression and with that I could set my value binding expression to the object representing #{bean.value}. But the selectitems property should be set not on the listbox but its nested f:selectItems that I don't know how to create.
I think UISelectItem and/or UISelectItems objects should be added as children of HtmlSelectOneListbox in a similar way you add combo to the parent component.
I have couple of panel grids with rendered attribute, on value change event of a drop down list, I make one of the panel grids visible, this works fine. But after the panel is displayed all the conversions and validations attached to components inside panel grid fail.
Even if the component is single and outside the grid it fails validation.
Am I missing something on rendered attribute? Is there some thing going on in JSF lifecycle.
Any help will be really helpful...
Thanks in advance
I am using jsf 2.0 mojarra implentation.
You need to ensure that the condition responsible for the rendered attribute evaluates the same in the subsequent request. JSF will namely recheck the condition during apply request values and validations phases. As of now it look like that your bean is request scoped and that the condition got lost in the subsequent request. Easiest fix is to place the bean in view scope by annotating it as #ViewScoped. This way the bean will live as long as you're interacting with the same view.
See also:
Benefits and pitfalls of #ViewScoped
Here's the sit:
I have a JSF component which is basically a list of 'documents'
I have any number of document viewer components on the same page.
None of these components "know" about each other. In other words, they cannot be configured at design time to link to each other or anything like that.
When the user clicks a document link I wish each one of the document viewer components to be notified.
Basically the idea would be to have the document viewers publish the fact that they listen for a certain type of event ("DocumentSelectedEvent" say) which the doc list component would fire.
I can think of ways of doing this that are not JSF specific, but I'm wondering if the JSF event model can handle that sort of thing.
Anyone have any ideas?
I don't think there's a way of doing that with the standard JSF event model.
Is there any way you can bind the components to a backing bean? That way when an event happens you can just go through your list of components and notify each of them.
You need to just bind the components with a backing bean and use a ValueChangeListener to notify the backing bean. The listener method could change the state of the other components which are tied to respective UI components.
Are you trying to do it in a "Ajax" way without page being explicitly submitted?
ValueChangeEvent
I do not know how you implemented your document list but if it were say a dropdown or any other multi item list component you can do an Value Change Event and force a submit on change for the component. Then in the page code backing bean you can call the methods for your viewers to load whatever you like.
In your jsf you just specify the value change handler you wrote in the backing bean.
/**
* Handle document click value change.
*
* #param valueChangedEvent the value changed event
*/
public void handleDocumentSelect(ValueChangeEvent valueChangedEvent) {
String selectedDocument = valueChangedEvent.getNewValue();
doDocViewer1DisplayMethod(selectedDocument);
doDocViewe2DisplayMethod(selectedDocument);
}
Modify your jsf tag to use your new value change event handler and force the submit.
<f:componentTag
attr=xxx
attr=xxx
valueChangeListener="#{pc_BackingBean.handleDocumentSelect}"
onChange=submit();>