1) add entity by method-binding
page 18
#{tipAction.add(tip)}
public void add(GolfTip tip) {
entityManager.persist(tip);
activeTip = tip;
facesMessages.add(
"Thanks for the tip, #{activeTip.author}!");
retrieveAllTips();
}
2) factory component trace
seam's factory component
which did not show in the log,
using following to record the in the log
log.info("Factory for tips called. Retrieving all golf tips...");
3) check empty content
if (tip.getContent().trim().length() == 0) { FacesMessages.instance().add("Please provide a tip from which we may all learn.");
return;
}
4) remove component
Contexts.removeFromAllContexts("tip");
// another option is to outject a null value to the context variable tip
5) find entity / remove entity
activeTip = entityManager.find(GolfTip.class, activeTip.getId());
entityManager.remove(activeTip);
6) display error
<div class="prop">
<h:outputLabel styleClass="name" for="author">Author <span class="required">*</span></h:outputLabel>
<span class="value">
<h:inputText id="author" value="#{tip.author}" required="true" style="width: 150px;"/>
</span>
<span class="error">
<h:graphicImage value="/img/error.gif" rendered="#{not empty [b]facesMessages.getCurrentMessagesForControl('author')[/b]}" styleClass="errors"/>
<h:message for="author" styleClass="errors"/>
</span>
</div>
7) set order of entityquery
pg 68
public String getOrder() {
if (super.getOrder() == null) {
setOrder("name asc");
}
return super.getOrder();
}
page 18
#{tipAction.add(tip)}
public void add(GolfTip tip) {
entityManager.persist(tip);
activeTip = tip;
facesMessages.add(
"Thanks for the tip, #{activeTip.author}!");
retrieveAllTips();
}
2) factory component trace
seam's factory component
which did not show in the log,
using following to record the in the log
log.info("Factory for tips called. Retrieving all golf tips...");
3) check empty content
if (tip.getContent().trim().length() == 0) { FacesMessages.instance().add("Please provide a tip from which we may all learn.");
return;
}
4) remove component
Contexts.removeFromAllContexts("tip");
// another option is to outject a null value to the context variable tip
5) find entity / remove entity
activeTip = entityManager.find(GolfTip.class, activeTip.getId());
entityManager.remove(activeTip);
6) display error
<div class="prop">
<h:outputLabel styleClass="name" for="author">Author <span class="required">*</span></h:outputLabel>
<span class="value">
<h:inputText id="author" value="#{tip.author}" required="true" style="width: 150px;"/>
</span>
<span class="error">
<h:graphicImage value="/img/error.gif" rendered="#{not empty [b]facesMessages.getCurrentMessagesForControl('author')[/b]}" styleClass="errors"/>
<h:message for="author" styleClass="errors"/>
</span>
</div>
7) set order of entityquery
pg 68
public String getOrder() {
if (super.getOrder() == null) {
setOrder("name asc");
}
return super.getOrder();
}