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
public String getProjectNameList(int index) {
StringBuffer stringBuffer = new StringBuffer();
String newProjectName;
for (int i = 0; i < vectorForProjectName.size(
String projectAbbrevation = "";
String pname = vectorForProjectName.eleme
System.out.println("pname[
for (int a = 0; a < vectorFreezeProject.size()
String vFProject = vectorFreezeProject.elemen
System.out.println("vFProj
if (vectorFreezeProject.index
System.out.println("It contains");
stringBuffer.append(
"<option PROOJECT_ABBREVATION=\""
+ projectAbbrevation
+ "\" value=\""
+ pname
+ "\">"
+ pname
+ "</option>\n");
}
else {
try {
projectAbbrevation =
vectorForProjectAbbrevatio
} catch (ArrayIndexOutOfBoundsExce
projectAbbrevation = "DEFAULT";
}
newProjectName = vectorForProjectName.eleme
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?