Invisible comments in jsf 2.0? [duplicate] - jsf

This question already has an answer here:
How can I remove HTML comments in my Facelets?
(1 answer)
Closed 8 years ago.
is it possible to embed comments in my .xhtml-files that are only displayed in the source and not the rendered result?
I want to include author, date,... in the files but they should not be visible to the enduser in the generated output. If I use the standard comment-tags <!-- --> the browser displays them.

Add the following into your web.xml:
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
This way Facelets will skip the comments while parsing the view xhtml template.

Invisible comments in JSF is a drawback, specially for beginers. I agree with answer of Mr Minchev. Anyway, I provide an alternative way to comment content in JSF consisting of using ui:remove
<ui:remove> This is a comment </ui:remove>
The UI Remove tag is used to specify tags or blocks of content that should be removed from your page by the Facelets view handler at compile time. This tag has no attributes. You can use this tag to indicate that a particular tag should be removed from the rendered page.
It's useful to remove content which is required during design time, but not during run time, such as comments, some stubbed content (e.g. "lorem ipsum") which aids in filling up the page content to fit the layout in visual designers such as Dreamweaver, etc.
See: Practical implications of Facelets ui:remove tag
Note that the Facelets compilation process is much faster than the JSP compilation process because no Java bytecode is actually generated and compiled behind the scenes when you first visit your page. The UI Remove tag is used to specify tags or blocks of content that should be removed from your page by the Facelets view handler at compile time. This tag has no attributes.
Examples of both comment options

Wrong, the right way is:
<context-param>
<param-name>facelets.SKIP_COMMENTS</param-name>
<param-value>true</param-value>
This work for me, javax.faces.FACELETS_SKIP_COMMENTS no!

Related

How to change index.html in every folder to / when we access it on browser

I've some unique problem, but I think this is not problem, I just want to optimize the url that my website have.
so I want to change all
index.html
on every folder as example
culture
folder, so normally if we want access
index.html
in culture folder we can just type
culture/index.html
right? but i want to access by just type
culture/
Is it possible to do that? If so, how we produce? I'm using jsf 2 as programming language.
Maybe I misunderstand your problem, but this can be done by configuring welcome files in the web.xml file:
Web Application developers can define an ordered list of partial URIs
called welcome files in the Web application deployment descriptor. The
purpose of this mechanism is to allow the deployer to specify an
ordered list of partial URIs for the container to use for appending to
URIs when there is a request for a URI that corresponds to a directory
entry in the WAR not mapped to a Web component. This feature can make
your site easier to use, because the user can type a URL without
giving a specific filename.
Note: Welcome files can be JSPs, static pages, or servlets.
Just:
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
I've tested this on WildFly 11 and it works, my project structure is:
+ WebContent
- index.xhtml
+ folder_a
- index.xhtml
+ folder_b
- index.html
+ folder_c
- other_name.xhtml
- some_name.html
When I enter:
http://localhost:8080/myproject/ I get a content from WebContent/index.xhtml
http://localhost:8080/myproject/folder_a I get a content from WebContent/folder_a/index.xhtml
http://localhost:8080/myproject/folder_b I get a content from WebContent/folder_b/index.html
Does the .xhtml file contain JSF content? is it parsed? I always
thought defining a jsf/facelets file as a welcome file did not work
and you needed http redirects via 'meta-inf'
.jsf' is that an extension I am using in myweb.xml` file:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
Please read answers for the below question to learn what it is:
JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?
What is the difference between creating JSF pages with .jsp or .xhtml or .jsf extension
JSF 2.0 does not have support for extensionless URL by default. This is a long waited feature for the community, but finally we got this with JSF 2.3 (released early 2017). If you care able to update your application to JSF 2.3, or maybe want some more information, please check it out here.
A brief example of how you can make the default JSF approach for extensionless URLs:
In the web.xml file, include each desired mapping using a tag inside the tag:
<url-pattern>/page1</url-pattern>
<url-pattern>/page2</url-pattern>
<url-pattern>/path/page1</url-pattern>
These patterns will redirect the user to the following paths respectively:
www.domain.com/page1 -> www.domain.com/page1.xhtml
www.domain.com/page2 -> www.domain.com/page2.xhtml
www.domain.com/path/page1 -> www.domain.com/path/page1.xhtml
Note that the above examples are not providing a way to redirect to the index.xhtml page, they are just a example of how the new JSF 2.3 mapping work.
However, if you can't update your project right now, I suggest you to follow #Kukeltje advice and take a look on the PrettyFaces library.
PrettyFaces is focused on provide a simple way to create URL mappings for older JSF versions. Heres a example of how it works:
In the pretty-config.xml file, include your desired mappings using a tag:
<url-mapping id="view-page">
<pattern value="/page" />
<view-id value="/page/index.xhtml" />
</url-mapping>
<url-mapping id="view-page-edit">
<pattern value="/page/#{id}" />
<view-id value="/page/edit.xhtml" />
</url-mapping>
These patterns would work like the following examples:
www.domain.com/page -> www.domain.com/page/index.xhtml
www.domain.com/page/2 -> www.domain.com/page/edit.xhtml?id=2
Both are good alternatives, PrettyFaces looks more powerful right now, since they are support this kind of solution for more time, but the JSF 2.3 should also do the trick.

Add a global Jsp to include in Liferay tomcat-6

I have a Jsp that dynamically needs to get included in entire project as user opens any jsp. i.e. As a user opens a jsp my jsp should automatically gets included.
I have written this in web.xml in Tomcat
<jsp-property-group>
<url-pattern>/webapps/ROOT/html/*.jsp</url-pattern>
<url-pattern>*.jspf</url-pattern>
<el-ignored>false</el-ignored>
<scripting-invalid>false</scripting-invalid>
<is-xml>false</is-xml>
<include-prelude>/WEB-INF/jsp/tracker.jsp</include-prelude>
<!-- <include-coda>/template/coda.jspf</include-coda> -->
</jsp-property-group>
I had kept my jsp in tomcat under WEB-INF/jsp/ and i want to include it into every porject as it contains a code that tracks log for user.
Or any other way to make this happen.
Thanks.
There is one more way to include your JSP for the whole portal and i.e. the dockbar.
You can create a hook and include your jsp in the /html/portlet/dockbar/view.jsp using either <jsp:include /> or <liferay-util:include /> or simple <%# include file="" /> (this would be static).
<jsp:include page="/jsp/yourJSPPageToBeIncluded.jsp" />
OR
<liferay-util:include page="/jsp/yourJSPPageToBeIncluded.jsp" />
OR
<%# include file="/jsp/yourJSPPageToBeIncluded.jsp" />
Note: the path may differ depending on where you will be putting the JSP.
Why I am choosing dockbar is because it is present on all the portal-pages of liferay. This won't work if you are opening a pop-up like configuration pop-up or look-and-feel pop-up or other custom dialog pop-ups since dockbar is not present in the pop-up. For using in pop-ups you would have to override portal_pop_up.vm in your custom-theme and write the code as suggested by #VikasV
$theme.include($themeServletContext, "/jsp/yourJSPPageToBeIncluded.jsp")
There are two ways for this.
Simple way is to include your JSP in the Theme. When your Theme is applied to your project, and when Theme is rendered, any pages in your project will render this included JSP.
Code sample below. This has to be placed in vm file(navigation.vm).
$theme.include($themeServletContext, "/jsp/yourJSPPageToBeIncluded.jsp")
Here, JSP folder is placed directly inside Theme war.
Other way (tedious one), is to include this JSP in each and every JSP page that you want this to be included.
Use <jsp:include> element for this.
Some references,
Ref1
Ref2

How to prevent loading of Richfaces 4 component css files

I'm upgrading from Richfaces 3.3 to 4.
I have a number of custom css files and skins.
Richfaces 4 seems to have added a whole load of new classes to various components i.e. rf-tab, rf-tab-cnt, etc.
These components have styles associated with them (They appear to be loaded in ecss file with names like panel.ecss, datascroller.ecss, etc)
They have really messed up my current UI layout :(
Is there any way to disable the loading of all these component stylessheets?
I tried applying the following but it does not work:
<context-param>
<param-name>org.richfaces.LoadStyleStrategy</param-name>
<param-value>NONE</param-value>
</context-param>
<context-param>
<param-name>org.ajax4jsf.COMPRESS_STYLE</param-name>
<param-value>false</param-value>
</context-param>
Thanks
Use 'plain' skin. This way most CSS classes will be rendered but not defined...

myFaces Trinidad example not displaying

Hi I have followed the setup guide at:
http://myfaces.apache.org/trinidad/installation.html
When I include the following code in my faces-config.xml file I get an error when I hit a page:
<application>
<default-render-kit-id>org.apache.myfaces.trinidad.core</default-render-kit-id>
</application>
Start of Error:
java.lang.IllegalStateException: No RenderingContext
at org.apache.myfaces.trinidad.render.CoreRenderer.encodeBegin(CoreRenderer.java:390)
at org.apache.myfaces.trinidadinternal.renderkit.htmlBasic.HtmlFormRenderer.encodeBegin(HtmlFormRenderer.java:56)
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:813)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:928)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
When I remove that piece of code from my faces-config.xml file I can navigate my site as normal, but when I hit a page that has some sample Trinidad code nothing is displayed...just an empty page.
Any ideas on what I'm doing wrong?
I removed the following from my web.xml and its working now, any ideas? Confused :(
<context-param>
<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
<param-value>com.sun.facelets.FaceletViewHandler</param-value>
</context-param>
Thanks
I've actually discovered an excellent control for Richfaces that will provide the same functionailty. I'm going to go with this instead.
http://livedemo.exadel.com/richfaces-demo/richfaces/extendedDataTable.jsf?c=extendedDataTable&tab=usage
As BalsusC suggested, mixing different ajaxical component libraries might not be such a good idea.
Additionally, I have found the documentation and examples for Trinidad to be quite poor; Particularly in comparasion to Richfaces.
Would I be correct in thinking Trinidad is slowly dying?

Primefaces Style Doens't work correctly

I started a JSF project and included primefaces. But I have problems with the style. It doesn't look that nice than in the official showcase. But I have no idea why.
That's what I did so far:
I downloaded a style and extracted it into my project.
I added <link type="text/css" rel="stylesheet" href="#{request.contextPath}/resources/flick/skin.css" /> to my facelets template
I extended my web.xml with the following:
<context-param>
<param-name>primefaces.skin</param-name>
<param-value>none</param-value>
</context-param>
Unfortunately it loks like that:
fyi: That's a prime panel and a prime button :-/
can you pls help me :-)
cheers
Update:
Whatsoever I change in context-param. it doesn't work!
Do you need more information to help me solve that problem?
Thank you for help..
That's becuase you used none skin.
Look in Prime different skins to choose the right skin.
For example, if you would like Eggplant add:
<context-param>
<param-name>primefaces.skin</param-name>
<param-value>Eggplant</param-value>
</context-param>
I switched from myfaces to mojarra and now it works -.-

Resources