aspose file tools*
The moose likes JSP and the fly likes <textarea> </textarea> nested inside a custom tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "<textarea> </textarea> nested inside a custom tag" Watch "<textarea> </textarea> nested inside a custom tag" New topic
Author

<textarea> </textarea> nested inside a custom tag

Roshan Khandelwal
Ranch Hand

Joined: Apr 16, 2009
Posts: 35
I have made a custom tag... which has no attributes and a body.. Now within this custom tag i need to insert a textarea box(as its body) .. in which i will be pasting my xml as input.
Upon button click this is passed on to a servlet.. which then sends it to a java code for further processing...

However How do i access the value of the textarea (contents) indented inside my custom tag inside my servlet...

JSP code :



Should i give my tag a name attribute for which i generate a setter and getter in my java file.
I am pretty clueless..
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
I don't understand you. What do you want to access, the name, cols and rows or the value that the user introduces in your text area? In the first case invoke the body and call the getters of that properties, in the second case use the normal request parameters (as I suppose this is part of a form)
Roshan Khandelwal
Ranch Hand

Joined: Apr 16, 2009
Posts: 35
@Albareto : had you read my problem a bit carefully... you would have understood that i have to read the value that the user enters inside the textarea..
However the larger question is how can i read this value which would be an xml and yet pass it as an xml and not a set of values...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41906
    
  63
What are you getting if you use request.getParameter("input")?

The <readxml:readXmlData> stuff should only be in the JSP page, not in the HTML - that's how JSP tags work.


Ping & DNS - my free Android networking tools app
Roshan Khandelwal
Ranch Hand

Joined: Apr 16, 2009
Posts: 35
Think of it this way...




If now i render this page having this code.... and i say inside my tag.java




Then it displays the garbage code followed by the textarea.. 80 by 20 in size..

However now i inout a value inside the textarea.. and i now want to read the body again.. How do i do that

right now thid code says.. on first rendering :
this is being evaluated
this is the body :
<textarea name="input" cols="80" rows="20">
</textarea>
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41906
    
  63
It sounds as if the rendering process works perfectly.

What do you mean by "i now want to read the body again"? Once the form gets submitted, you can use the getParameter call I mentioned before. If that's not what you want to do, then tell us *in detail* what it is that you do want to achieve.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Roshan Khandelwal wrote:@Albareto : had you read my problem a bit carefully... you would have understood that i have to read the value that the user enters inside the textarea..


Then, as I told you before, use the request.getParameter, you are trying to read the value that the user enters in the tag which is not possible, take care that when the jsp is read and parsed to html you don't have the value you want. The value is submited with the form so you have to read it in the Servlet, not in the Tag.
Roshan Khandelwal
Ranch Hand

Joined: Apr 16, 2009
Posts: 35
I have stumbled into something very puzzling :

see I have a page as described in my previous posts... i.e a textarea inside a custom tag.. and all
so on forst rendering the textarea shows up and i put in my xml input ...


I click on Post request and in the servlet use the


where input is the name of my textarea...

and then i show it on ajsp page.. which shows the output as :

<?xml version="1.0" ?>
- <testApp>
<version>1.0</version>
</testApp>



Now i change the xml a bit:




and viola... the output is :

1.0


Only the value and no tags...

WHY??? does this happen.. I have tried with several combinations , but this problem occurs only with Header and Body...
ANY ONE knows why this happens..
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41906
    
  63
It's up to the browser to decide what to do with XML that pretends to be HTML. If you want XML to be faithfully reproduced in an HTML page, then you need to replace all potentially problematic characters (like <, > and &) by their respective HTML entities (&lt;, &gt; and &amp;).
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
You can also use

Roshan Khandelwal
Ranch Hand

Joined: Apr 16, 2009
Posts: 35
@albaerto : Could you be a little more explicit.... i do realize that this is a custom tag...
Should i write this inside my form element...
Could you please give me an example..

@Ulf : I know that trick... But i need to paste the xml output as generated and not after manipulating it..
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Roshan Khandelwal wrote:@albaerto : Could you be a little more explicit.... i do realize that this is a custom tag...
Should i write this inside my form element...
Could you please give me an example..

@Ulf : I know that trick... But i need to paste the xml output as generated and not after manipulating it..


Sure man ;)

It's not a custom tag but a standard one, take a look at the JSTL API http://java.sun.com/products/jsp/jstl/reference/api/index.html you have to include them in your application have a look also at this tutorial: http://java.sun.com/javaee/5/docs/tutorial/doc/bnakc.html

c: out outputs the value you recieve from the request (in fact it checks pageContext, request and session in that order to get the value) and scapeXml to false make it not to evaluate any xml tag that it finds. If I am correct it should work with ${input} but now I am doubting if it's ${param.input} as you are passing a parameter... anyway you can test it :P

So in your case if you have jsp1.jsp with the code you give and you pass through the request the param called input in the next jsp you can do the c: out in jsp2.jsp and the text should appear in the generated html.

Hope this heleped you ;)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61239
    
  66

Roshan Khandelwal wrote:@Ulf : I know that trick... But i need to paste the xml output as generated and not after manipulating it..

Well, you can't. If you just plop the XML in with the HTML, the browser will try to render it as HTML and will ignore any invalid tags. The special character must be encoded whether you do it yourself, or let <c:out> do it for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: <textarea> </textarea> nested inside a custom tag