I've a little experience with JSF and I would like to know the best practice to build a classic crud application with search capabilities. In particular I 'm in doubt about this last one; I've a form where the user type the object id; I've all my entities mapped with jpa and the relating facade session bean. But in the jsf page how could I read the parameter, call the finder method and then display the object properties? Shall I use a servlet that get the object and store it in the request scope and access to that eith JSF EL?
Thank you in advance
You don't need a servlet. Just inject the session facade / EJB by @EJB
in managed bean and call it in the bean action method and then display it the usual JSF/EL way in the result page.
View:
<h:form>
<h:inputText value="#{bean.search}" />
<h:commandButton value="search" action="#{bean.submit}" />
</h:form>
<h:panelGroup rendered="#{not empty bean.result}">
<p>#{bean.result.someProperty}</p>
</h:panelGroup>
Model:
@ManagedBean
@RequestScoped
public class Bean {
private String search; // +getter +setter
private Data result; // +getter
@EJB
private DataFacade dataFacade;
public void submit() {
result = dataFacade.find(search);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With