JPA Entity as JSF Bean?

You could do so. It’s technically possible. But it does (design)functionally not make any sense. You’re basically tight-coupling the model with the controller. Usually the JPA entity (model) is a property of a JSF managed bean (controller). This keeps the code DRY. You don’t want to duplicate the same properties over all place, let alone … Read more

Outcommented Facelets code still invokes EL expressions like #{bean.action()} and causes javax.el.PropertyNotFoundException on #{bean.action}

Look closer at the stack trace. Here’s the relevant part: … org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189) com.sun.faces.facelets.el.ELText$ELTextVariable.toString(ELText.java:217) com.sun.faces.facelets.el.ELText$ELTextComposite.toString(ELText.java:157) com.sun.faces.facelets.compiler.CommentInstruction.write(CommentInstruction.java:77) … It’s thus evaluating EL in a comment block (recognizable by CommentInstruction). A comment block is considered as template text. Facelets evaluates by default also EL #{} in template text. It’s like as if you’re writing <p>#{screenShotBean.takeScreenshot}</p> without any JSF … Read more

Is it suggested to use h:outputText for everything?

If you’re using JSF 2.x with Facelets 2.x instead of JSP, then both are equally valid. Even more, Facelets implicitly wraps inline content in a component as represented by <h:outputText> (in other words, it will be escaped!). Only whenever you’d like to disable escaping using escape=”false”, or would like to assign id, style, onclick, etc … Read more

How to show faces message in the redirected page

Keep the message in the flash scope. It’ll survive the redirect. context.addMessage(clientId, message); externalContext.getFlash().setKeepMessages(true); return “users.xhtml?faces-redirect=true”; Note that older Mojarra versions have some peculiar Flash scope related bugs: issue 1755 – Flash scoped messages lives longer than next request – fixed in 2.0.7 / 2.1.4 issue 2130 – Flash cookie enables data exploits – fixed … Read more

How to use in or to select multiple items?

Your best bet is to bind the <h:selectBooleanCheckbox> value with a Map<Item, Boolean> property where Item represents the object behind the corresponding row. <h:dataTable value=”#{bean.items}” var=”item”> <h:column> <h:selectBooleanCheckbox value=”#{bean.checked[item]}” /> </h:column> … </h:dataTable> <h:commandButton value=”submit” action=”#{bean.submit}” /> public class Bean { private Map<Item, Boolean> checked = new HashMap<Item, Boolean>(); private List<Item> items; public void submit() … Read more