0

My real use is a bit different, but I've narrowed the problem down to the code you see below. When you click the "go nowhere" button, all is well, no matter how many times you click it. But when you click "go somewhere", you get an IllegalStateException, "Component ID j_idt3:fnord1 has already been found in the view". Why does it work just fine returning null but not when you return a nav string?

I've read this answer, which is relevant, but doesn't have quite enough for my understanding. If there's a section in the jsf spec (or some such source) that is relevant, I'd greatly appreciate answers pointing it out.

/secure/application/sample.xhtml:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:fn="http://java.sun.com/jsp/jstl/functions"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
  <h:body>
    <h:form>
      <ul>
        <li><h:commandLink action="#{sample.goNowhere}" value="go nowhere"/></li>
        <li><h:commandLink action="#{sample.goSomewhere}" value="go somewhere"/></li>
      </ul>
      <h:selectOneMenu id="fnord0" binding="#{components.menuAddForm}">
        <f:selectItem id="fnord1" itemLabel="---" noSelectionOption="true"/>
      </h:selectOneMenu>
    </h:form>
  </h:body>
</html>

I don't need the ids, it just makes the error easier to read.

"components" is a request scoped hashmap, following the recommendation in this answer about component bindings.

Sample.java:

package com.example;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class Sample
{
  private static final String somewhere = "/secure/application/sample.xhtml";

  public String goNowhere()
  {
    System.out.println("goNowhere()");
    return null;
  }

  public String goSomewhere()
  {
    System.out.println("goSomewhere()");
    return somewhere;
  }
}
Community
  • 1
  • 1
djeikyb
  • 4,470
  • 3
  • 35
  • 42

3 Answers3

0

The implicit navigation needs the id of the view, change

private static final String somewhere = "/secure/application/sample.xhtml";

To

private static final String somewhere = "/secure/application/sample";
rekiem87
  • 1,565
  • 18
  • 33
  • Changing this doesn't change the outcome. – djeikyb May 27 '14 at 17:16
  • Yep, you totally right, sorry, that should be just a comment since doesn't help with you problem, ill read again and see if i can see something related to your issue – rekiem87 May 28 '14 at 18:48
  • Thanks for pointing this out though. Both ways seem to work for us. We weren't sure which was correct. – djeikyb Jun 03 '14 at 20:39
0

I see now, your namespaces import is wrong, which version of mojarra do you have? old one should be all in

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:fn="http://java.sun.com/jsp/jstl/functions"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets">

If you have the newer version (recomended and almost mandatory), you should have all in jcp namespace:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:f="http://xmlns.jcp.org/jsf/core"
  xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
rekiem87
  • 1,565
  • 18
  • 33
  • If you are using glassfish server note: In glassfish 4 there is a bug with the mojarra version included, in you're using 4.0.1 its fine, in case of 4 you should change your javax.faces.jar with the newest one from mojarra, in case of glassfish 3, then use java.sun namespaces – rekiem87 May 28 '14 at 18:55
  • Hey thanks for the update. I'll try that as soon as I can. Fwiw, we're using ant/ivy, deploying to tomcat 7. – djeikyb Jun 03 '14 at 20:37
  • Then just check the requerimients, if is JSF 7 (i recommend, some new and nice features) you should use jcp only, in EE 6 was java.sun, but im not very sure about tomcat since we're using glassfish, so good luck – rekiem87 Jun 03 '14 at 21:54
  • Tomcat 7, java ee 7, jsf 2.2, java 7. I fixed the namespaces, but I'm still getting the error. I *don't* get it on a different machine, so I have a lead to follow there now. – djeikyb Jun 05 '14 at 03:38
0

I was using jsf 2.2.4. I cannot reproduce the problem with subsequent point releases (2.2.5, 2.2.6, 2.2.7). The 2.2.5 release notes have several bug fixes with the keywords "duplicate", "id", and "navigation". I don't see how they directly address this issue. Nevertheless, I'm chalking this up to a bug.

I am glad to find that my understanding of this feature is correct and that my problems are merely an implementation bug.

For anyone who wants to see this bug in action, here's an SSCCE.

djeikyb
  • 4,470
  • 3
  • 35
  • 42