Solved

Need two option values from a single method.

Posted on 2006-10-19
4
223 Views
Last Modified: 2010-03-31
Hello All,
I'm trying to get two option values in single method through if else condition. i.e. if one condition is satisfied, then show the first option values or else the second option values needs to be shown. But when I try the return the string, it returns me with the both options appended.

i.e. I have one vector named Project Name, from which I generate freezed Project name and print those values in the dropdown list. Then I want to create another option which would generate unfreezed project i.e. Project Name-Freeze Project = UnFreeze Project.

Here is the code:

public String getProjectNameList(int index) {
    StringBuffer stringBuffer = new StringBuffer();
    String newProjectName;
    // if (vectorFreezeProject != null) {
    for (int i = 0; i < vectorForProjectName.size(); i++) {
        String projectAbbrevation = "";
        String pname = vectorForProjectName.elementAt(i).toString().trim();
        for (int a = 0; a < vectorFreezeProject.size(); a++) {
            String vFProject = vectorFreezeProject.elementAt(a).toString().trim();
            if (vectorFreezeProject.indexOf(pname) != -1) {
                stringBuffer.append(
                    "<option PROOJECT_ABBREVATION=\""
                        + projectAbbrevation
                        + "\" value=\""
                        + pname
                        + "\">"
                        + pname
                        + "</option>\n");
 
            } else {
 
                try {
                    projectAbbrevation =
                        this.vectorForProjectAbbrevation.elementAt(i).toString().trim();
                } catch (ArrayIndexOutOfBoundsException aioobe) {
                    projectAbbrevation = "DEFAULT";
                }
                newProjectName = this.vectorForProjectName.elementAt(i).toString();
                // newProjectName = this.vectorForTrackerDate.elementAt(index).toString().trim();
 
                stringBuffer.append(
                    "<option PROOJECT_ABBREVATION=\""
                        + projectAbbrevation
                        + "\" value=\""
                        + newProjectName
                        + "\">"
                        + newProjectName
                        + "</option>\n");
 
                System.out.println("print:::: " + newProjectName);
 
            }
 
            break;
        }
 
    }
    return stringBuffer.toString();
}

What is the best way of doing it? Is there any other solution?

Please help.

Thnx & Rgds,

P.S. I want to display this option values, which are dynamically generated through java, in JSP
0
Comment
Question by:jas99
  • 2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:Venabili
ID: 17764947
OK... What is the exact problem because you lost me somewhere in the explanations :)And what you need this "break;" for? BEcause from what I see this means that 'a' will be only 0 and then you will get out of the cycle.

So what I miss?
0
 

Author Comment

by:jas99
ID: 17771558
Hi,
Sorry. I have posted a right code (see below). O.k. I will explain it again.

Just go thru the code comments for better understanding.

........................................................................................................................................

/**
* This method return the unfreeze project name drop down and freeze project name drop down only if there were any previous entires
* otherwise it should remove the freeze project name from the drop down list and show me the unfreeze project name.
* @return String
* @param selectedIndex int
*/
public String getProjectNameList(int index) {
    StringBuffer stringBuffer = new StringBuffer();
    String newProjectName;
    for (int i = 0; i < vectorForProjectName.size(); i++) {
        String projectAbbrevation = "";
        String pname = vectorForProjectName.elementAt(i).toString().trim();
          for (int a = 0; a < vectorFreezeProject.size(); a++) {
            String vFProject = vectorFreezeProject.elementAt(a).toString().trim();
            if (vectorFreezeProject.indexOf(pname) != -1) {
                stringBuffer.append(
                    "<option PROOJECT_ABBREVATION=\""
                        + projectAbbrevation
                        + "\" value=\""
                        + pname
                        + "\">"
                        + pname
                        + "</option>\n");        
 
            }
            else {

                try {
                    projectAbbrevation =
                        this.vectorForProjectAbbrevation.elementAt(i).toString().trim();
                } catch (ArrayIndexOutOfBoundsException aioobe) {
                    projectAbbrevation = "DEFAULT";
                }
                newProjectName = this.vectorForProjectName.elementAt(i).toString();
                     stringBuffer.append(
                    "<option PROOJECT_ABBREVATION=\""
                        + projectAbbrevation
                        + "\" value=\""
                        + newProjectName
                        + "\">"
                        + newProjectName
                        + "</option>\n")                       
            }
           
   break;
        }

    }
    return stringBuffer.toString();
      // some how this is displaying options with both the values.
}
0
 
LVL 20

Accepted Solution

by:
Venabili earned 250 total points
ID: 17773295
Something is wrong/unexpected with the parameters you give. Let's try this code and let me know what it prints:
 public String getProjectNameList(int index) {
        StringBuffer stringBuffer = new StringBuffer();
        String newProjectName;
            for (int i = 0; i < vectorForProjectName.size(); i++) {
                String projectAbbrevation = "";
                String pname = vectorForProjectName.elementAt(i).toString().trim();
                System.out.println("pname[i]=" + pname);
                for (int a = 0; a < vectorFreezeProject.size(); a++) {
                    String vFProject = vectorFreezeProject.elementAt(a).toString().trim();
                    System.out.println("vFProject[a]=" + vFProject);
                    if (vectorFreezeProject.indexOf(pname) != -1) {
                        System.out.println("It contains");
                        stringBuffer.append(
                        "<option PROOJECT_ABBREVATION=\""
                        + projectAbbrevation
                        + "\" value=\""
                        + pname
                        + "\">"
                        + pname
                        + "</option>\n");        
                   
                    }
                    else {
                   
                        try {
                            projectAbbrevation =
                            vectorForProjectAbbrevation.elementAt(i).toString().trim();
                        } catch (ArrayIndexOutOfBoundsException aioobe) {
                            projectAbbrevation = "DEFAULT";
                        }
                        newProjectName = vectorForProjectName.elementAt(i).toString();
                        stringBuffer.append(
                        "<option PROOJECT_ABBREVATION=\""
                        + projectAbbrevation
                        + "\" value=\""
                        + newProjectName
                        + "\">"
                        + newProjectName
                        + "</option>\n");
                        System.out.println("It does not contain");                    
                    }
                   
                    break;
                }
           
            }
        return stringBuffer.toString();
        // some how this is displaying options with both the values.
    }

Also:

This method receives index as a parameter which is used nowhere? Had you missed something?
0
 

Author Comment

by:jas99
ID: 17817369
Hi,
This got solved thru other method, so i didn't check this up.... Anyways thanks for your help.

Regards,
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now