This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSP and the fly likes How can I write jsp lib that removes html tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "How can I write jsp lib that removes html tag" Watch "How can I write jsp lib that removes html tag" New topic
Author

How can I write jsp lib that removes html tag

Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
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

Joined: Jan 10, 2002
Posts: 61316
    
  66

To hide an element form the display, you need to use CSS.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Matt W Robinson
Greenhorn

Joined: Dec 13, 2007
Posts: 12

Try changing your custom tag to insert style="display: none; visibility: hidden" in that case.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61316
    
  66

With a display of none, visibility is redundant.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.



Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Apr 27, 2006
Posts: 597
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

Joined: Dec 11, 2004
Posts: 13410

A tag file would be perfect for that.
Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
what do you mean by tag file ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61316
    
  66

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

Joined: Apr 27, 2006
Posts: 597
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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Apr 27, 2006
Posts: 597
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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Apr 27, 2006
Posts: 597
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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Dec 11, 2004
Posts: 13410

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.
 
GeeCON Prague 2014
 
subject: How can I write jsp lib that removes html tag