primefaces components not working with own css - java

i am using ready-made template(with css and j-queries) in my java ee app. all the primefaces components are rendered properly except the panelgrid control of primefaces 3.2.
it is displayed with border. i want it without border.
i have removed all the table styling from the css of custom ready-made template.
still the border is there.
when i remove the readymade template, the panelgrid is rendered perfectly without any border. how do i remove the border and what is the cause of this problem?
edited:
xhtml file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>AP administration panel - A massive administration panel</title>
</h:head>
<h:body>
<div>
<h:form>
<p:panelGrid columns="2" style="border: none">
<h:outputText value="scrip symbol"/>
<p:inputText value=""/>
<p:commandButton value="submit"/>
</p:panelGrid>
</h:form>
</div>
</h:body>
</html>

When overriding PrimeFaces default styles, you have to specify a CSS selector of at least the same strength or to specify a stronger selector. The strength of a CSS selector (the cascading rules) is specified in the W3 CSS specification and clearly explained in this article: Understanding Style Precedence in CSS: Specificity, Inheritance, and the Cascade.
Based on PrimeFaces own CSS, the following selectors should do:
.ui-panelgrid tr, .ui-panelgrid td {
border: none;
}
Just put them in a .css file which you include by <h:outputStylesheet> inside the beginning of the <h:body> so that it will be included after PrimeFaces own style.
<h:body>
<h:outputStylesheet name="layout.css" />
...
</h:body>
See also:
How to remove border from specific PrimeFaces p:panelGrid?
How do I override default PrimeFaces CSS with custom styles?
Update: As per your update, your CSS doesn't seem to be loaded at all. You should have noticed this by verifying the HTTP traffic in browser builtin webdeveloper toolset (press F12 in Chrome/IE9/Firebug) and seeing that it returned a HTTP 404 error. When using <h:outputStylesheet> you need to put the CSS file in the /resources folder of the webcontent. So you must have a /resources/css/mycss.css in order to be able to use <h:outputStylesheet name="css/mycss.css" />.
See also:
How to reference CSS / JS / image resource in Facelets template?

Related

JSF 2 - construct a page from two files - main and current content

I'm quite new to using JSF and I'm not sure if that's the right way to go, but in Rails you usually have a main application file into which the current page is loaded. That way I don't have to worry about copy-pasting the menu, etc. every time.
How can I achieve that with JSF 2? Can I navigate to the same main page every time and tell it to load a current content? Or do I tell the current page that I navigate to to load the "main frame around the content"?
Thanks!
Yes of course, JSF 2.0 has page-templating feature. You define a template that defines a generic layout to all the view pages.
Facelets tags to create basic page:
ui:insert – defines content that is going to replace by the file that load the template;
ui:define – defines content that is inserted into tag ui:insert;
ui:include – includes content from another page;
ui:composition – the specified template is loaded, if used with template attribute, and the children of this tag defines the template layout. In other case, it’s a group of elements, that can be inserted somewhere.
For example:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/templates/myLayout.xhtml">
<ui:define name="menu">
<ui:include src="/mypath/menu.xhtml"/>
</ui:define>
<ui:define name="content">
<ui:include src="/mypath/content.xhtml"/>
</ui:define>
</ui:composition>
or
<ui:insert name="content">
<ui:include src="/mypath/mycontent.xhtml"/>
</ui:insert>
JSF doesn't support what you want to archive. Instead, it support the views and basic layout(template). What you need it this:
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
template="path/to/template.xhtml>
<your custom content here/>
<ui:composition/>

Not able to add HTML to <ui:define>

I have recently started working with JSF2.0 and Facelets, but have run into what I hope is an easy answer for most of you out there. When I am trying to add any HTML tag within a <ui:define> tag I receive the following error:
javax.faces.view.facelets.TagException: /content/home/test.xhtml #11,10 Tag Library supports namespace: http://java.sun.com/jsf/facelets, but no tag was defined for name: div
If I remove all of the HTML tags from the section the page displays correctly. Here is my simple page that I have been trying to get working:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:jrc="http://com.comanche.web.components">
<ui:composition template="/templates/masterLayout.xhtml" xmlns="http://java.sun.com/jsf/facelets">
<ui:define name="windowTitle">Home</ui:define>
<ui:define name="content">
<div>I want to add HTML and am having lots of trouble.</div>
</ui:define>
</ui:composition>
</html>
I know I should be able to add HTML within the define tag. What do I need to do to get HTML in without any errors.
Your <ui:composition> declaration is using the wrong global XML namespace. You definied http://java.sun.com/jsf/facelets as global XML namespace while it should have been assigned to ui: XML namespace. The <div> tag doesn't exist in the Facelets taglib (which is what the exception is trying to tell you). You should have assigned http://www.w3.org/1999/xhtml as global XML namespace. Further, the <!DOCTYPE> and <html> will be ignored anyway. The sole content of the file should be the following:
<ui:composition template="/templates/masterLayout.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:define name="windowTitle">Home</ui:define>
<ui:define name="content">
<div>I want to add HTML and am having lots of trouble.</div>
</ui:define>
</ui:composition>
Nothing before or after <ui:composition> in the very same file is necessary.
See also:
How to include another XHTML in XHTML using JSF 2.0 Facelets?

JSF 2.1 + RichFaces 4 - Change rich:dataScroller default stylesheet

I have the page which has the following tags:
<h:head>
<h:outputStylesheet name="style.css" library="css" />
</h:head>
and some kind of dataScroller:
<rich:dataScroller for="productsList" id="scroller" maxPages="10">
Now I'm trying to override dataScroller default css style by adding
.rf-ds { background: black; }
in my style.css file.
I don't see any changes. When I open firebug I see both .rf-ds classes one is coming from my css and is disabled and second one is default dataScroller class.
How can I override default class?
try to add !important to your css like this:
.rf-ds { background: black !important; }
see
http://www.electrictoolbox.com/using-important-css/
Try <link rel="stylesheet" type="text/css" href="/resources/css/style.css" /> in your <head></head>
.From what I have seen, RichFaces loads CSS attached with <link> after it has loaded its own CSS, giving your CSS precedence.
In our project we needed to customize a lot of components's css and IMHO adding !important is not such an elegant solution (its more like a hack). Hence we took this approach.

How include page in JSF?

i'm new in jsf, i would like to know how i can reuse others .jsf pages without 'copy paste' them.
In .jsp i do:
// head.jsp
<head> ... </head>
// top.jsp
<body> ... </body>
Then i include them in my new .jsp
// index.jsp
<%#include file="head.jsp" %>
<%#include file="top.jsp" %>
...
How can i do this with jsf ?
i'm trying this way:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<ui:include src="components/head.xhtml" />
</h:head>
<h:body>
<ui:include src="components/top.xhtml" />
</h:body>
</html>
But is not working..
Any idea ?
Best regards,
Valter Henrique.
Facelets is the default view technology for JSF2, so I would use its <ui:include> tag here. Make sure your paths are correct - they should start with webapp root, one containing WEB-INF - and also make sure the included facelets contain <ui:composition> tag around the included content. Anything outside this tag will be ignored.
Try looking for the "import" tag in the core library.
I think ui:include might be for facelets rather than plain jsf.

problem refreshing captcha with ajax

I'm using a captcha in my JSF page (not recaptcha or randomly generated image value, etc). Initially it gets its value from CaptchaServlet. I want to add "refresh image" button without refreshing the whole page, but the code below doesn't work.
<h:panelGrid id="grid" columns="1" style="margin-bottom:10px">
<h:graphicImage id="capimg" value="#{facesContext.externalContext.requestContextPath}/../Captcha.jpg"/>
</h:panelGrid>
The refresh button with PrimeFaces <p:commandButton>
<p:commandButton value="This" process="#this" update="grid" onclick="#{facesContext.externalContext.requestContextPath}/../Captcha.jpg"/>
refreshes the whole page.
Do you have any suggestions? Can I use a managed bean and forward to a servlet?
The <p:commandButton> uses Ajax to asynchronously update parts of the page. However, it requires that all necessary JavaScript libraries are included to do all the Ajax works. This should automatically happen when you have a <h:head> instead of a <head> in the master template. The JSF 2.0 resource management will then include the necessary <script> elements in there. If you have read the server logs, you should have noticed warnings that this has failed because the <h:head> is missing.
Here's how a minimum JSF 2.0 Facelet master template should look like, with PrimeFaces taglib declared:
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.som/jsf/core"
xmlns:h="http://java.sun.som/jsf/html"
xmlns:ui="http://java.sun.som/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
<title>Page title</title>
</h:head>
<h:body>
<h1>Put your content here</h1>
</h:body>
</html>
Please note the <h:head> and <h:body> instead of <head> and <body>. Rightclick the generated HTML page in the webbrowser an choose View Source. You should see the included <script> elements in there.
Update: get rid of the onclick attribute. It's not valid JavaScript code. Further you also need to ensure that the servlet response with the image is not cached by the webbrowser. You can do that by adding the following headers before you write any bit to the response:
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0); // Proxies.

Categories