3 Replies Latest reply: May 31, 2012 1:56 AM by EJP RSS

    Clicking an element in a list doesn't work

      Sorry about my rather vague subject - my problem is not so easy to sum up in a few words.

      I am working on an application that

      - Displays a list of items from a MySQL table
      - Each item should be clickable, and on clicking should open an edit page with the clicked item pre-loaded

      This must have been done millions of times before and should be simple. It doesn't work, presumably because I know too little. This is what I have done:

      The clickable item list looks like this (without all the trimmings):

      <h:dataTable id="users" value="#{userlist.userList()}" var="ul">
      <h:commandLink action="#{ul.edituser}" value="#{ul.uid}"/>

      This displays a list of the right sort of items, but the clickable item (the UID) doesn't do anything. Also, the resulting html looks the same no matter what I put into the action element - this is the inside of the a-tag:

      href="#" onclick="mojarra.jsfcljs(document.getElementById('j_idt9'),{'j_idt9:users:1:j_idt15':'j_idt9:users:1:j_idt15'},'');return false"

      I'm not entirely sure what that means; all I know is that it does not call the edituser() method.

      But what is the right way, then? I haven't found any examples that highlight this particular situation although it must be used all the time, I expect.
        • 1. Re: Clicking an element in a list doesn't work
          Spot the difference there. I do believe "ul" should be "userlist"; in other words it will link to an action method "edituser()" in a JSF managed bean which I assume will be named Userlist. Its really simple when you run into the problem of an action method not working: 99/100 times the action method EL declaration is wrong. Now it could be typo, but I've been known to forget the #{} part too...

          I use the JBoss Tools Eclipse plugin myself; it has nice JSF additions that add EL validation and autocompletion to the editor. That way I know already from the code view when I've made a mistake in stead of "at runtime". A missing action method turns up as a warning in the jsf editor for example. That is of course only helpful when you're actually using Eclipse ;)
          • 2. Re: Clicking an element in a list doesn't work
            So - I can't call into the actual row variable in a table? But how does the backing bean know which particular row I clicked on, then?

            As you can see, I am still a fumbling amateur; there ought to be a beginners' cook-book for how to design java ee applications.

            BTW - I use NetBeans; it seemed to come almost packaged with GlassFish, and I have got fairly used to the way they work together., and I like the annotation-only style you can use with GlassFish 3.
            • 3. Re: Clicking an element in a list doesn't work
              To be usable as an action, the edituser() method must be public, take no arguments, and return a String, usually null.