How to call a method in session bean from JSF (xhtml) page.

Discussion in 'Java' started by Johnson Scaria John, Jun 30, 2008.

  1. How to call a method in session bean from JSF (xhtml) page.

    JSF

    <h:commandButton type="submit" value="Register"
    action="#{register12.register()}"/>

    SESSION BEAN

    package org.domain.FinalSeam.session;

    import java.util.List;

    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;

    import org.domain.FinalSeam.entity.User;
    import org.hibernate.validator.Valid;
    import org.jboss.seam.annotations.IfInvalid;
    import org.jboss.seam.annotations.Name;
    import org.jboss.seam.annotations.In;
    import org.jboss.seam.annotations.Logger;
    import org.jboss.seam.annotations.Outcome;
    import org.jboss.seam.log.Log;
    import org.jboss.seam.core.FacesMessages;
    @Stateless
    @Name("register12")
    public class RegisterActionBean implements Register
    {
    @In
    @Valid
    private User user;

    @PersistenceContext
    private EntityManager em;

    @IfInvalid(outcome=Outcome.REDISPLAY)
    public String
    register()
    {
    List existing = em.createQuery("select username from
    User where
    username=:username")
    .setParameter("username", user.getUsername())
    .getResultList();

    if (existing.size()==0)
    {
    em.persist(user);
    return
    "success";
    }
    else
    {
    FacesMessages.instance().add("User #{user.username}
    already
    exists");
    return null;
    }
    }

    }

    But it show some error "register12" is not bound"

    Is it correct way or need to modify some xml/file

    I expecting a big hand from all

    Thanks in advance
    Johnson Scaria John, Jun 30, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Thielen
    Replies:
    2
    Views:
    773
    Marek Lange
    Sep 12, 2003
  2. X3
    Replies:
    0
    Views:
    408
  3. BlackIce
    Replies:
    1
    Views:
    17,152
  4. Replies:
    0
    Views:
    2,514
  5. laredotornado
    Replies:
    4
    Views:
    4,222
    laredotornado
    Jul 10, 2008
Loading...

Share This Page