Foros del Web » Programación para mayores de 30 ;) » Java »

Inquietud con EJB y primefaces

Estas en el tema de Inquietud con EJB y primefaces en el foro de Java en Foros del Web. Hola a todos soy nuevo en este mundo de JSP con JSF y primefaces utilizando EJB, estoy haciendo una aplicacion web con netbeans y genere ...
  #1 (permalink)  
Antiguo 12/05/2012, 11:30
Avatar de calichecal  
Fecha de Ingreso: junio-2009
Ubicación: Colombia
Mensajes: 288
Antigüedad: 14 años, 10 meses
Puntos: 12
Pregunta Inquietud con EJB y primefaces

Hola a todos soy nuevo en este mundo de JSP con JSF y primefaces utilizando EJB, estoy haciendo una aplicacion web con netbeans y genere los entity beans luego generé las páginas JSF para todos estos entity beans.

Aparte de generar las paginas para editar,eliminar y crear en cada tabla, también me genera un clase fachada para cada entity y un controlador, de los cuales muestro uno a continuación:

codido java
Código PHP:

package Controllers
;

/* por acá muchos imports*/

@ManagedBean(name "mensajeController")
@
SessionScoped
public class MensajeController implements Serializable {

    private 
Mensaje current;
    private 
DataModel items null;
    @
EJB
    
private SesionBeans.MensajeFacade ejbFacade;
    private 
PaginationHelper pagination;
    private 
int selectedItemIndex;


    public 
Mensaje getSelected() {
        if (
current == null) {
            
current = new Mensaje();
            
selectedItemIndex = -1;
        }
        return 
current;
    }

    private 
MensajeFacade getFacade() {
        return 
ejbFacade;
    }

    public 
PaginationHelper getPagination() {
        if (
pagination == null) {
            
pagination = new PaginationHelper(10) {

                @
Override
                
public int getItemsCount() {
                    return 
getFacade().count();
                }

                @
Override
                
public DataModel createPageDataModel() {
                    return new 
ListDataModel(getFacade().findRange(new int[]{getPageFirstItem(), getPageFirstItem() + getPageSize()}));
                }
            };
        }
        return 
pagination;
    }

    public 
String prepareList() {
        
recreateModel();
        return 
"List";
    }

    public 
String prepareView() {
        
current = (MensajegetItems().getRowData();
        
selectedItemIndex pagination.getPageFirstItem() + getItems().getRowIndex();
        return 
"/mensaje/View";
    }

    public 
String prepareCreate() {
        
current = new Mensaje();
        
selectedItemIndex = -1;
        return 
"Create";
    }

    public 
String create() {
        try {
            
getFacade().create(current);
            
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("MensajeCreated"));
            return 
prepareCreate();
        } catch (
Exception e) {
            
JsfUtil.addErrorMessage(eResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
            return 
null;
        }
    }

    public 
String prepareEdit() {
        
current = (MensajegetItems().getRowData();
        
selectedItemIndex pagination.getPageFirstItem() + getItems().getRowIndex();
        return 
"Edit";
    }

    public 
String update() {
        try {
            
getFacade().edit(current);
            
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("MensajeUpdated"));
            return 
"View";
        } catch (
Exception e) {
            
JsfUtil.addErrorMessage(eResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
            return 
null;
        }
    }

   
/*por acá el método destroy*/

    /*por acá el método destroyAndView() */

    
private void performDestroy() {
        try {
            
getFacade().remove(current);
            
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("MensajeDeleted"));
        } catch (
Exception e) {
            
JsfUtil.addErrorMessage(eResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
        }
    }

    
por acá metodo  updateCurrentItem()

 

    public 
DataModel getItems() {
        if (
items == null) {
            
items getPagination().createPageDataModel();
        }
        return 
items;
    }

 

    public 
String next() {
        
getPagination().nextPage();
        
recreateModel();
        return 
"List";
    }

    public 
String previous() {
        
getPagination().previousPage();
        
recreateModel();
        return 
"List";
    }

    public 
SelectItem[] getItemsAvailableSelectMany() {
        return 
JsfUtil.getSelectItems(ejbFacade.findAll(), false);
    }

    public 
SelectItem[] getItemsAvailableSelectOne() {
        return 
JsfUtil.getSelectItems(ejbFacade.findAll(), true);
    }

    @
FacesConverter(forClass Mensaje.class)
    public static class 
MensajeControllerConverter implements Converter {

        public 
Object getAsObject(FacesContext facesContextUIComponent componentString value) {
            if (
value == null || value.length() == 0) {
                return 
null;
            }
            
MensajeController controller = (MensajeControllerfacesContext.getApplication().getELResolver().
                    
getValue(facesContext.getELContext(), null"mensajeController");
            return 
controller.ejbFacade.find(getKey(value));
        }

        
java.lang.String getKey(String value) {
            
java.lang.String key;
            
key value;
            return 
key;
        }

        
String getStringKey(java.lang.String value) {
            
StringBuffer sb = new StringBuffer();
            
sb.append(value);
            return 
sb.toString();
        }

        public 
String getAsString(FacesContext facesContextUIComponent componentObject object) {
            if (
object == null) {
                return 
null;
            }
            if (
object instanceof Mensaje) {
                
Mensaje o = (Mensajeobject;
                return 
getStringKey(o.getIdMensaje());
            } else {
                throw new 
IllegalArgumentException("object " object " is of type " object.getClass().getName() + "; expected type: " MensajeController.class.getName());
            }
        }
    }

y luego yo en una de las vistas liste todos estos mensajes, (hasta acá todo bien):

código primefaces
Código PHP:

<h:outputText escape="false" value="#{bundle.ListMensajeEmpty}" rendered="#{mensajeController.items.rowCount == 0}"/>
                <
h:panelGroup rendered="#{mensajeController.items.rowCount > 0}">
                    <
h:outputText value="#{mensajeController.pagination.pageFirstItem + 1}..#{mensajeController.pagination.pageLastItem + 1}/#{mensajeController.pagination.itemsCount}"/>&nbsp;
                    <
h:commandLink action="#{mensajeController.previous}" value="#{bundle.Previous} #{mensajeController.pagination.pageSize}" rendered="#{mensajeController.pagination.hasPreviousPage}"/>&nbsp;
                    <
h:commandLink action="#{mensajeController.next}" value="#{bundle.Next} #{mensajeController.pagination.pageSize}" rendered="#{mensajeController.pagination.hasNextPage}"/>&nbsp;
                    <
h:dataTable value="#{mensajeController.items}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">
                        <
h:column>
                            <
f:facet name="header">
                                <
h:outputText value="#{bundle.ListMensajeTitle_idMensaje}"/>
                            </
f:facet>
                            <
h:outputText value="#{item.idMensaje}"/>
                        </
h:column>
                        <
h:column>
                            <
f:facet name="header">
                                <
h:outputText value="#{bundle.ListMensajeTitle_mensaje}"/>
                            </
f:facet>
                            <
h:outputText value="#{item.mensaje}"/>
                        </
h:column>
                        <
h:column>
                            <
f:facet name="header">
                                <
h:outputText value="#{bundle.ListMensajeTitle_fecha}"/>
                            </
f:facet>
                            <
h:outputText value="#{item.fecha}">
                                <
f:convertDateTime pattern="MM/dd/yyyy" />
                            </
h:outputText>
                        </
h:column>
                        <
h:column>
                            <
f:facet name="header">
                                <
h:outputText value="#{bundle.ListMensajeTitle_idUsuario}"/>
                            </
f:facet>



  <
h:outputText value="#{item.idUsuario}"/> /* acá necesito es  el nombre del usuario(con ese Id) que esta en otro entity*/


                        
</h:column>
                        <
h:column>
                            <
f:facet name="header">
                                <
h:outputText value="#{bundle.ListMensajeTitle_idTipomensaje}"/>
                            </
f:facet>
                           <
h:outputText value="#{item.idTipomensaje}"/>
                       </
h:column>
                        <
h:column>
                            <
f:facet name="header">
                                <
h:outputText value="&nbsp;"/>
                            </
f:facet>
                            <
h:commandLink action="#{mensajeController.prepareView}" value="#{bundle.ListMensajeViewLink}"/>
                            <
h:outputText value=" "/>
                            <
h:commandLink action="#{mensajeController.prepareEdit}" value="#{bundle.ListMensajeEditLink}"/>
                            <
h:outputText value=" "/>
                            <
h:commandLink action="#{mensajeController.destroy}" value="#{bundle.ListMensajeDestroyLink}"/>
                        </
h:column>
                    </
h:dataTable

tengo un problema con lo que señale (en comentarios) en el código anterior, y es que no necesito el ide del usuario que digitó el mensaje, lo que necesito es su nombre, pero no se como obtener este valor pues esta en otra tabla osea otro entity..

agradezco sus recomendaciones... para poder entender mejor este funcionamiento.
__________________
Hay una fuerza motriz más poderosa que el vapor, la electricidad y la energía atómica: la voluntad. -Einstein-

Etiquetas: ejb, ejb3, jfs, jsp, netbeans, primefaces
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:30.