help needed in implementing design pattern

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ajos
    Contributor
    • Aug 2007
    • 283

    help needed in implementing design pattern

    Hi friends,
    I am trying to implement a factory design pattern.I'm quite confused on how to put it down here.Let me try.I have certain html option containing values like example--->
    [HTML]<html:select property="branc h" size="1">
    <html:option value="Californ ia"></html:option>
    <html:option value="New York"></html:option>
    and so on....
    [/HTML]
    the option value here is lage.so ive been told to implement the factory pattern.I've been searching on google on how to do this,but found no help.I dont know how to start with this n im lost now completely.Can anyone please help me on how to implement the factory pattern with respect to html option values?Any input from you will be helpful and appreciated.... Awaiting your response.
    regards,
    ajos
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by ajos
    Hi friends,
    I am trying to implement a factory design pattern.I'm quite confused on how to put it down here.Let me try.I have certain html option containing values like example--->
    [HTML]<html:select property="branc h" size="1">
    <html:option value="Californ ia"></html:option>
    <html:option value="New York"></html:option>
    and so on....
    [/HTML]
    the option value here is lage.so ive been told to implement the factory pattern.I've been searching on google on how to do this,but found no help.I dont know how to start with this n im lost now completely.Can anyone please help me on how to implement the factory pattern with respect to html option values?Any input from you will be helpful and appreciated.... Awaiting your response.
    regards,
    ajos
    What do you mean by "the option value here is large"?

    Comment

    • ajos
      Contributor
      • Aug 2007
      • 283

      #3
      Originally posted by r035198x
      What do you mean by "the option value here is large"?
      i meant that i have lots of html option in my html select like for say...
      [HTML]
      <html:option value="Californ ia"></html:option>
      <html:option value="New york"></html:option>
      i have some 20 of them and the code in jsp looks too big because of this.
      [/HTML]
      this way in each page i have 3 html option tag.so i want to implement the factory pattern.
      regards,
      ajos

      Comment

      • ajos
        Contributor
        • Aug 2007
        • 283

        #4
        Is it possible to populate the option from a ArrayList.
        i have done something like this--->
        Code:
        public ArrayList<String> getSelect()
        	{
        		
        		ArrayList<String> list=new ArrayList<String>();
        		
        		list.add("California");
        		list.add("New York");
        		list.add("Dallas");
        		list.add("Sydney");
        		list.add("tokyo");
        		
        		return list;
        		
        	}
        how can i populate the values in my jsp's, html option?
        regards,
        ajos

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by ajos
          Is it possible to populate the option from a ArrayList.
          i have done something like this--->
          Code:
          public ArrayList<String> getSelect()
          	{
          		
          		ArrayList<String> list=new ArrayList<String>();
          		
          		list.add("California");
          		list.add("New York");
          		list.add("Dallas");
          		list.add("Sydney");
          		list.add("tokyo");
          		
          		return list;
          		
          	}
          how can i populate the values in my jsp's, html option?
          regards,
          ajos
          You just use a loop in the JSP

          [CODE=java]for(int i = 0; i < list.size(); i++) {
          %>
          <OPTION value ="<%=list.get(i )%>"><%=list.ge t(i)%> </OPTION>
          <%
          }
          %>
          [/CODE]

          Comment

          • ajos
            Contributor
            • Aug 2007
            • 283

            #6
            Originally posted by r035198x
            You just use a loop in the JSP

            [CODE=java]for(int i = 0; i < list.size(); i++) {
            %>
            <OPTION value ="<%=list.get(i )%>"><%=list.ge t(i)%> </OPTION>
            <%
            }
            %>
            [/CODE]
            but my arraylist that i've created is in my class,so how can i write this directly in my jsp page.im getting list is not resolved to a type.
            regards,
            ajos

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by ajos
              but my arraylist that i've created is in my class,so how can i write this directly in my jsp page.im getting list is not resolved to a type.
              regards,
              ajos
              Of course you'll have to pass that list to the JSP somehow.
              Can you access that class from the JSP? Just make the getSelect method static and then it's just a simple
              [CODE=java]ArrayList<list> list = ClassName.getSe lect();[/CODE]

              Comment

              • ajos
                Contributor
                • Aug 2007
                • 283

                #8
                Originally posted by r035198x
                Of course you'll have to pass that list to the JSP somehow.
                Can you access that class from the JSP? Just make the getSelect method static and then it's just a simple
                [CODE=java]ArrayList<list> list = ClassName.getSe lect();[/CODE]
                [HTML]
                <% ArrayList<Strin g> list = SelectFactory.g etSelect(); %>
                <%for(int i=0; i < list.size(); i++); %>
                <%{ %>
                <OPTION value ="<%=list.get(i )%>"><%=list.ge t(i)%> </OPTION>
                //its saying i cannot be resolved
                <%} %>

                [/HTML]

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by ajos
                  [HTML]
                  <% ArrayList<Strin g> list = SelectFactory.g etSelect(); %>
                  <%for(int i=0; i < list.size(); i++); %>
                  <%{ %>
                  <OPTION value ="<%=list.get(i )%>"><%=list.ge t(i)%> </OPTION>
                  //its saying i cannot be resolved
                  <%} %>

                  [/HTML]
                  You did not copy properly the code I posted above.
                  That means you are not trying to understand what I'm posting. That is not very good at all ...

                  Comment

                  • ajos
                    Contributor
                    • Aug 2007
                    • 283

                    #10
                    Originally posted by r035198x
                    You did not copy properly the code I posted above.
                    That means you are not trying to understand what I'm posting. That is not very good at all ...
                    Im sorry...i think im missing the point here. my arraylist is returning the type as string thats why i did it
                    ArrayList<Strin g>....
                    the rest of the part i followed your advice.

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #11
                      Originally posted by ajos
                      Im sorry...i think im missing the point here. my arraylist is returning the type as string thats why i did it
                      ArrayList<Strin g>....
                      the rest of the part i followed your advice.
                      That part is fine. You corrected my mistake fine. It's the for loop that you failed to copy correctly

                      Comment

                      • ajos
                        Contributor
                        • Aug 2007
                        • 283

                        #12
                        Originally posted by r035198x
                        That part is fine. You corrected my mistake fine. It's the for loop that you failed to copy correctly
                        ya i gave it a extra ; there.but still i get the same error i not resolved to a type.

                        Code:
                        An error occurred at line: 60 in the jsp file: /pages/admin/addbdgt.jsp
                        i cannot be resolved
                        57:   <% ArrayList<String> list = SelectFactory.getSelect(); %>
                        58: <%for(int i=0; i < list.size(); i++) %>
                        59: <%{ %>
                        60: <OPTION value ="<%=list.get(i)%>"> <%=list.get(i)%> </OPTION>
                        61: <%} %>
                        62:   
                        63:   <tr>

                        Comment

                        • ajos
                          Contributor
                          • Aug 2007
                          • 283

                          #13
                          is it possible with <html:optionCol lection> coz i want to populate the values in it?
                          regards,
                          ajos

                          Comment

                          • r035198x
                            MVP
                            • Sep 2006
                            • 13225

                            #14
                            What happens when you have the code like this

                            [CODE=java]<%
                            ArrayList<Strin g> list = SelectFactory.g etSelect();
                            for(int i=0; i < list.size(); i++) {

                            %>
                            <OPTION value ="<%=list.get(i )%>"> <%=list.get(i)% >
                            <%
                            }
                            %>
                            [/CODE]

                            Comment

                            • ajos
                              Contributor
                              • Aug 2007
                              • 283

                              #15
                              Originally posted by r035198x
                              What happens when you have the code like this

                              [CODE=java]<%
                              ArrayList<Strin g> list = SelectFactory.g etSelect();
                              for(int i=0; i < list.size(); i++) {

                              %>
                              <OPTION value ="<%=list.get(i )%>"> <%=list.get(i)% >
                              <%
                              }
                              %>
                              [/CODE]
                              due to some strange reason the values are getting printed.but not on my <option> tag but on my jsp display.why is it not getting displayed on the select tag?

                              Comment

                              Working...