Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Using html properties in custom tag in jsp

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

We need to create a jsp form using custom tags and to write field display logic based on some condition in tld descriptor file. I have used simpletagsupport class but that is not useful in this case. Searched in web but did not find much relevant details about it. Could anybody help please.
 
Saloon Keeper
Posts: 6380
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you have so far, and what is still missing?
 
Anjana Kumari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I started with basic example, have created a jsp with an string attribute,tld.xml(define that atteibute here)  and a tld file that extends tagsupport class,setter and getter method and basic implemetation of dotag method to print one string. This worked fine.

Now when i try to modified  this by adding html property in custom tag,its prompting error,also not sure how the tld java file will return some flag based on that to display/hide field. Not sure whether bodysupport class need to extend or dynamic attribute to be use,havenot found any examples of such online..
 
Marshal
Posts: 67388
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show your code and the complete error that you are getting. Be sure to use code tags (see usecodetags) to preserve the formatting of both.
 
Anjana Kumari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please find following  code snippet, basically i need to conditionally set the visibility of input text field using custom tag. Able to  print simple string messages though.
 
Anjana Kumari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Need to und how to use dynamic attribute for this as could not find much details or there is any other way using custom tags for this
 
Marshal
Posts: 25436
65
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately all you have shown us so far is an example of code which fails to do what you want. But you haven't said what that is.

It seems to me that you might possibly want to use the type="hidden" attribute on one of your <input> elements? It's very easy to do that in plain JSP, I certainly wouldn't try to write a custom tag just for that. If I've guessed wrong then perhaps you could show us an example for the HTML you want to produce? It's a lot easier to write code which produces HTML if you know what HTML you want to produce.
 
Anjana Kumari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thaks for responsing. As i mention i am still trying to figure out how to implement this functionality using custom tags/dynamic attribute- to conditionally display/hide a simple text field. So if you can guide to some specific references would be helpful.

Reason why we dont want to use html hidden property or javasccript or c chose tags to avoid lot of other than ui  code in jsp.
 
Tim Moores
Saloon Keeper
Posts: 6380
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Reason why we dont want to use html hidden property or javasccript or c chose tags to avoid lot of other than ui  code in jsp.


How is using a custom JSP tag any different than using JSTL in a JSP? You have to implement this somehow; if the easiest way involves JavaScript, what's wrong with that? Without knowing precisely what you want to achieve, jQuery is probably what I would use to show/hide DOM elements dynamically.

But yes, we need to see the HTML that you want to generate in order to advise how getting there might best be achieved.
 
Anjana Kumari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the JSP code where i have created dropdown using custom tag. Now i need to hide this dropdown based on some condition , need to understand what to be mention in the tld file that generated html.

JSP: please ignore the scriptlet , its for testing purpose only.




TLD:




Taghandler:

 
Rancher
Posts: 4548
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say "i need to hide this dropdown based on some condition", do you mean having the TagHandler not add the <select> element at all, or do you mean hiding the element when the user does something on that page in their browser?

Because the first part would simply be if <condition> then do nothing in the handler...that latter would be Javascript (or preferably some framework) and has nothing to do with JSP  tags at all.
 
Anjana Kumari
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dave, its clear now.

Am able to display 1 drop down using dynamic attribute in jsp  and the other handling.

However when i tried to add multiple drop downs and input text fields, its giving error like attributes need to be define which i already did in tld file. Could help what need to be change please?

Error in jsp page: missing optionsList attribute highlighted in country and race drop down

JSP code:




TLD file :

 
Tim Moores
Saloon Keeper
Posts: 6380
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The TLD should define only optionsList, not countryList or raceList. And then you would use optionsList for all 3 dropdowns.
 
Replace the word "snake" with "danger noodle" in all tiny ads.
ScroogeXHTML 8.7 - RTF to HTML5 and XHTML converter
https://coderanch.com/t/730700/ScroogeXHTML-RTF-HTML-XHTML-converter
    Bookmark Topic Watch Topic
  • New Topic