4 Replies Latest reply on Oct 30, 2007 8:03 AM by ivan.tufegdzic

    Simple examples needed

    mortena

      I need to do the following:

      Create a form, where I can edit the Credentials of a User and the user.

      User.java has properties:


      String firstName,
      String surName
      Credential credential

      Credential.java has properties:

      username,
      password.


      Now I'm creating a form where I can edit the firstName and surName of the user and the users credentials.

      How can I create an input field where i can edit the credentials of the user?

      I've tried:

      <h:inputText required="true"
      value="#{userHome.instance.credential.username}"/>

      But it gives an error saying that the credentials are null:

      Target Unreachable, 'credential' returned null on 'com.tmn.smile.model.User'".

      Any hints on where I can find simple examples showing how these things should be done?

        • 1. Re: Simple examples needed
          damianharvey

          Look at the 'examples' folder in your Seam directory.

          For your problem you just need to instantiate a Credential when you create a new User in UserHome. Try doing this in createInstance().

          Cheers,

          Damian.

          • 2. Re: Simple examples needed
            mortena

            I Changed the following in UserHome generated by seam-gen:

            @Override @Begin
             public void create() {
             super.create();
             }
            


            to:

            @Override @Begin
             public void create() {
             super.create();
             super.getInstance().setCredential(new Credential());
             }
            


            Added a line where I manually create a new credential.

            Now it works.

            • 3. Re: Simple examples needed
              mortena

              I was a little too fast there.

              Make sure you only set the credentials if the credentials are null.

              Else they'll be overwritten.

              • 4. Re: Simple examples needed
                ivan.tufegdzic

                When you create User in that moment you must create Credential. After that link that entities.
                user.setCredential(that new credential);