Solved

Need two option values from a single method.

Posted on 2006-10-19
4
237 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
micro services vs rest web services 16 107
eclipse package explorer vs project explorer view 2 135
Java Options in Zimbra Server 2 54
Java exception bubble up 2 18
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

831 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