6 Replies Latest reply on May 16, 2010 10:29 PM by mpelaez

    problem with @In

      Hi, I have one question. This is my situation: I have one class A and one class B, class A has an attribute type class B and class B has an attribute that is pased through class A, ok, better take a look to the fallow example:

       

      class A{

       

          @In(create=true)

          B obj;

       

          Integer vA;

        

         M(){

           this.obj.setVB(this.vA);

           this.obj.MX();

         }

       

       

      }

       

      class B{

       

         Integer vB;

       

      }

       

      What happends is that attribute vB will be equal to attribute vA, but I get attribute vA via presentation in class A and I have a method in class A like in the example, the problem is that  this.obj.set(this.vA); does not work because when I go to  this.obj.MX(); and I check the value in attribute vB appears null.

       

       

      Any Idea?? There is another way to do this??

        • 1. Re: problem with @In
          nbelaevski

          Hi,

           

          Can you please clarify more on the problem?

          • 2. Re: problem with @In

            ok, see if you understand this example:

             

            these are like entities:

             

            @Name("hc")
            public class HC {

               
                private int id;
                private String nomb_medico;
                private String nomb_especialidad;//la coge de cita
                   
                public HC(){}
               
                public int getId() {
                    return id;
                }
                public void setId(int id) {
                    this.id = id;
                }
                public String getNomb_medico() {
                    return nomb_medico;
                }
                public void setNomb_medico(String nomb_medico) {
                    this.nomb_medico = nomb_medico;
                }
                public String getNomb_especialidad() {
                    return nomb_especialidad;
                }
                public void setNomb_especialidad(String nomb_especialidad) {
                    this.nomb_especialidad = nomb_especialidad;
                }

             

            }

             

            @Name("cP")
            public class CP {

               
                private int id;
                private String nomb_paciente;
                private String nomb_medico;
               
                public CP(){}
               
                public int getId() {
                    return id;
                }
                public void setId(int id) {
                    this.id = id;
                }
                public String getNomb_paciente() {
                    return nomb_paciente;
                }
                public void setNomb_paciente(String nomb_paciente) {
                    this.nomb_paciente = nomb_paciente;
                }

             

                public void setNomb_medico(String nomb_medico) {
                    this.nomb_medico = nomb_medico;
                }

             

                public String getNomb_medico() {
                    return nomb_medico;
                }

             

            }

             

            @Name("cit")
            public class Cit {

               
                private int id;   
                private String nomb_espec;
                private String nomb_pac;
               
                public Cit(){}
               
                public Cit(int id,String nomb_espec,String nomb_pac){
                   
                    this.id=id;       
                    this.nomb_espec=nomb_espec;
                    this.nomb_pac=nomb_pac;
                }
               
                public int getId() {
                    return id;
                }
                public void setId(int id) {
                    this.id = id;
                }   
                public String getNomb_espec() {
                    return nomb_espec;
                }
                public void setNomb_espec(String nomb_espec) {
                    this.nomb_espec = nomb_espec;
                }
                public String getNomb_pac() {
                    return nomb_pac;
                }
                public void setNomb_pac(String nomb_pac) {
                    this.nomb_pac = nomb_pac;
                }
            }

             

            and these are classes that use the entities:

             

            main class:


            @Scope(ScopeType.CONVERSATION)

            @Name("ccHC")

            public class CCHC {

             

                private HC hc=new HC();

             

                @In(create=true)

                private CCCit ccCit;

             

                @In(create=true)

                private CCCP ccCP;

             

             

                @Begin(join=true)

                @Create

                public void crearHC(){

             

                    this.hc.setId(1);

                    this.hc.setNomb_medico("Mary");

                    this.hc.setNomb_especialidad(ccCit.getCit().getNomb_espec());

                }

             

                public void CrearConsPac(){

             

                    crearHC();

                    ccCP.crearCP(this.hc);//llama al metodo de la clase ccConsultaPaciente para coger el nombre del medico

                }

             

                public void setHc(HC hc) {

                    this.hc = hc;

                }

             

                public HC getHc() {

                    return hc;

                }

             

                public void setCcCit(CCCit ccCit) {

                    this.ccCit = ccCit;

                }

             

                public CCCit getCcCit() {

                    return ccCit;

                }

             

                public void setCcCP(CCCP ccCP) {

                    this.ccCP = ccCP;

                }

             

                public CCCP getCcCP() {

                    return ccCP;

                } 

             

             

            }

             

            @Name("ccCP")
            public class CCCP {

               
                private CP cP=new CP();
                private Cit cit=new Cit(2,"Cardiologia","Jose");
                private CCEF ccEF;
                private int id_cons;

                private String status;


               
                public CCCP(){}
               
                public void crearCP(HC hc){
                           
                    cP.setId(id_cons);
                    cP.setNomb_paciente(cit.getNomb_pac());
                    cP.setNomb_medico(hc.getNomb_medico());
                }
               
                public void M(){
                   
                    if(cP!=null){
                      if(cP.getNomb_medico().equals("Mary"))
                          status= "siiiiiiii";
                      status="nooooooo";
                    }
                    status="no sirve";
                   
                }
               
                public int getId_cons() {
                    return id_cons;
                }

             

                public void setId_cons(int id_cons) {
                    this.id_cons = id_cons;
                }

             

                public void CrearExamen(){
                           
                    ccEF.crearEF(this.cP);
                }
               
               
               
                public CCEF getCcEF() {
                    return ccEF;
                }

             

                public void setCcEF(CCEF ccEF) {
                    this.ccEF = ccEF;
                }

             

               
                public Cit getCit() {
                    return cit;
                }
                public void setCit(Cit cit) {
                    this.cit = cit;
                }

             

                public CP getCP() {
                    return cP;
                }

             

                public void setCP(CP cp) {
                    cP = cp;
                }

             

            }

             

             

            code in presentation:

                                       <rich:panel >
                                            <h:outputText value="#{ccHC.hc.id}" />
                                             <h:outputText value=": " />
                                            <h:outputText value="#{ccHC.hc.nomb_medico}" />
                                            <h:outputText value=": " />
                                            <h:outputText value="#{ccHC.hc.nomb_especialidad}" />
                                          </rich:panel>
                                         
                                          <rich:panel>
                                            <h:inputText value="#{ccHC.ccCP.id_cons}" />
                                            <h:commandButton action="#{ccHC.CrearConsPac()}" value="Aceptar" />
                                          </rich:panel>
                                         
                                          <h:outputText value="#{ccHC.ccCP.id_cons}" />
                                         
                                         
                                          <h:commandButton action="#{ccHC.ccCP.M()}" value="OKOK" />
                                       

            the problem is that the method ccHC.CrearConsPac() works fine but when the method ccHC.ccCP.M() is called the ccHC.ccCP.cP is null

            • 3. Re: problem with @In
              nbelaevski

              So, ccHC.ccCP.getCP() returns null, right?

               

              BTW, have you asked at Seam forum?

              • 4. Re: problem with @In
                ipraveenjain

                the way you are using @In is not correct , the purpose of @in is that you waht to use some thing in your class, so there is no need to have getter/setter for @In varibale.

                but what you are doing you are trying to aceess that variable inside your jsf page, which is not right.

                if u want to access the M() directly use cccp.M().

                and if required to access it form another class then you must have to initialize the @In variable in your class, and like this way there is no use of @In.

                • 5. Re: problem with @In

                  yes, returns null.

                  Thanks for you suggestion, I already ask. I am waiting for answer.

                  • 6. Re: problem with @In

                    ok, you know any way to pass an attribute to one class to another and the attribute that was created in first class remains in the second class when you called from another method???