0 Replies Latest reply on Aug 21, 2008 8:52 PM by Maykell Frómeta

    strange behavior around page parameters

    Maykell Frómeta Newbie

      Hi all, i have a doubt about a behavior that i have seen in Seam and i haven´t answer to it.
      I have a little application with a typical list page and a typical detail page, i want the detail page serve to make inserts and updates; in order to this i have to pass the element id as a request parameter from the list page to the detail page, and besides put a page descriptor in the detail page side to catch the id. I did it and everything works ok, but i was surprised when i just for curiosity drop the h:param from the list page and thus no pass anymore the id to the detail page, but in some manner i can´t explain the id still kept on arriving to the detail page.


      How can it be possible?


      this is my code:
      the list page:


      <!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:s="http://jboss.com/products/seam/taglib"
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:rich="http://richfaces.org/rich" template="layout/template.xhtml">
      
              <ui:define name="body">
      
                      <h:messages globalOnly="true" styleClass="message" />
      
                      <rich:panel>
                              <f:facet name="header">acusadoList</f:facet>
      
                              <div class="results"><h:outputText value="No acusado exists"
                                      rendered="#{empty acusadoList.resultList}" /> <h:dataTable
                                      id="acusadoList" var="acusado" value="#{acusadoList.resultList}"
                                      rendered="#{not empty acusadoList.resultList}" cellpadding="2">
                                      <h:column>
                                              <f:facet name="header">CI</f:facet>
                          #{acusado.id}
                      </h:column>
      
                                      <h:column>
                                              <f:facet name="header">Nombre</f:facet>
                          <s:link id="nombreLink" value="#{acusado.nombre}" view="/registerAcusado.xhtml"/>
                      </h:column>
      
                                      <h:column>
                                              <f:facet name="header">Direccion</f:facet>
                          #{acusado.direccionParticular}
                      </h:column>
      
                                      <h:column>
                                              <f:facet name="header">Desc Fisica</f:facet>
                          #{acusado.descripcionFisica}
                                      </h:column>
      
                              </h:dataTable></div>
      
                      </rich:panel>
      
                      <div class="actionButtons"><s:button id="done"
                              value="Create acusado" view="/registerAcusado.xhtml" /></div>
      
              </ui:define>
      
      </ui:composition>
      



      the detail page:


      <!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:s="http://jboss.com/products/seam/taglib"
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:rich="http://richfaces.org/rich"
              xmlns:a="http://richfaces.org/a4j" template="layout/template.xhtml">
      
              <ui:define name="body">
      
                      <h:messages globalOnly="true" styleClass="message" />
      
                      <h:form id="registerAcusadoActionForm">
                              <rich:panel>
                                      <f:facet name="header">Registrar Acusado</f:facet>
      
                                      <s:decorate id="ciDecoration" template="layout/edit.xhtml">
                                              <ui:define name="label">CI</ui:define>
                                              <h:inputText id="name" required="true" value="#{acusado.id}" />
                                      </s:decorate>
      
                                      <s:decorate id="nombreDecoration" template="layout/edit.xhtml">
                                              <ui:define name="label">Nombre</ui:define>
                                              <h:inputText id="nombre" required="true" value="#{acusado.nombre}" />
                                      </s:decorate>
      
                                      <s:decorate id="direcionDecorate" template="layout/edit.xhtml">
                                              <ui:define name="label">Direcion</ui:define>
                                              <h:inputText id="direccion" value="#{acusado.direccionParticular}" />
                                      </s:decorate>
      
                                      <s:decorate id="descFisicaDecorate" template="layout/edit.xhtml">
                                              <ui:define name="label">Descripcion Fisica</ui:define>
                                              <h:inputText id="desc" value="#{acusado.descripcionFisica}"></h:inputText>
                                      </s:decorate>
                                      <div style="clear: both" />
      
                              </rich:panel>
      
                              <div class="actionButtons"><h:commandButton
                                      id="registerAcusado" value="Registrar Acusado"
                                      action="#{registerAcusadoAction.registerAcusado(acusado)}" /></div>
                      </h:form>
              </ui:define>
      </ui:composition>
      
      the page descriptor for the detail page:
      <?xml version="1.0" encoding="UTF-8"?>
      <page login-required="false">
         
         <param name="nothing" value="#{acusado.id}"/>
         <action execute="#{registerAcusadoAction.loadAcusado}"/>
      </page>
      
      


      the code for registerAcusadoAction:


      package com.prueba.facade;
      
      import javax.persistence.EntityManager;
      import javax.persistence.NoResultException;
      import javax.persistence.NonUniqueResultException;
      
      import org.jboss.seam.Component;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.web.RequestParameter;
      import org.jboss.seam.log.Log;
      import org.jboss.seam.faces.FacesMessages;
      
      import com.prueba.domain.Acusado;
      
      @Name("registerAcusadoAction")
      public class RegisterAcusadoAction {
      
              @Logger
              private Log log;
              @In
              FacesMessages facesMessages;
              @In
              private EntityManager entityManager;
              @RequestParameter
              String acusadoId;
              
              @In @Out Acusado acusado;
      
              public void registerAcusado(Acusado acusadoLocal) {
                      entityManager.persist(acusadoLocal);
                      // implement your business logic here
                      log.info("registerAcusadoAction.registerAcusado() action called");
                      facesMessages.add("Acusado Registrado");
              }
      
              public void loadAcusado() {
                      if (acusadoId != null) {   
                              try {
                                      acusado = (Acusado) entityManager.createQuery(
                                                      "select r from Acusado r " + "where r.ci = :ci")
                                                      .setParameter("ci", acusadoId).getSingleResult();
                              } catch (NoResultException nre) {
                              } catch (NonUniqueResultException nure) {
                              }
                      }
              }
              // add additional action methods
      
      }