Announcement Announcement Module
Collapse
No announcement yet.
passing info from one bean to another Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • passing info from one bean to another

    I am trying to process the name in two different beans as follows. Basically the original "get/setName" for name is working fine. I am tyring to process this name in another bean by name "set/getNamesAsString" so that I can use it in another part of jsp. Is it possible to do it like this. It is not working. Can anyone help me in this.
    Code:
    public class MyForm {
    
       private String name;
     
       public void setName(String name){
          this.samples = samples;
       }
    
       public String getname(){
          return name;
       }
        private List<String> namesAsString;   
      
      private String names = this.name;
    
      public List<String> getNamesAsString(){
          
           return namesAsString;
           
       }
               
       public void setNamesAsString(String names){
          
            String[] multiSamples = name.split("\r\n|\r|\n");
            List<String> multiNames = new ArrayList();
    
            for(int i=0; i <= multiSamples.length-1; i++){
                if(multiSamples[i] != null && multiSamples[i].length() != 0){
                    
                  multiNames.add(multiSamples[i]);                          
                }          
            }
           
           this.namesAsString = multiNames;
           
       }
    
    }
    Thanks

  • #2
    . I am tyring to process this name in another bean by name "set/getNamesAsString" so that I can use it in another part of jsp. Is it possible to do it like this. It is not working.
    You haven't supplied your JSP code or an error message. How, exactly, is it not working? You should be able to bind to the "namesAsString" property path, and I believe this will work fine.

    Comment


    • #3
      Originally posted by pmularien View Post
      You haven't supplied your JSP code or an error message. How, exactly, is it not working? You should be able to bind to the "namesAsString" property path, and I believe this will work fine.
      Let me more clearly explain about my problem.
      I have a spring bind for "name" in my jsp. My spring Bind is only with respect to only name and not namesAsString
      I am trying to use "name" in two different types like name and namesAsString so that I can call them in two different situation. "name" will be used in the controller where as "namesAsString" is being used in jsp to display as separate string after splitting(as shown in the above code). Basically I am binding a textarea into "name" first and then I am trying to add one more method "get/setnamesAsString", so that I can call this splitted strings in order to display. That is why I have used as below:
      Code:
       
      private List<String> namesAsString;   
        
        private String names = this.name;
      public void setNamesAsString(String names){
      ...
      }
      1. I used get/setName for name (spring bind)
      2. Then I am declaring a List "namesAsString"
      3. Then I am assiging name to names which is being processed inside setnamesAsString so that a list of strings will be get from my jsp as ${form.NamesAsString}


      Does it make any sense? Hope I have clearly mentioned about my problem. Foa single spring bind, I want to have them processed in two different way so that I can them in different occassion. If the above method is not possible, can anyone let me know to resolve the situation.

      Thanks for your time.

      Regards
      Gopu

      Comment


      • #4
        I guess I don't understand why you need the separate List<String> - why can't your get/setNamesAsString methods just work directly on the name member variable? Where are you expecting the setNamesAsString method to be called?

        Comment


        • #5
          Originally posted by pmularien View Post
          I guess I don't understand why you need the separate List<String> - why can't your get/setNamesAsString methods just work directly on the name member variable? Where are you expecting the setNamesAsString method to be called?
          As my jsp is not splitting with "\n" as the delimiter, I am trying to add some code as above in java part so that I try calling List "namesAsString" for the display in a nicer way. But I am not getting anything in my display jsp, may be something wrong in the logic or it is not possible to send one bean value as a parameter for another bean/method.

          Where as the rest of the application like controller etc... deal with the existing "name". As I don't want to mess with the whole application, I am trying like this. Please let me know about your view on this.

          Thanks

          Comment

          Working...
          X