0

I'm facing some issue that doesn’t make sense to me. I'm getting an "identifier resolved to null" when trying to use a selectOneMenu in a jsf page.

I do know this happens when the controller is not being resolved or the field is null, however: i) if I remove the selectOneMenu, everything works fine (including other fields binding to attributes of the same controller); ii) the field target of my selectOneMenu is a non-null String. Here is my code:

<h:selectOneMenu id="brandAccess" value="#{myController.field}" title="" >
   <f:selectItem itemValue="Item1" itemLabel="Item1" />
   <f:selectItem itemValue="Item2" itemLabel="Item2" />
   <f:selectItem itemValue="Item3" itemLabel="Item3" />
</h:selectOneMenu>

Controller:

@ManagedBean(name = "myController")
@SessionScoped
public class MyController implements Serializable {
   private String field; //Makes no difference with new String()
   public void setField(String field) { this.field = field; }
   public String getField() { return this.field; }
}

Edit:

The indicated question leads to two possible roots:

1) controller is null, not accessible or wrongly defined in the xhtml file: this is not the case. If I remove this particular component, everything else works fine.

2) Field doesn't exist or is null: Not the case, also. The field does exist and it is not null. Also, tried creating a new field and it is still not working

Update

For whoever is having the same issue with Spring and JSF: I cannot answer as the question was marked as duplicated. My case was a bit different from the ones related to the other question: the issue was that Spring wasn't creating my controller. For some reason, the error doesn't occur with h:inputText for example, but it does with h:selectOneMenu. Fixing is quite simple: just annotate the controller with @Controller (even though this is not a Spring Controller) and Spring will do the rest of the work.

pedrohreis
  • 821
  • 2
  • 11
  • 28
  • If you remove the component, you remove the symptom only, but not the root cause. The component tries to (write) access `field` on `myController` and `myContoller` resolves to `null`. Likely root causes for `myController` resolving to `null` are described in the linked answer. What does `` output? – Selaron Jun 13 '19 at 09:14
  • Did you possibly have a typo writing `value="#{MyController.field}" ` instead of `value="#{myController.field}" ` ? Asking because it's written upper case in your error message. – Selaron Jun 13 '19 at 09:18
  • Hi @Selaron, I've not included just to make the things easier, but I do have other fields binding to the same controller. For example, `` works pretty fine. That's why I say, I do not think my problem is in the controller usage – pedrohreis Jun 13 '19 at 09:36
  • Having `@ManagedBean` and it not working and adding `@Controller` as a 'fix' is weird and very illogical... unless and I quote: _"You didn't accidentally import javax.annotation.ManagedBean instead of javax.faces.bean.ManagedBean. Watch out with IDE autocomplete, Eclipse is known to autosuggest the wrong one as first item in the list."_ which is explicitly stated in the duplicate. – Kukeltje Jun 18 '19 at 15:11
  • Just rechecked and I'm importing the right class (`javax.faces.bean.ManagedBean`). What I realized is that spring wasn't creating the bean when only annotating with `@ManagedBean`. The first answer is stating this solution: https://stackoverflow.com/questions/12317288/how-to-declare-a-jsf-managed-bean-in-a-spring-3-1-application – pedrohreis Jun 18 '19 at 19:21

0 Answers0