Concatenating strings within EL expression defined in an attribute of a facelets tag

It is possible to concatenate Strings in EL using the java.lang.String.concat(String) method. Thus your code could look like: <h:outputText value=”#{cc.attrs.appreciatedByCurrentUser ? (”.concat(cc.attrs.count).concat(‘&lt;br/&gt;’).concat(cc.attrs.count-1)) : (”.concat((cc.attrs.count+1)).concat(‘&lt;br/&gt;’).concat(cc.attrs.count))}” escape=”false” /> In this particular case however I would go with one of the options that Mr BalusC had suggested because the code above doesn’t look quite elegant. In some cases … Read more

Facelets repeat Tag Index

Specify a value for the “varStatus” attribute: <ui:repeat id=”…” var=”…” value=”…” varStatus=”myVarStatus”> You can then access the loop index via EL: #{myVarStatus.index} Additionally, the following properties are available to the varStatus: begin of type Integer end of type Integer index of type int step of type Integer even of type boolean odd of type boolean … Read more

How to display my application’s errors in JSF?

FacesContext.addMessage(String, FacesMessage) requires the component’s clientId, not it’s id. If you’re wondering why, think about having a control as a child of a dataTable, stamping out different values with the same control for each row – it would be possible to have a different message printed for each row. The id is always the same; … Read more

How to use JSF generated HTML element ID with colon “:” in CSS selectors?

The : is a special character in CSS identifiers, it represents the start of a pseudo class selector like :hover, :first-child, etc. You would need to escape it. #phoneForm\:phoneTable { background: pink; } This only doesn’t work in IE6/7. If you’d like to support those users as well, use \3A instead (with a trailing space … Read more

Error parsing XHTML: The content of elements must consist of well-formed character data or markup

Facelets is a XML based view technology which uses XHTML+XML to generate HTML output. XML has five special characters which has special treatment by the XML parser: < the start of a tag. > the end of a tag. ” the start and end of an attribute value. ‘ the alternative start and end of … Read more

When to use f:view and f:subview

<f:view> The <f:view> is only useful if you want to explicitly specify/override any of the available attributes such as locale, encoding, contentType, etc or want to attach some phase listeners. E.g. <f:view locale=”#{user.locale}” encoding=”UTF-8″ contentType=”text/html”> If you don’t specify it, then the sane JSF defaults will just be used instead, which is respectively UIViewRoot#getLocale(), UTF-8 … Read more

Get Request and Session Parameters and Attributes from JSF pages

You can get a request parameter id using the expression: <h:outputText value=”#{param[‘id’]}” /> param—An immutable Map of the request parameters for this request, keyed by parameter name. Only the first value for each parameter name is included. sessionScope—A Map of the session attributes for this request, keyed by attribute name. Section 5.3.1.2 of the JSF … Read more

What is the difference between creating JSF pages with .jsp or .xhtml or .jsf extension

JSP is an old view technology and widely used in combination with JSF 1.x. Facelets (by some people overgeneralized as XHTML) is the successor of JSP and introduced as default view technology of JSF 2.x at end of 2009. When you were seeing JSPs, you were perhaps reading outdated books, tutorials or resources targeted on … Read more

Sometimes I see JSF URL is *.jsf, sometimes *.xhtml and sometimes /faces/*. Why?

The .jsf extension is where the FacesServlet is during the JSF 1.2 period often mapped on in the web.xml. <servlet-mapping> <servlet-name>facesServlet</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> The .xhtml extension is of the actual Facelets file as you’ve physically placed in the webcontent of your webapp, e.g. Webapp/WebContent/page.xhtml. If you invoke this page with the .jsf extension, e.g. http://localhost:8080/webapp/page.jsf … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)