0

The following facelet code, which renders a message when the employeeId inputText component loses focus, is executing successfully...

<h:inputText id="employeeId" value="#{questionAnswerAction.questionAnswerActionForm.employeeId}" 
 required="true" requiredMessage="#{app:requiredFieldMessage(bundle, 'label.peoplesoftId')}"
 binding="#{questionAnswerAction.questionAnswerActionForm.employeeIdInputText}">
    <f:ajax event="blur" render="employeeIdMessage" />
</h:inputText>
<h:message id="employeeIdMessage" errorClass="deg-msg-error" infoClass="deg-msg-info" for="employeeId"></h:message>

For some reason though, when I attempt to apply just about the same code on another facelet (the difference being that it is for a managerId instead of employeeId), when the setter occurs that gets triggered in the ajax call (setEmployeeId in the above call), my SessionScoped ManagedProperty is being flagged as null in the method. The ManagedProperty is actually a SessionScoped ManagedBean itself.

Can't figure out why this code is working fine in one page but then in another facelet when the 'set' occurs the ManagedProperty is showing up as null...

Zack Macomber
  • 6,682
  • 14
  • 57
  • 104
  • 1
    Not sure if it's the cause in this particular case as the provided information is not in SSCCE flavor, but using the `binding` attribute on a bean with a broader scope than the request scope is recipe for JSF state trouble (physically the same component is now shared across multiple requests/views in the same session!). Get rid of it or rebind it to a request scoped bean and retry. – BalusC Dec 06 '12 at 20:55
  • @BalusC - that binding attribute is on a UIInput field in the SessionScoped bean. The UIInput field is then passed to a method that adds a FacesContext message to the specified UIComponent (in this case it's the UIInput field). Does that make any difference? – Zack Macomber Dec 06 '12 at 21:39
  • @BalusC - setting the manager bean to be RequestScoped fixed it...this is strange because when I set my employee managed bean to be SessionScoped, the ajax functionality started working...any ideas on the reasons behind this? – Zack Macomber Dec 07 '12 at 16:54

1 Answers1

2

The binding attribute causes problems when bound to a property of a bean in a scope broader than the request scope, such as the session scope, because you're then basically sharing physically the same JSF component state across multiple page includes, page views and browser tabs/windows throughout the entire session. Get rid of it or rebind it to a request scoped bean.

The UIInput field is then passed to a method that adds a FacesContext message to the specified UIComponent (in this case it's the UIInput field

Just use a normal Validator or Converter depending on the functional requirement and register it on the component. If you throw a ValidatorException or ConverterException, then the wrapped FacesMessage will automagically end up in the right place. This way you don't need the component binding any more.

setting the manager bean to be RequestScoped fixed it...this is strange because when I set my employee managed bean to be SessionScoped, the ajax functionality started working

This is answered by points 4 and 5 in commandButton/commandLink/ajax action/listener method not invoked or input value not updated.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Do you know how I could show a success message via a validator? I'd like to use the h:message tag for my component for when either there's an error in validation or success if possible...I tried using FacesMessage.SEVERITY_INFO for the success message but that still indicated the message as an error... – Zack Macomber Dec 10 '12 at 15:50
  • Don't throw it as `ValidatorException`. Add it to the context directly. E.g. `context.addMessage(component.getClientId(context), message)`. – BalusC Dec 10 '12 at 15:51