• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

JSP Newbie - Dynamic ComboBox

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm new to JSP, although I do have some backend Java experience. The goal use a custom anchor tag, and then the JSP will automatically build a combo box using the values. Users can then select from the combo box and skip down to the respective anchor. Everything must be done on the client side using JSP and javascript. I'm assuming that I would create two custom JSP tags, a combobox and an anchor tag. The custom combobox would take the values from the 1-n number of anchor tags and build the list when the page loads. The custom anchor would replace the html code:
<a name="anchor1">
Therefore I would create a custom tag, e.g., AnchorTag.java, and place it on the page as follows to replace the above html code:
<myTags:anchor value="anchor1>"
Am I approaching this in the correct manner? How do I get the combobox tag to communicate with the anchor tag? Where does JavaScript fit into all this? Any help would be greatly appreciated, thanks,
Sid
 
Author
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, the first thing to note is that jsp is NOT client side - it is a server side technology. Except for javascript, whatever you send to the browser is out of your hands once it has left the serve.r
secondly, it would help enormously if you described your problem in specific terms rather than generic as I am not entirely sure of what you mean. If i am right, what you want to do is entirely possible but the result would be static and i cnat see why you would need to use javascrip tfor it
 
Sid Wunn
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply,
This is my problem. I've been tasked to create a template jsp page that other developers can use. The functionality that I'm working on presently is to dynamically create a combo box comprised of links to anchors in the page. The names located in the combo box will be comprised using the "name" attribute of the <a> tag. These anchors may appear on a developer's JSP page in a number of ways, including:
1) harcoding in specific places.
2) when using a custom jsp "Heading" tag that writes an html anchor
3) in a conditional loop, for example if 50 records are returned an anchor will be placed every 10 records.

Please let me know if this is enough information, I'm at a loss on how to accomplish it and I'm on a tight deadline.
Thanks,
Sid
 
chanoch wiggers
Author
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am finding it still somewhat difficult to understand what you mean but here goes:
You have a 50 record set which you need to output into a page with a combo box in the top for navigation and regular anchors along the way.
I assume that the outputting of hte records is also part of the dynamism of the page so it would look something like this:
//acquire record set
<record_outputter_tag numrecs="5">
</record_outputter_tag>
in order to make the tag more flexible - you should provide a number of records variable (with perhaps a default value). In this example, you wouldnt need an anchor tag since the anchors would be automatically generated by the tag:
output combobox and generate n/numrecs links where n is the number of records and numrecs is the number of records between anchors
output record 1
output record 2
output record 3
output record 4
output record 5
anchor1
output record 6
output record 7
output record 8
output record 9
output record 10
anchor2
etc etc
I cant see how you could provide hard coded links unless you are controlling atomically the output of the records - in this case, you dont exactly need to write a special tag to output anchors?
Let me see - what alternatives might you want? I can imagine a scenario where you want to control the output of the records - in this case you could provide additional anchors to the combo box by nesting special anchor tags which add themselves to the list of links:
e.g.
<combo_generator>
<output_record no="1"/>
<anchor name="name1"/>
<output_record no="2"/>
<output_record no="3"/>
<output_record no="4"/>
<anchor name="name2"/>
<output_record no="5"/>
<output_record no="6"/>
<output_record no="7"/>
</combo_generator>
Combo generator has a collection which holds the links that should go in the combo box. Each anchor tag adds its name as a link (value #name2 for example) to the collection by calling getParent to get the combo generator and then casting the result to add itself to the collection of links. Each of the tags then also outputs its anchor into the generators output writer.
the combo generator in this case would be responsible for picking up the links only. When the end of the combo generator is reached, it outputs a combo box followed by the records and anchors output by the nested tags.
Finally, hard coded anchors could be added through nested tags too - if you want to be able to pick up HTML anchors in the page automatically, you can either parse the contents of the page for the character sequence that matches a link - or you could require explicit adding of the links by using an <add_anchor name="somename"/> nested tag - such as
<combo_generator>
<add_anchor name="somename" position="4"/>
<add_anchor name="somename2" position="7"/>
<output_record no="1"/>
<anchor name="name1"/>
<output_record no="2"/>
<output_record no="3"/>
<output_record no="4"/>
<anchor name="name2"/>
<output_record no="5"/>
<output_record no="6"/>
<output_record no="7"/>
</combo_generator>
IN the example above I am assuming that somewhere in the page or perhaps within the tag, there is a n anchor that is called somename (and another one called somename2) that need to be added to the combo box. The extra thing I've done is to allow the web developer to specify where in the combo's list of links the link should turn up. This assumes a very good understanding of what is going to end up on the page though.
If none of this is helpful that feel free to write back
 
Sid Wunn
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it was very helpful, thank you!
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just did this, but not with a tag with a utility class.
<select name="link">
<%= Utilities.getComboboxOptions() %>
</select>
this class returns a string that is full of <option></option> stuff. You could also use a tag. Just quicker to use a utility class.
 
Oh. Hi guys! Look at this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic