Help! JSF tag + Html tag problem

I used <f:verbatim> tag around html tags to force the jsf parsing them.But i got:

java.lang.ClassCastException: javax.faces.component.UIViewRoot

at org.apache.myfaces.taglib.core.VerbatimTag.doAfterBody(VerbatimTag.java:76)

at org.apache.jsp.pages.album.main_jsp._jspx_meth_f_verbatim_8(org.apache.jsp.pages.album.main_jsp:2018)

at org.apache.jsp.pages.album.main_jsp._jspx_meth_f_view_0(org.apache.jsp.pages.album.main_jsp:276)

at org.apache.jsp.pages.album.main_jsp._jspService(org.apache.jsp.pages.album.main_jsp:147)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

And my page is :

<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %>

<%@ include file="/pages/common/taglibs.jsp" %>

<html>

<head>

<title>Album Main Page</title>

<link rel="stylesheet" type="text/css" href="<c:url value='/css/common.css'/>" />

<script src="<c:url value='/js/prototype.js'/>" type="text/javascript"></script>

<script src="<c:url value='/js/scriptaculous.js'/>" type="text/javascript"></script>

<script src="<c:url value='/js/ajax.js'/>" type="text/javascript"></script>

</head>

<body class="center">

<f:view>

<jsp:include page="/pages/common/header.jsp"/>

<f:verbatim>

<div class="div1">

<jsp:include page="/pages/common/left.jsp"/>

<div id="main_div" class="div2" style="width:496px;">

<div style="width:466px;height:22px;padding-left:16px;border-bottom: #DBDBDB 1px solid;">

<div style="width:100px;height:22px;float:left;background-color:#EEEEEE;padding-top:4px;" class="font_color1">

My Albums

</div>

<div style="width:100px;height:22px;float:left;margin-left:12px;padding-top:4px;">

</f:verbatim>

<h:commandLink action="" value="Friends Albums" styleClass="link1"/>

<f:verbatim>

</div>

</div>

<div style="width:406px;">

<div>

</f:verbatim>

<t:newspaperTable id="data" newspaperColumns="2" rows="4" value="#{albumHandler.albumModel}" var="album">

<f:facet name="spacer">

<f:verbatim>

</f:verbatim>

</f:facet>

<h:column>

<h:panelGrid columns="1">

<h:commandLink action="#{albumHandler.open}"

style="background-image:url(/album/images/pic_td_bg.jpg);

width:171px;height:109px;padding-top:8px;padding-left:18px;">

<h:graphicImage alt="album-face" url="#{album.face}" style="width:142px;height:93px;border:0px;"/>

<f:param name="album.id" value="#{album.id}"/>

</h:commandLink>

<h:panelGroup>

<h:panelGrid columns="1">

<h:panelGroup>

<f:verbatim> </f:verbatim>

<h:commandLink styleClass="link1" action="#{albumHandler.edit}" target="_blank">

<h:outputText styleClass="font1" value="#{album.name}"/>

<f:param name="album.id" value="#{album.id}"/>

</h:commandLink>

<f:verbatim> </f:verbatim>

<h:outputText styleClass="font2" value="#{album.createtime}"/>

</h:panelGroup>

<h:panelGroup>

<f:verbatim> </f:verbatim>

<h:outputText styleClass="font2" value="#{album.photonum} photoes"/>

</h:panelGroup>

</h:panelGrid>

</h:panelGroup>

</h:panelGrid>

</h:column>

</t:newspaperTable>

<f:verbatim>

</div>

<div style="background-image:url(<c:url value='/images/pic_td_bg.jpg'/>);

width:171px;height:109px;border:0px;

padding-top:22px;margin-left:2px;float:left;">

<span>+

</f:verbatim>

<h:commandLink action="create_album" value="#{message['label_album_new']}"/>

<f:verbatim>

</span>

</div>

<div style="width:406px;height:82px;padding-top:20px;">

</f:verbatim>

<h:commandButton action="all_album" image="/images/all_button.gif"/>

<f:verbatim>

</div>

</div>

<div style="width:466px;border-top:#DBDBDB 1px solid;">

</f:verbatim>

<t:dataScroller id="scroll_1"

for="data"

fastStep="10"

pageCountVar="pageCount"

pageIndexVar="pageIndex"

styleClass="scroller"

paginator="true"

paginatorMaxPages="9"

paginatorTableClass="paginator"

paginatorActiveColumnStyle="font-weight:bold;"

>

<f:facet name="first" >

<t:graphicImage url="/images/arrow-first.gif" border="1" />

</f:facet>

<f:facet name="last">

<t:graphicImage url="/images/arrow-last.gif" border="1" />

</f:facet>

<f:facet name="previous">

<t:graphicImage url="/images/arrow-previous.gif" border="1" />

</f:facet>

<f:facet name="next">

<t:graphicImage url="/images/arrow-next.gif" border="1" />

</f:facet>

<f:facet name="fastforward">

<t:graphicImage url="/images/arrow-ff.gif" border="1" />

</f:facet>

<f:facet name="fastrewind">

<t:graphicImage url="/images/arrow-fr.gif" border="1" />

</f:facet>

</t:dataScroller>

<f:verbatim>

</div>

</div>

<jsp:include page="/pages/common/right.jsp"/>

</div>

</f:verbatim>

<jsp:include page="/pages/common/footer.jsp"/>

</f:view>

</body>

</html>

Please help me out and thank you(r) very much!!!!

[6134 byte] By [spud_webbera] at [2007-10-2 14:26:24]
# 1

1) The problem is probably in your jsp:include files. When using a jsp:include within the f:view tags, you must include f:subview in the included file (or around the jsp:include tag).

2) In the include file, you cannot have any HTML. All HTML tags must be wrapped in f:verbatim tags.

3) Within your main f:view tags however, it is not necessary to wrap everything in f:verbatim tags (it's not bad either). Just HTML that appears as children to other JSF components (i.e. t:newspaperTable).

Here's an example of each of those things:

<body class="center">

<f:view>

<f:subview id="headerInclude">

<jsp:include page="/pages/common/header.jsp"/>

</f:subview>

<div class="div1">

<f:subview id="leftInclude">

<jsp:include page="/pages/common/left.jsp"/>

</f:subview>

<div id="main_div" class="div2" style="width:496px;">

<div style="width:466px;height:22px;padding-left:16px;border-bottom: #DBDBDB 1px solid;">

<div style="width:100px;height:22px;float:left;background-color:#EEEEEE;padding-top:4px;" class="font_color1">

My Albums

</div>

<div style="width:100px;height:22px;float:left;margin-left:12px;padding-top:4px;">

blah blah

<t:newspaperTable id="data" newspaperColumns="2" rows="4" value="#{albumHandler.albumModel}" var="album">

<f:facet name="spacer">

<f:verbatim>

<P>I could have HTML tags in here!</P>

</f:verbatim>

</f:facet>

<h:column>

<h:panelGrid columns="1">

<h:commandLink action="#{albumHandler.open}"

style="background-image:url(/album/images/pic_td_bg.jpg);

width:171px;height:109px;padding-top:8px;padding-left:18px;">

<h:graphicImage alt="album-face" url="#{album.face}" style="width:142px;height:93px;border:0px;"/>

<f:param name="album.id" value="#{album.id}"/>

</h:commandLink>

<h:panelGroup>

<h:panelGrid columns="1">

<h:panelGroup>

<f:verbatim></f:verbatim>

<h:commandLink styleClass="link1" action="#{albumHandler.edit}" target="_blank">

<h:outputText styleClass="font1" value="#{album.name}"/>

<f:param name="album.id" value="#{album.id}"/>

</h:commandLink>

<f:verbatim></f:verbatim>

<h:outputText styleClass="font2" value="#{album.createtime}"/>

</h:panelGroup>

<h:panelGroup>

<f:verbatim></f:verbatim>

<h:outputText styleClass="font2" value="#{album.photonum} photoes"/>

</h:panelGroup>

</h:panelGrid>

</h:panelGroup>

</h:panelGrid>

</h:column>

</t:newspaperTable>

Does that help a bit? Sorry about the poor formatting, you should use the code tags around any example code (in the future).

CowKing

IamCowKinga at 2007-7-13 12:46:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thank you , thank you very much, it works now.

Thank you! And i am sorry for the bad format in my question, i am very vexed with the question.

And i want to know where i can find the criterion of the myfaces tags, i do not know it must use <f:subview> in include pages at all.

spud_webbera at 2007-7-13 12:46:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
And there is another question:When i click the next page in the <t:dataScroller> , the <h:commandLink action="create_album" value="#{message['label_album_new']}"/> disappear.
spud_webbera at 2007-7-13 12:46:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

I midified the page code like this:

<f:subview id="option">

<div style="background-image:url(<c:url value='/images/pic_td_bg.jpg'/>);width:171px;height:109px;border:0px;

padding-top:22px;margin-left:2px;float:left;">

+

<h:commandLink action="create_album" value="#{message['label_album_new']}"/>

</div>

<div style="width:406px;height:82px;padding-top:20px;">

<h:commandButton action="all_album" image="/images/all_button.gif"/>

</div>

</f:subview>

and it works , i am very confused now . When and where should i use <f:subview>?

spud_webbera at 2007-7-13 12:46:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Glad that helped!

f:subview should be used when you want to include a page. It just designates a subsection of the main page. Remember though, all HTML tags within a subview MUST have f:verbatim JSF tags wrapping them. Or, you can use h:outputLink with escape="false".

There is only one other time I know of to use subview, and you probably don't need to worry about that. I had to use subview when I configured an error page in my web.xml for my web application. The error page had to have f:subview instead of f:view tags. It's a bit of an oddity. Anyways, I wouldn't worry about this right now.

I'm not actually sure where you can find an official criteria for when to use subview. The TLD docs maybe? I just learned these tricks and criteria along my way. I can tell you though that this subview thing is the same for all JSF implementations (i.e. the SUN JSF RI, MyFaces, Oracle ADF, etc...).

CowKing

IamCowKinga at 2007-7-13 12:46:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Thank you Cow:)

I know that i need use f:subview in include pages and error pages now.Thank you very much!

But

<f:subview id="option">

<div style="background-image:url(<c:url value='/images/pic_td_bg.jpg'/>);width:171px;height:109px;border:0px;

padding-top:22px;margin-left:2px;float:left;">

+

<h:commandLink action="create_album" value="#{message['label_album_new']}"/>

</div>

<div style="width:406px;height:82px;padding-top:20px;">

<h:commandButton action="all_album" image="/images/all_button.gif"/>

</div>

</f:subview>

it is not in a include page, it is in main page.When i do not use <f:subview> wapping them the commndLink and the commandButton will disppear when i click the next page in the dataScroller. And i can not use <f:verbatim> in this <f:subview>, when i use it i get

java.lang.ClassCastException: javax.faces.component.html.HtmlCommandLink

at org.apache.myfaces.taglib.core.VerbatimTag.doAfterBody(VerbatimTag.java:76)

What's the matter of this?

spud_webbera at 2007-7-13 12:46:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

First and foremost, using subview within your main page (not within an include) is adding more complexity to your page than is necessary. I'd recommend you just remove the f:subview tag(s) from your main page.

However, IF you wanted to get the above code sample working... You will still need to wrap the HTML tags within f:verbatim. Do not wrap JSF tags inside f:verbatim. You must close the f:verbatim tag before opening a JSF tag.

Here are the rules you should know about f:subview and f:verbatim (I realize that you understand some of these):

f:subview

- Designates a subview of the UIViewRoot (f:view).

- Used when including external files into a main page. i.e jsp:include

- Used for error pages that are configured from the web.xml (don't worry about this for now)

- ANY HTML that appears in this tag must be wrapped in f:verbatim, or use h:outputText with escape=false.

f:verbatim

- Tells JSF to print the text between start and closing verbatim

- Used to wrap HTML tags that appear inside JSF tags (such as h:panelGrid, or f:subview).

- Do not include JSF component tags inside f:verbatim. Close the f:verbatim tag first, then use the JSF tag.

Does this clarify things a bit?

CowKing

IamCowKinga at 2007-7-13 12:46:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
Yes ,it's very useful for me.Thank you very much!And can you give me your MSN? Then i can ask you questions directly:)
spud_webbera at 2007-7-13 12:46:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

Your welcome.

I'm not sure if you were joking or not about getting my MSN so you can "ask me questions directly". If you were serious, you can forget it. You may not have my MSN (I don't use it anyways). My time is worth something and I'm not going to just give it away to every person on the forums that wants me at their service.

I donate some of my time here on the forums to help the JSF community strengthen and grow. I have reasons, but a couple are simple:

- I appreciate this free technology from SUN and this is my way of paying them/thanking them.

- The future of the company I work for is more secure if there's wider acceptance of JSF.

CowKing

IamCowKinga at 2007-7-13 12:46:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
Ok, I see. :)Thank you very much for your answer.
spud_webbera at 2007-7-13 12:46:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11
I should apologize, my response regarding the MSN thing sounded a lot harsher than I intended. I just wanted to let you know that you couldn't have my MSN and some good reasons why not. =)If you have more questions, I'll still be hanging out in the forums!CowKing
IamCowKinga at 2007-7-13 12:46:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12

hi..................

i used t:newspapertable for my code and followed same procedure as urs

but commandlink action is not triggering .................

but if i remove t:newspapertable tag , commandlink action will be triggered can u plz solve the problem............

<f:view>

<f:loadBundle basename="alien.support.iap_messages" var="msg"/>

<h:form name="ThumbnailCenter2">

<table border="0" bordercolor=red cellspacing="0" cellpadding="0" height=100% valign=top>

<tr><td colspan="2" height="8" width="100%"></td></tr>

<tr>

<td width="2" height=100% bgcolor="#e0e0e0"><img src="images/transparent.gif" width=2 height=100%></td>

<td width="100%" valign=top>

<t:newspaperTable id="data" newspaperColumns="4" value="#{thumbnailBean.thumbimages}" var="album" >

<h:column>

<h:panelGrid columns="1" style="border:0px solid green;height:150px;width:30px" cellspacing="0" cellpadding="0">

<h:panelGroup style="height:150px;width:25px">

<h:outputText value=" "/>

</h:panelGroup>

</h:panelGrid>

</h:column>

<h:column>

<h:panelGrid columns="1" style="border:1px solid black;height:138px;width:138px" cellspacing="0" cellpadding="0">

<h:panelGroup style="height:11px;width:138px">

<h:outputText value=" " style="height:11px;width:127px"/>

<h:graphicImage url="images/redball.jpg" width="11" height="11"/>

</h:panelGroup>

<h:panelGroup style="height:68px;width:138px">

<h:outputText value=" " style="height:68px;width:14px"/>

<h:graphicImage url="show_Thumbnail.jsf?imageid=#{album.id}"/>

</h:panelGroup>

<h:panelGroup style="height:20px;width:138px">

<t:commandLink id="imagename" action="#{thumbnailBottomBean.thumbDetails}" style="text-decoration:none;color:black; font-family: Verdana; font-size: 11px; font-weight: normal; color: black" onmouseover="style.color='#000000';style.backgroundColor='#D4D4D4';style.fontWeight='bold'" onmouseout="style.color='#000000';style.backgroundColor='#ffffff';style.fontWeight='normal'" target="f4">

<h:outputText value="#{album.name}"/>

<f:param name="id" value="#{album.id}"/>

</t:commandLink>

</h:panelGroup>

<h:panelGroup style="height:20px;width:138px;">

<h:graphicImage url="images/image1.jpg" width="15" height="18"/>

<h:outputText value="" style="height:20px;width:35px;" />

<h:graphicImage url="images/imagewrite.jpg" width="16" height="18"/>

<h:commandButton id="fullImage" immediate="true" onmousedown="showFullImage(this,'ThumbnailCenter2','fullImage', #{album.id})" image="images/imageview.jpg" >

<f:param name="fullImageID" value="#{node.id}"/>

</h:commandButton>

<h:outputText value="" style="height:20px;width:30px;" />

<h:selectBooleanCheckbox id="imageCheck" value="#{thumbnailBean.imageselect}"></h:selectBooleanCheckbox>

</h:panelGroup>

</h:panelGrid>

</h:column>

</t:newspaperTable>

vin114a at 2007-7-13 12:46:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13

I don't know if I can solve your problem vin. Two things though:

First. try it with h:commandLink instead of t:commandLink. I'm not sure what t:commandLink does.

Secondly, I've experience some odd behaviour when using commandLink and commandButton as children components to anything but h:form (that is, f:view>h:form>h:command*). The action method doesn't seem to get called for some reason. I was unable to figure out why.

CowKing

IamCowKinga at 2007-7-13 12:46:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 14
thanks for ur response...........if i put h:commandlink also it is not performing any action...............i wasted around 4 days working hours......plz if u have got any solution for this, respond me as early as possible
vin114a at 2007-7-13 12:46:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 15
did you check myfaces site and see the current bugs for that component?Why don't you change to another component like datatable?
pringia at 2007-7-20 22:15:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 16
Thanks CowKing.Your insights were very useful when i encountered the same problem
jFocia at 2007-7-20 22:15:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 17

Hi ,

I am using some formatted text to display in the JSF page.

For display purpose I am using h:outputText and I have already set escape="false"

But still everytime it gives me following error when I use
or any other formatting tag.

Can somebody help me out.

Error Parsing /pages/comments.xhtml: Error Traced[line: 147] The value of attribute "value" associated with an element type "null" must not contain the '<' character.

Thanks and Regards,

Amit

flummoxingamita at 2007-7-20 22:15:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...