Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I write jsp lib that removes html tag

 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all
I have simple tag lib's that added attributes to html tags for example:

Will add to the html tag the " readonly=\"readonly\"" based on some conditions in the server.
But one of the conditions I need to remove the html "input" tag from the display.
Can I some how do it ? With the same jsp tag location in the html file?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To hide an element form the display, you need to use CSS.
 
Matt W Robinson
Greenhorn
Posts: 12
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try changing your custom tag to insert style="display: none; visibility: hidden" in that case.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With a display of none, visibility is redundant.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the field contains sensitive data, then a client side technique might not be enough. You'll want to remove the field up on the server so that the user can't view the HTML source to see the value of this field.

For instance if a field such as payRate is only supposed to be visible to managers you can hide it with JSTL's <c:if .. /> tag.

 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply but i wander if i could do it with only 1 tag
and avoiding if else's in the html
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <c:if ../> tag has no else.

Also, if you look at the HTML source generated from your JSP, you'll see that the <c:if tag doesn't appear there. JSTL tags (like all JSP code) is interpreted on the server. Your HTML and Javascript code is the output from it.

To directly answer your question, yes, you could create a custom tag or a tagfile that, conditionally prints an <input .../> tag to the page.

Out of curiosity, what is the benefit to getting this down to one tag?
 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
simple, the people that will work on the html pages are "html" oriented
With no knowledge in server side scripts so it will be lot easer if they have
only one tag they need to put and the logic will be in the server side
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A tag file would be perfect for that.
 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what do you mean by tag file ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using JSP 2.0 and don't know what a tag file is, it's definitely time to grab a copy of the JSP Specification and start reading!
 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi and thanks for the reply, i was reading this:
http://www.oracle.com/technology/pub/articles/cioroianu_tagfiles.html
but i could find there something that i need for me .
can you point me to tutorial or show me simple example
Thanks allot
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below are few links I found over the net.

Custom Tags in JSP Pages
Easy Custom Tags with Tag Files

Hope these would help you in writing a tag file.
 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello and thanks for the reply
As I was reading the articles I saw that I can control the tags only if I create new tag
I cant control the "Original" html tag from custom tag .
This is not what I need here I need to control the option of if to render the "Original" html tag
from custom tag I made . or did I not looking in the right way �
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Meir Yan:
As I was reading the articles I saw that I can control the tags only if I create new tag. I cant control the "Original" html tag from custom tag .
This is not what I need here I need to control the option of if to render the "Original" html tag from custom tag I made . or did I not looking in the right way


Obviously, if you think you can add new or modify existing attributes of the original tag, thats not the purpose of the custom tag. We recommended custom tags, so you can write one for your desired functionality and hide your HTML tag rendering inside that tag file. That was our whole point. This way the HTML author would be able to use your tag less painfully.
 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes , I understand this put I still need to find if I can do what I need to do .
If I just can't do it its also an answer.
By the way I have something like 60 html pages I don�t think im going to start to replace the html tags with
New custom tags

Thanks
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Meir Yan:
Yes , I understand this put I still need to find if I can do what I need to do.


To me this something you need to do.

Originally posted by Meir Yan:
By the way I have something like 60 html pages I don�t think im going to start to replace the html tags with New custom tags


If you don't want to replace it in all your 60 pages, just use this tag where ever you need this kind of functionality.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing in JSP will allow you to 'take control of an HTML tag'.

To JSP your HTML is nothing more than textual output.
Since the JSP writes the HTML, you can use it to conditionally write your HTML and to alter the way in which it is written.

Once written, HTML is interpreted in the browser, on the clients machine, and no more interaction with the original JSP code that wrote it is possible.
As Bear suggested, you can alter the state of HTML tags with CSS and Javascript but, as I've mentioned, by the time your javascript is interpreted, the HTML will already have made it to the browser and it will be possible for the end user to view its source. If that doesn't matter, then you should investigate a client side solution. If the data is sensitive and absolutely must be hidden from the user, then you will need to write something on the server side that prevents the field from ever being sent to the browser.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic