• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to remove the span from outputText in jsf1.2

 
Navdeep Singh kanwal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a situation where i need to pic some html elements from db and attach them in html view.
But when i use
<h:outputText value="#{bean.var}"/>
it give me something like
<span id="xyz"> Abc Text</span>

I can not bear this span over my output because i have some elements in my output which will not work in span.

Can anybody suggest me the way to get out of the this span element.

Thanks
Navdeep Singh kanwal
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Nadeep!

What can you be outputting via outputText that can't tolerate being placed in a span?

If you're attempting to barf out raw HTML from an outputText, that's not a good idea to begin with. And if you are trying to barf out syntactically incomplete HTML - for example, only an element start or end tag - that's just not something you should be doing at all. It violates basic XML rules.

For the most part, not only is it not a good idea to output raw HTML from a JSF outputText, but I also don't recommend putting raw HTML in any form at all into JSF View Definitions. JSF can usually generate all the HTML that's needed.

In some cases, there's no choice, because you need to display or even edit bulk HTML that comes from somewhere else, such as boilerplate HTML stored in a database. However, stuff like that should be syntactically complete, if at all possible. That is, every start element should be paired with a corresponding end element, and elements should nest, not overlap.

For cases where syntactically complete text cannot be used, forget outputText altogether and use the f:verbatim tag. Also, note that raw EL can be used in the view definition, as long as you obey the syntactical rules. Although there are reasons both historical and having to do with good programming discipline for using outputText and its relatives, there are cases where an exception can be made.

One of the reasons why outputText generates a span is because it supports style and styleClass attributes, and that's where they'd be placed. In the span opening tag.

And if your intent is to produce non-HTML output such as an Excel spreadsheet or PDF, that should be done by a servlet, not by JSF code.
 
Navdeep Singh kanwal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Tim,

I agree with you that in JSF i need not to do this way, But the thing is i have some meta tags which are not hard coded and will be changed with time.
Can you suggest me the the best way.

Thanks
Navdeep Singh Kanwal
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
META tags are an interesting case. They're not really HTML as such.

JSF2 added an h:head element, I think. Before then, that was one of the areas where my "no raw HTML" rule couldn't be applied. And I still have JSF view definitions with raw HTML head and title tags.

I think this will do the trick:

 
Navdeep Singh kanwal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Tim for your help.

i have solved my problem this way

<c:forEach items="${bean.list}" var="item">
<meta name="${item.name}" content="${item.content}" />
</c:forEach>



Thanks
Navdeep Singh Kanwal
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to try the "ui:repeat" Facelets tags instead.

JSTL and JSF don't work that well together as a rule, even though in this particular case you got what you wanted. Since you are, in fact repeating a UI element (or actually iterating a set of them), not actually coding a logic loop (which in MVC terms is a no-no for the View), the Facelets tag is technically more appropriate.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!