1 Reply Latest reply on Jun 6, 2008 9:20 PM by sudeval

    Parameters restored in EntityQuery with RESTRICTIONs

    sudeval

      Hi,
      Why my parameters restored in my EntityQuery with restriction ?



      ...
      <h:form id="formBuscaProjeto" styleClass="edit">
          <rich:simpleTogglePanel label="Parâmetros da Busca" switchType="ajax">
            <s:decorate template="layout/display.xhtml">
              <ui:define name="label">Título:</ui:define>
           <h:inputText id="tituloProjetoParam" value="#{projetoList.projeto.titulo}"/>
             </s:decorate>
             <s:decorate template="layout/display.xhtml">
               <ui:define name="label">Período Execução:</ui:define>
               <h:inputText value="#{projetoList.projeto.dataPrevisaoInicio}">
                  <f:convertDateTime type="date" pattern="dd/MM/yyyy"/>
                </h:inputText>
              </s:decorate>
              <s:decorate template="layout/display.xhtml">
             <ui:define name="label">Status:</ui:define>
                <h:selectOneMenu value="#{projetoList.projeto.statusProjeto}">
                   <s:selectItems var="statusProjeto"
                                value="#{statusProjetoList.resultList}"
                                label="#{statusProjeto.nome}"
                     noSelectionLabel="selecione um status..."/>
                   <s:convertEntity/>
                </h:selectOneMenu>                           
              </s:decorate>                                  
         </rich:simpleTogglePanel>
         <div class="actionButtons">
             <h:commandButton id="buscar" value="Buscar" action="/projetoList.xhtml"/>
         </div>
      </h:form>
      
      <rich:panel>
              <f:facet name="header">Lista de Projetos</f:facet>        
              <div class="results">
                  
                  <h:dataTable id="projetoList" var="projeto"
                            value="#{projetoList.resultList}" 
                         rendered="#{not empty projetoList.resultList}">
                      <h:column>
                          <f:facet name="header">Unidade</f:facet>
                          inserir unidade op.
                      </h:column>
                      <h:column>
                          <f:facet name="header">Programa</f:facet>
                          #{projeto.enquadramentoProjeto.programa.nome}
                      </h:column>                
                      <h:column>
                          <f:facet name="header">Título</f:facet>
                          <s:link id="projeto" 
                               value="#{projeto.titulo}" 
                               view="/projeto.xhtml">
                              <f:param name="projetoId" 
                                      value="#{projeto.id}"/>
                          </s:link>
                      </h:column>
                      <h:column>
                          <f:facet name="header">Status</f:facet>
                          #{projeto.statusProjeto.nome}
                      </h:column>
                      <h:column>
                          <f:facet name="header">Usuário</f:facet>
                          #{projeto.usuario.nomeUsuario}
                      </h:column>
                      <h:column>
                          <f:facet name="header">Previsão Início</f:facet>
                          <h:outputText value="#{projeto.dataPrevisaoInicio}">
                                    <f:convertDateTime type="date" pattern="dd/MM/yyyy"/>
                               </h:outputText>                    
                      </h:column>
                      <h:column>
                          <f:facet name="header">Previsão Fim</f:facet>
                          <h:outputText value="#{projeto.dataPrevisaoFim}">
                                    <f:convertDateTime type="date" pattern="dd/MM/yyyy"/>
                               </h:outputText>                                        
                      </h:column>
                  </h:dataTable>        
              </div>
              <div class="controleBusca">
                   <s:link view="/projetoList.xhtml" rendered="#{projetoList.previousExists}" value="Primeira Página">
                         <f:param name="firstResult" value="0"/>
                     </s:link>
                     
                     <s:link view="/projetoList.xhtml" rendered="#{projetoList.previousExists}" value="Anterior">
                         <f:param name="firstResult" value="#{projetoList.previousFirstResult}"/>
                     </s:link>
                     
                     <s:link view="/projetoList.xhtml" rendered="#{projetoList.nextExists}" value="Próxima">
                         <f:param name="firstResult" value="#{projetoList.nextFirstResult}"/>
                     </s:link>
                     
                     <s:link view="/projetoList.xhtml" rendered="#{projetoList.nextExists}" value="Última Página">
                         <f:param name="firstResult" value="#{projetoList.lastFirstResult}"/>
                     </s:link>
                </div>
                
                <h:outputText value="Não existe Projeto cadastrado" 
                             rendered="#{empty projetoList.resultList}"/>
          </rich:panel>
          
          <div class="actionButtons">
              <s:button id="done" 
                     value="Novo Projeto"
                     title="Cadastrar Novo Projeto"
                     view="/projeto.xhtml"/>                 
          </div>
      ...



      and my EntityQuery



      @Name("projetoList")
      public class ProjetoList extends EntityQuery<Projeto> {
               
           private static final long serialVersionUID = 1L;
           
           private static final String[] RESTRICTIONS = {
                "lower(projeto.titulo) like concat(lower(#{projetoList.projeto.titulo}),'%') ",
                "projeto.unidadeOperacional.id = (#{projetoList.projeto.unidadeOperacional.id}) ",
                "projeto.enquadramentoProjeto.programa.id = (#{projetoList.projeto.enquadramentoProjeto.programa.id}) ",          
                "projeto.statusProjeto.id = (#{projetoList.projeto.statusProjeto.id}) ",
                "projeto.dataPrevisaoInicio = (#{projetoList.projeto.dataPrevisaoInicio}) "
                };
           
      
           private Projeto projeto = new Projeto();
      
           @Override
              public String getEjbql() { 
                 return "select projeto from Projeto projeto";
              }
           
           @Override
           public Integer getMaxResults() {          
                return 20;
           }     
           
           public Projeto getProjeto() {
                return this.projeto;
           }
           
           @Override
           public List<String> getRestrictions() {
                return Arrays.asList(RESTRICTIONS);
           }
      



      and when i execute the commandButton Buscar( projetoList.resultSet).


      14:51:03,636 INFO  [STDOUT] Hibernate: 
          select
              top 5 projeto0_.id as id95_,
              projeto0_.titulo as titulo95_,
              projeto0_.justificativa as justific3_95_,
              projeto0_.metodologia as metodolo4_95_,
              projeto0_.objetivoGeral as objetivo5_95_,
              projeto0_.publicoAlvo as publicoA6_95_,
              projeto0_.resultadoDesejado as resultad7_95_,
              projeto0_.dataPrevisaoInicio as dataPrev8_95_,
              projeto0_.dataPrevisaoFim as dataPrev9_95_,
              projeto0_.idUsuario as idUsuario95_,
              projeto0_.idUnidadeOperacional as idUnida10_95_,
              projeto0_.idEnquadramentoProjeto as idEnqua13_95_,
              projeto0_.idStatus as idStatus95_ 
          from
              Projeto projeto0_ 
          where
              lower(projeto0_.titulo) like (lower(?)+'%')
      14:51:03,714 INFO  [STDOUT] Hibernate: 
          select
              top 5 projeto0_.id as id95_,
              projeto0_.titulo as titulo95_,
              projeto0_.justificativa as justific3_95_,
              projeto0_.metodologia as metodolo4_95_,
              projeto0_.objetivoGeral as objetivo5_95_,
              projeto0_.publicoAlvo as publicoA6_95_,
              projeto0_.resultadoDesejado as resultad7_95_,
              projeto0_.dataPrevisaoInicio as dataPrev8_95_,
              projeto0_.dataPrevisaoFim as dataPrev9_95_,
              projeto0_.idUsuario as idUsuario95_,
              projeto0_.idUnidadeOperacional as idUnida10_95_,
              projeto0_.idEnquadramentoProjeto as idEnqua13_95_,
              projeto0_.idStatus as idStatus95_ 
          from
              Projeto projeto0_
      14:51:03,761 INFO  [STDOUT] Hibernate: 
          select
              statusproj0_.id as id100_,
              statusproj0_.nome as nome100_ 
          from
              StatusProjeto statusproj0_
      14:51:03,792 INFO  [STDOUT] Hibernate: 
          select
              count(*) as col_0_0_ 
          from
              Projeto projeto0_
      



      i think that my parameters restored, but why it´s happened?


        • 1. Re: Parameters restored in EntityQuery with RESTRICTIONs
          sudeval

          hi, i create an projetoList.page.xml and resolved my problem :D



          <?xml version="1.0" encoding="UTF-8"?>
          <page xmlns="http://jboss.com/products/seam/pages"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd">
          
             <param name="firstResult" value="#{projetoList.firstResult}"/>
             <param name="order" value="#{projetoList.order}"/>
             <param name="from"/>
             <param name="titulo" value="#{projetoList.projeto.titulo}"/>
          </page>
          



          thanks :D



          but i dont know do restriction with Collections...
          for example:


          Company x Employee


          @Entity
          Company {
            List<Employee> employee;
          }
          




          how i do in RESTRICTIONS rules(EntityQuery) and in PARAM (entityList.page.xml) ?