[JBoss Seam] - Question about passing an action Listener
by german.delacruz
Hi people
I'm very new to seam (Actually, I've using it for 2 weeks). I've read all the documentation I found, I reviewed all the examples.
Nowadays, I'm making my first complete crud. I must say that I've been using tapestry since 2002, then I think my main problem is trying to solve all the problems in the tapestry way.
In my application I've using EJB3, Seam and facelets for the view. I've been using a SFSB with Session scope for the actions. I'm using it with session scope because When I go to any action from the table I lost the last search results (Because the default is a temporal conversation). I can't use a long conversation because in a crud it haven't an end This is my code...
| package manchot.actions;
|
| import java.util.List;
|
| import javax.ejb.EJB;
| import javax.ejb.Remove;
| import javax.ejb.Stateful;
|
| import manchot.model.Person;
| import manchot.services.PersonService;
|
| import org.jboss.seam.ScopeType;
| import org.jboss.seam.annotations.Destroy;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Out;
| import org.jboss.seam.annotations.Scope;
| import org.jboss.seam.annotations.Unwrap;
| import org.jboss.seam.annotations.datamodel.DataModel;
| import org.jboss.seam.annotations.datamodel.DataModelSelection;
|
| @Name("personController")
| @Stateful
| @Scope(ScopeType.SESSION)
| @LoggedIn
| public class PersonControllerBean implements PersonController {
|
| private String searchString;
|
| @EJB
| private PersonService personService;
|
|
| // private List<Person> model;
|
| @DataModelSelection
| private Person selected;
|
| private Person entity;
|
| public Person getEntity() {
| return entity;
| }
|
| public void setEntity(Person entity) {
| this.entity = entity;
| }
|
| public String getSearchString() {
| return searchString;
| }
|
|
| public Person getSelected() {
| return selected;
| }
|
| public void setSearchString(String searchString) {
| this.searchString = searchString;
| }
|
| public void setSelected(Person selected) {
| this.selected = selected;
| }
|
| @DataModel("model")
| public List<Person> getModel() {
| return (personService.findByNameLike(searchString));
| //return "personCRUD";
|
| }
|
| public String select() {
| setEntity(getSelected());
| // setSelected(personService.merge( getSelected()));
| return "personCRUD";
| }
|
| public String clearSelected() {
| setEntity(null);
| return "personCRUD";
| }
|
| @Destroy
| @Remove
| public void destroy() {
| }
| }
|
|
An this is my xhtml
| <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
| <ui:composition xmlns="http://www.w3.org/1999/xhtml"
| xmlns:ui="http://java.sun.com/jsf/facelets"
| xmlns:h="http://java.sun.com/jsf/html"
| xmlns:f="http://java.sun.com/jsf/core"
| xmlns:s="http://jboss.com/products/seam/taglib"
| template="/WEB-INF/templates/template.xhtml">
|
| <!-- content -->
|
| <ui:define name="content">
| <div class="section">
| <h:form>
| <span class="errors"><h:messages globalOnly="true"/></span>
| <h1>Buscar Padron</h1>
| <fieldset>
| <h:inputText value="#{personController.searchString}" style="width: 165px;"/> 
| <h:commandButton value="Buscar Padron" action="#{personCRUD}" styleClass="button"/>
| </fieldset>
| </h:form>
| </div>
|
|
| <div class="section">
| <h:form>
| <h:outputText value="No se encontraron datos" rendered="#{model != null and model.rowCount==0}"/>
| <h:dataTable value="#{model}" var="e" rendered="#{model.rowCount>0}">
| <h:column>
| <f:facet name="header">Razon social</f:facet>
| #{e.razonSocial}
| </h:column>
| <h:column>
| <f:facet name="header">CUIT/CUIL</f:facet>
| #{e.fiscalID}
| </h:column>
| <h:column>
| <f:facet name="header">Action</f:facet>
| <s:link value="View" action="#{personController.select}"/>
| </h:column>
| </h:dataTable>
| </h:form>
| </div>
|
| <h:panelGroup rendered="#{personController.entity!=null}">
| <div class="section">
| <h1>View Hotel</h1>
| </div>
| <div class="section">
| <div class="entry">
| <div class="label">CUIT/CUIL</div>
| <div class="output">#{personController.entity.fiscalID}</div>
| </div>
| <div class="entry">
| <div class="label">Razon Social:</div>
| <div class="output">#{personController.entity.razonSocial}</div>
| </div>
| <div class="entry">
| <div class="label">Nombre Completo:</div>
| <div class="output">#{personController.entity.completeName}</div>
| </div>
| </div>
| <h:form>
| <div class="section">
| <h:commandButton value="Ok" action="#{personController.clearSelected}" styleClass="button"/>
| </div>
| </h:form>
| </h:panelGroup>
| </ui:define>
| </ui:composition>
|
Then, I've some questions...
1. What do you think of my code?
2. I can't make a "redirect" with a button from xhtml. When I write a search String I want to redirect to the same page only for reloading the model. How can I make it?
2. My model (I've put and @DataModel in a getter) is never in the session, isn't it? I mean, by now, I don't want to put in in the session, I want to recalculate in any request. Since it's an internal application the DB isn't a problem. But my session size is a problem.
3. I want to make a editor component for this entity. I'm thinking in another facelet templeate this a param to call it with the action to execute. How can I make it?
That's all!
thanks!
German.-
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3962126#3962126
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3962126
18 years, 5 months