[jboss-user] [JBoss Seam] - Re: @in(create=true) not working !
mickknutson
do-not-reply at jboss.com
Wed Oct 24 16:55:17 EDT 2007
Sorry, but I am a bit confused as to the @Name, and variable name solutions proposed.
I have a UserServiceAction (SFSB), and a User (EB).
Here is my UserServiceACtionL
| package com.baselogic.yoursos.user;
|
| import org.hibernate.validator.InvalidStateException;
| import org.hibernate.validator.InvalidValue;
|
| import org.jboss.seam.annotations.Begin;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Out;
| import org.jboss.seam.bpm.Actor;
| import org.jboss.seam.contexts.Context;
| import org.jboss.seam.faces.FacesMessages;
| import org.jboss.seam.security.Identity;
|
| import javax.annotation.Resource;
|
| import javax.ejb.Remove;
| import javax.ejb.SessionContext;
| import javax.ejb.Stateful;
|
| import javax.persistence.EntityManager;
| import javax.persistence.PersistenceContext;
|
|
| /**
| * User Service Bean.
| */
| @Stateful
| @Name("userService")
| public class UserServiceAction implements UserService {
|
| /** variable. */
| @PersistenceContext EntityManager em;
|
| /** variable. */
| @Resource SessionContext ctx;
|
| /** variable. */
| @In Context sessionContext;
|
| /** variable. */
| @In(create=true)
| @Out
| User user;
|
| /** variable. */
| @In FacesMessages facesMessages;
|
| /** variable. */
| @In Identity identity;
|
| /** variable. */
| String password = null;
|
| /**
| * todo DOCUMENT ME!
| *
| * @param password todo DOCUMENT ME!
| */
| public void setPasswordVerify(String password) {
| this.password = password;
| }
|
| /**
| * todo DOCUMENT ME!
| *
| * @return todo DOCUMENT ME!
| */
| public String getPasswordVerify() {
| return password;
| }
|
|
| /**
| * todo DOCUMENT ME!
| */
| @Begin(
| nested = true,
| pageflow = "registration"
| )
| public void startRegistration() {
| }
|
| /**
| * todo DOCUMENT ME!
| *
| * @return todo DOCUMENT ME!
| */
| public boolean isValidNamePassword() {
| boolean ok = true;
|
| if (!isUniqueName()) {
| facesMessages.add("userName", "This name is already in use");
| ok = false;
| }
|
| if (!isPasswordsMatch()) {
| facesMessages.add("passwordVerify", "Must match password field");
| ok = false;
| }
|
| return ok;
| }
|
| /**
| * todo DOCUMENT ME!
| *
| * @return todo DOCUMENT ME!
| */
| @SuppressWarnings("unchecked")
| private boolean isUniqueName() {
| String name = user.getUsername();
|
| /*if (name == null) return true;
|
| List<User> results = em.createQuery("select u from User u where u.userName = :name")
| .setParameter("name", name)
| .getResultList();
|
| return results.size() == 0;*/
| return true;
| }
|
| /**
| * todo DOCUMENT ME!
| *
| * @return todo DOCUMENT ME!
| */
| private boolean isPasswordsMatch() {
| String customerpass = user.getPassword();
|
| return (password != null) && (customerpass != null)
| && (customerpass.equals(password));
| }
|
| /**
| * todo DOCUMENT ME!
| *
| * @return todo DOCUMENT ME!
| */
| public String saveUser() {
|
| if (!isValidNamePassword()) {
| /////facesMessages.add("User name #{customer.userName} is not unique");
|
| return null;
| }
|
| try {
| em.persist(user);
| sessionContext.set("currentUser", user);
| Actor.instance().setId(user.getUsername());
|
| identity.setUsername(user.getUsername());
| identity.setPassword(user.getPassword());
| identity.login();
|
| facesMessages.addFromResourceBundle("createCustomerSuccess");
|
| return "success";
| } catch (InvalidStateException e) {
| InvalidValue[] vals = e.getInvalidValues();
|
| for (InvalidValue val : vals) {
| facesMessages.add(val);
| }
|
| return null;
| } catch (RuntimeException e) {
| ctx.setRollbackOnly();
|
| facesMessages.addFromResourceBundle("createCustomerError");
|
| return null;
| }
| }
|
| /*public Map<String, Integer> getCreditCardTypes() {
| Map<String, Integer> map = new TreeMap<String, Integer>();
| for (int i = 1; i <= 5; i++) {
| map.put(Customer.cctypes[i - 1], i);
| }
| return map;
| }*/
|
| /**
| * todo DOCUMENT ME!
| */
| @Remove public void destroy() {
| }
|
| } // The End...
|
Here is my User:
| package com.baselogic.yoursos.user;
|
| import com.baselogic.yoursos.BaseEntity;
| import com.baselogic.yoursos.Contact;
|
| import org.hibernate.validator.Length;
| import org.hibernate.validator.NotNull;
|
| import java.io.Serializable;
|
| import java.util.ArrayList;
| import java.util.List;
|
| import javax.persistence.*;
|
|
| /**
| * Main User.
| */
| @Entity
| @Table(name = "USERS")
| public class User extends BaseEntity implements Serializable {
|
| ...//more details omitted for clarity //
|
My error seems to be from the User object in my UserServiceAction and is identical to this.
How do I fix this? Make my User Object name be "User userService" to match @Name("userService") ???
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4098564#4098564
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4098564
More information about the jboss-user
mailing list