Solo formulario new.xhtml no usar list.xhtml ni el view.xhtml

Solo formulario new.xhtml no usar list.xhtml ni el view.xhtml

  • Solo creamos el fomulario new.xhtml

  • No se crea list.xtml. ni view.xhtml

  • No usamos el componente <a:new

  • Quitar el render con entityController.writable

  • Se invoca el formulario new.xhtml desde el menú.

  • Ajustar el init() para verificar que este vació o no para mostrar los datos y asignar true o false a writable

  • Solo se usara el botón Guardar, y en el método save() se verifica si es para guardar o editar.

Controller

init()

    @PostConstruct
    public void init() {
        try {
            writable = false;
            Integer count = porcentajemorosidadRepository.count();
            if (count.equals(0)) {
                porcentajemorosidad = new Porcentajemorosidad();
                writable = true;
            }else{
                List<Porcentajemorosidad> list = porcentajemorosidadRepository.findAll();
                porcentajemorosidad = new Porcentajemorosidad();
                if(!list.isEmpty()){
                    porcentajemorosidad = list.get(0);
                }
            }
        } catch (Exception e) {
            errorServices.errorMessage(nameOfClass(), nameOfMethod(), e.getLocalizedMessage());
        }
    }// </e

save()

 @Override
    public String save() {
        try {
            if (writable) {
                Integer identity = autoincrementableStoreejbServices.getContador("porcentajemorosidad");
                porcentajemorosidad.setIdporcentajemorosidad(identity);

                porcentajemorosidad.setUserInfo(userInfoServices.generateListUserinfo(loginController.getUsername(), "create"));

                if (porcentajemorosidadRepository.save(porcentajemorosidad)) {
                    revisionHistoryStoreejbRepository.save(revisionHistoryServices.getRevisionHistory(porcentajemorosidad.getIdporcentajemorosidad().toString(), loginController.getUsername(),
                            "create", "porcentajemorosidad", porcentajemorosidadRepository.toDocument(porcentajemorosidad).toString()));
                    JsfUtil.successMessage(rf.getAppMessage("info.save"));
                  writable=false;

                } else {
                    JsfUtil.successMessage("save() " + porcentajemorosidadRepository.getException().toString());
                }

            } else {
                porcentajemorosidad.getUserInfo().add(userInfoServices.generateUserinfo(loginController.getUsername(), "update"));

                revisionHistoryStoreejbRepository.save(revisionHistoryServices.getRevisionHistory(porcentajemorosidad.getIdporcentajemorosidad().toString(), loginController.getUsername(),
                        "update", "porcentajemorosidad", porcentajemorosidadRepository.toDocument(porcentajemorosidad).toString()));

               if(porcentajemorosidadRepository.update(porcentajemorosidad)){
                         JsfUtil.successMessage(rf.getAppMessage("info.update"));
               }else {
                    JsfUtil.successMessage("update() " + porcentajemorosidadRepository.getException().toString());
               }
                //        articuloServices.changePorcentajemorosidad(porcentajemorosidad);

            }


        } catch (Exception e) {
            errorServices.errorMessage(nameOfClass(), nameOfMethod(), e.getLocalizedMessage());
        }
        return "";
    }// </editor-fold>

new.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<ui:composition template="/layout/template.xhtml" 
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:b="http://bootsfaces.net/ui"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                xmlns:a="http://xmlns.jcp.org/jsf/composite/avbravo"> 
    <ui:define name="content">
        <!--<h:outputStylesheet library="bsf" name="css/thumbnails.css"/>-->

        <style>
            .thumbnail { max-width: 100%; }
            img.thumbnail:hover, img.thumbnail:focus {
                border: 1px solid;
                border-color: #428BCA;
            }
        </style>

        <b:form id="form"  prependId="false"  rendered="#{loginController.loggedIn and applicationMenu.porcentajemorosidad.create}" onkeypress="if (event.keyCode == 13) {
                    return false;
                }">
            <h:panelGroup id="content" layout="block"> 

                <a:messages id="msg"/>

                <b:panel title="#{msg['titleview.porcentajemorosidad']}" look="primary" >



                    <b:panelGrid id="panel" colSpans="2,10" size="xs" > 
                        <p:outputLabel  value="#{msg['field.porcentaje']}" />
                        <a:inputText value="#{porcentajemorosidadController.porcentajemorosidad.porcentajemorosidad}" id="porcentajemorosidad" span="2" label="#{msg['field.porcentajemorosidad']}" />


                        <p:outputLabel  value="#{msg['field.activo']}" />
                        <a:yesno value="#{porcentajemorosidadController.porcentajemorosidad.activo}" id="activo"  required="true"/>


                        <a:save rendered="#{applicationMenu.porcentajemorosidad.create}"
                                save="#{porcentajemorosidadController.save()}" />


                    </b:panelGrid>


                </b:panel>
            </h:panelGroup>
        </b:form>
        <a:denegado renderedcondition="#{!loginController.loggedIn or !applicationMenu.porcentajemorosidad.create}" />

        <br/><br/><br/>
    </ui:define>
</ui:composition>

Last updated