Reputation: 1584
I am creating a user manager page which updates and adds users in the same page.
Relevant parts of the view:
<h:outputText value="Existing User: "/>
<h:selectOneMenu value="#{userManagerBean.existingUser}" valueChangeListener="#{userManagerBean.updateDetails}" onchange="submit();">
<f:selectItems value="#{userManagerBean.existingUserList}"/>
</h:selectOneMenu>
<h:outputText value="User Name: "/>
<h:inputText binding="#{userManagerBean.userNameBinding}" value="#{userManagerBean.userName}"/>
<h:outputText value="Password: "/>
<h:inputSecret redisplay="true" binding="#{userManagerBean.passwordBinding}" value="#{userManagerBean.password}"/>
<h:outputText value="Accessibility: "/>
<h:selectManyCheckbox layout="pageDirection" value="#{userManagerBean.selectedPagesList}" binding="#{userManagerBean.checkBoxBinding}">
<f:selectItems value="#{userManagerBean.pagesList}"/>
</h:selectManyCheckbox>
<h:commandButton action="#{userManagerBean.submitUser}" image="../images/submit.gif"/>
I am using value change listener in the dropdownlist. The bean is request scoped. The value change listener code is below:
public void updateDetails(ValueChangeEvent evt) {
helper = new Helper();
System.out.println(evt.getNewValue());
UserManagerDAO userManagerDAO = new UserManagerDAO();
List<String> userDetails = userManagerDAO.getUserDetails(evt.getNewValue().toString());
//setUserName(getExistingUser());
if (evt.getNewValue().toString().equalsIgnoreCase("select")) {
passwordBinding.resetValue();
userNameBinding.resetValue();
checkBoxBinding.resetValue();
//setUserName("finland");
} else {
passwordBinding.setValue(userDetails.get(0));
userNameBinding.setValue(evt.getNewValue());
checkBoxBinding.setValue(helper.splitStringAndAddToList(userDetails.get(1)));
}
}
When I click the submit button, new username and password is not getting bind to the property, instead the value is returning null. If I remove the if-else
block from the valuechange event code, everything works normal. How can I solve this problem?
Upvotes: 3
Views: 4664
Reputation: 1108567
The components are processed in the order as they appear in the view. You're calling UIInput#setValue()
on components which aren't processed yet. Their values will be overridden afterwards with the actual submitted values. Rather use UIInput#setSubmittedValue()
instead.
Upvotes: 3