1 2 Previous Next 22 Replies Latest reply on Oct 24, 2007 5:08 PM by pmuir Go to original post
      • 15. Re: @in(create=true) not working !
        kukeltje

        I have been struggling with this as well for the last few hours. The way I finally solved it was giving the injected variable the same name as the @Name value of the object to be injected. If I do not do this, I see in the debug that Seam tries to find a contectVariable with the name of the variable to be injected. It does not look (anymore?) for a contextVariable of the same type. If it finds nothing, no the create=true does not go off.

        So:

        @In(create=true) MyObj myVar
        in combination with
        @Name("myVar")


        works

        whereas
        @In(create=true) MyObj myOtherVar
        in combination with
        @Name("myVar")


        does not (does not find the variable, but worse, does not create a new one)


        An additional test with

        @In(create=true, value="myVar") MyObj myOtherVar
        in combination with
        @Name("myVar")


        works to...

        Oh.. and I do not have a richpanel

        • 16. Re: @in(create=true) not working !
          pmuir

          Seam has *always* done bijection by variable name.

          • 17. Re: @in(create=true) not working !
            _polly

            yeah... this is different to my problem. I had the injected variable name matching @Name, and it still couldn't handle auto-creation from within the richfaces tab panel.

            Incidentally I never solved this. Just worked around it by refactoring a bit, so I didn't have to call any components referencing any injected auto-created components from the tabpanel.

            • 18. Re: @in(create=true) not working !
              matt.drees

              I think this due to a richfaces tabPanel behavior change/bug.
              See http://jira.jboss.com/jira/browse/RF-1047 and referenced forum post.

              I'll bet your EntityController is conversation-scoped, right? The conversation scope isn't available during restore view (when restoreState() is being called above), so that's why it's bombing.

              Your issue is not quite the same one I had, but it's related. You might comment on the issue, asking if they can possibly refrain from calling getValue() during restoreView. If they can't, though, you'd probably have to mark your injected entityController as non-required. (That is, if you decided to undo your workaround-refactoring, which I'm not necessarily recommending; I'm saying this more for anyone else who might be having the same problem.)

              • 19. Re: @in(create=true) not working !
                kukeltje

                @Pete, Yes, I know, but if I do not have a user as a variable and have an @In(create=true) I would have expected seam to create one.. otoh, how would I access it then....under what name.....hmmmmm I Probably always did this correctly by accident. Sorry for disturbing this thread ;-)

                • 20. Re: @in(create=true) not working !
                  _polly

                  matt - you are spot on - i was trying to reference a conversation scoped bean from a session scoped bean, from the tab panel, and it was this part that was failing.

                  thankyou very much for the explanation! it looks like it's been fixed in richfaces 3.2.0, so maybe i'll try upgrading...

                  • 21. Re: @in(create=true) not working !
                    mickknutson

                    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") ???


                    • 22. Re: @in(create=true) not working !
                      pmuir

                      You need a factory for user or to make User a Seam component.

                      1 2 Previous Next