1 Reply Latest reply on Jan 22, 2009 3:22 AM by Cody Lerum

    Beginners Question

    Sven Loewe Newbie

      Hello,


      I am new to seam. I have generated my seam project with seam-gen and deployed it on jboss 4.2.2 AS. I have the login working but the page to edit my users does not work. It shows the values but it does not push the edited values back to my action bean. I can not access the changes on the page. Has anybody an idea?


      The page:


      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:s="http://jboss.com/products/seam/taglib"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:rich="http://richfaces.org/rich"
          template="/layout/template.xhtml">
      
      <ui:define name="body">
      
          <h:form id="login">
      
              <rich:panel>
                  <f:facet name="header">Edit user settings</f:facet>
      
                  <p>Please edit the user settings</p>
      
                  <div class="dialog">
                      <h:panelGrid columns="2" rowClasses="prop" columnClasses="name,value">
                          <h:outputLabel for="username" value="Username"/>
                          <h:outputText id="username"
                                    value="#{userEditAction.myUser.username}"/>
                          <h:outputLabel for="password" value="Password"/>
                          <h:inputSecret id="password"
                                      value="#{userEditAction.myUser.passwordHash}"/>
                                              <h:outputLabel for="email" value="Email"/>
                                              <h:inputText id="email" value="#{userEditAction.myUser.emailAddress}"/>
                                              <h:outputLabel for="firstname" value="Firstname"/>
                                              <h:inputText id="firstname" value="#{userEditAction.myUser.firstname}"/>
                                              <h:outputLabel for="name" value="Name"/>
                                              <h:inputText id="name" value="#{userEditAction.myUser.lastname}"/>
                      </h:panelGrid>
                  </div>            
      
              </rich:panel>
      
              <div class="actionButtons">
                  <s:button value="OK" action="#{userEditAction.save}" propagation="end"/>
                  <s:button value="Cancel" action="/home.xhtml" propagation="end"/>
              </div>
      
          </h:form>
      
       </ui:define>
      </ui:composition>





      The action bean:



      package com.mydomain.marketinfo2;
      
      import javax.annotation.PostConstruct;
      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      import org.jboss.seam.annotations.Begin;
      import org.jboss.seam.annotations.End;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.log.Log;
      import org.jboss.seam.security.Identity;
      import org.jboss.seam.security.management.PasswordHash;
      
      import com.mydomain.marketinfo2.inter.UserEdit;
      
      @Stateful
      @Name("userEditAction")
      public class UserEditAction implements UserEdit {
              @Logger
              private Log log;        
              private MyUser myUser;
              @PersistenceContext
              private EntityManager em;
      
              private Identity identity;
      
              @Begin
              @PostConstruct 
              public void onCreate() {
                      if (myUser == null) {
                              identity = Identity.instance();
                              log.info("UserName=" + identity.getCredentials().getUsername());
                              myUser = (MyUser) em.createQuery("select u from MyUser u where u.username=:userName").setParameter(
                                              "userName", identity.getCredentials().getUsername()).getSingleResult();
                      }
              }
      
              @Remove
              public void destroy() {
                      
              }
              
              public String save() {
                      if (!myUser.getPasswordHash().isEmpty()) {
                              String hashStr = PasswordHash.instance().generateSaltedHash(myUser.getPasswordHash(), myUser.getUsername());
                              myUser.setPasswordHash(hashStr);
                      }
                      em.persist(myUser);
                      return "save";
              }
      
              public MyUser getMyUser() {
                      return myUser;
              }
      
              public void setMyUser(MyUser myUser) {
                      this.myUser = myUser;
              }
      
      }"