• Post Reply Bookmark Topic Watch Topic
  • New Topic

String array generation with distinct values

 
Amitkumar Fulambarkar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to create distinct value for "id" attribute of span to make the following code working. Requirement is, when I click on "docTitle" it will call showHide function and will show docDescription in the same TD adding a span. If I again click on docTitle, docDescription will hide. The below code comes under a loop which retreives the data from Enumeration. To make the function call working I should have distinct "id" value for SPAN.I used docTitle for span id by manipulating this value to remove the special character and white spaces, since it is not allowed for span id value.

when I get same values for docTitle from Enumeration, the function showHide fails. Here is the code...

for (Enumeration epm = prodManuals.elements(); epm.hasMoreElements(); ) {
DocumentItem docItem = (DocumentItem)(epm.nextElement());
String docDescription = docItem.getDocDescription();
String docTitle = docItem.getTitle();

//Code to remove special chars and white spaces- START
StringBuffer spID1 = new StringBuffer();
char [] str = docTitle.toCharArray();
for( int s=0; s< str.length; s++ )
{
if ( (str[s]>='A' && str[s]<='z' ) )
spID1.append( str[s] );
}
spID= spID1.toString();
out.println("spID =" + spID);
//Code to remove special chars and white spaces- END
.
.
.
.

<td width="70%"><a style="cursor:hand",call showHide function on onclick event, title="Click to see the description"><font size="1" face="Verdana, sans-serif" color="#0000ff"><%=docTitle%></font></a>
<span id='<%=spID %>' style="display:none"><table bgcolor="" width=""><tr ><td><%= docDescription %></td></tr></table></span>
</td>
.
.
.
}
Can you please suggest how can I manupulate the docTitle value to be distinct or any other way to create string array with different values?

Please help.

[ September 17, 2008: Message edited by: Amitkumar Fulambarkar ]

[ September 17, 2008: Message edited by: Amitkumar Fulambarkar ]
[ September 17, 2008: Message edited by: Amitkumar Fulambarkar ]
 
Anuraag Godika
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keep a running count and add it to the docTitle value by appending with a hyphen.

docTitle += "-" + count++;

This ensures that all Span IDs are unique, and as an added bonus, it will let you know the position of the span that was clicked - in case you are interested in that.
 
Amitkumar Fulambarkar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick reply Anuraag!!

As I mentioned, the span id doesn't allow any numeric character in its value, thats why I have used the code to remove numeric values and special characters. I can not used count.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Numeric digits are allowed in id values.
 
Amitkumar Fulambarkar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the whole code, change the value for String docTitle = "Do It Right"; to any including number like "11Do It Right" and please check if works. I tried this on tomcat.


Please check the code for calling showHide function. you need to right it. It doesn't allow me to post if I right the onclick function correctly.
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amitkumar Fulambarkar welcome to Javaranch
I think this question does not relate to JSP, in particular. Please CarefullyChooseOneForum . Posting a question in its proper place yields more useful responses.
 
Amitkumar Fulambarkar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amit,
This was my first post on javaranch, so probably I was not aware of these thing. Anyways, I found the solution and I would like to share it with you all ranchers.

I wrote a function which convert the number into words like "1" will convert to "one". I implemented a counter for the elements in the Enumeration and converted the counter value into words using the function I written. The same word I used for span ID.

This fixed my requirement.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!