[seam-dev] In list.xhtml.ftl, what is the point of the foreach for the create button if Pages.applyConvertedValidatedValuesToMode cannot deal with nulls in parameters?

Pete Muir pmuir at redhat.com
Sat Dec 13 14:38:37 EST 2008


I can't follow your description, just create a patch showing the  
changes you want.

On 8 Dec 2008, at 16:52, Francisco Jose Peredo wrote:

> Hi!
> The code for the create button in list.xhtml.ftl looks like this:
>
> <s:div styleClass="actionButtons" rendered="${'#'}{empty from}">
>         <s:button view="/${editPageName}.xhtml"
>                     id="create"
>            propagation="none"
>                  value="Create ${componentName}">
> <#assign idName = componentName + pojo.identifierProperty.name? 
> cap_first>
> <#if c2j.isComponent(pojo.identifierProperty)>
> <#foreach componentProperty in  
> pojo.identifierProperty.value.propertyIterator>
> <#assign cidName = componentName + componentProperty.name?cap_first>
>             <f:param name="${cidName}"/>
> </#foreach>
> <#else>
>             <f:param name="${idName}"/>
> </#if>
>         </s:button>
>     </s:div>
>
> That generates a <f:param name="${idName}"/> for the primarykey(s).  
> Why is that done? My best guess is that it is to clear the value
> of the primary key for the new object that is going to be created.
>
> But the <f:param name="${idName}"/> actually does nothing, because  
> in seam it is impossible to set a parameter to null. This f:params  
> are AFAIK expected to set the method generated in EntityHome.java.ftl:
>
>  public void set${idName}(${idType} id)
>     {
>         setId(id);
>     }
>
> But that set is never going to be called for <f:param name="$ 
> {idName}"/> because the id value is null! And there is code to  
> prevent set${idName}(${idType} id) from being called if the value  
> for the id is going to be null in  
> Pages.applyConvertedValidatedValuesToMode:
>
> private void applyConvertedValidatedValuesToModel(FacesContext  
> facesContext)
>    {
>       String viewId = getViewId(facesContext);
>       for ( Page page: getPageStack(viewId) )
>       {
>          for ( Param pageParameter: page.getParameters() )
>          {
>             ValueExpression valueExpression =  
> pageParameter.getValueExpression();
>             if (valueExpression!=null)
>             {
>                Object object =  
> Contexts.getEventContext().get( pageParameter.getName() );
>                if (object!=null) //<--- HERE IS THE PROBLEM
>                {
>                   valueExpression.setValue(object);
>                }
>             }
>          }
>       }
>    }
>
> Of course, it gives the impression it works, but that is just  
> because our EntityHome is recently created and the value for the Id  
> is initially null. But if we place our EntityHome inside a LRC, and  
> try to use after a previous creation set the value of the Id, we  
> will see that the Id is not reset to null by the <f:param name="$ 
> {idName}"/>
>
> A workaround I use when the id is Integer is this the -1 value:
>
> <f:param name="${idName}" value="-1"/>
>
>  public void set${idName}(${idType} id)
>     {
>         if(id<0){
>              setId(null);
>         }else{
>             setId(id);
>         }
>     }
>
> But that, as it was commented in another null related discussion, a  
> really ugly way to deal with stuff we want to be "undefined". So  
> what can be done to fix this in Seam/seam-gen? (And of course offer  
> a solution that can be used as a "best practice" for dealing with  
> this even in applications that do not use seam-gen).
>
> I propose removing the if (object!=null) from  
> applyConvertedValidatedValuesToModel (and maybe other methods in  
> Pages that avoid dealing with nulls in the same limited way? like  
> perhaps convertAndValidateStringValuesInPageContext? and  
> getStringValuesFromModel? and storeRequestStringValuesInPageContext?  
> and possibly others...).
>
> Now, if ignoring null values for page parameters in this way is not  
> a bug, but a feature, then I propose removing the foreach for the  
> create button list.xhtml.ftl, because it just creates the false  
> impression that  <f:param name="${idName}"/> actually does something.
>
> I already created a related JIRA a while ago (https://jira.jboss.org/jira/browse/JBSEAM-3693 
> ) but guess I was not able to correctly explain this problem, I hope  
> to have better luck this time.
>
> Regards,
> Francisco Peredo
>
>
> -- 
> Dirección Informática de Servicios Financieros
> Dirección General de Modernización e Innovación Gubernamental
> Secretaría de Administración y Finanzas
> Paseo de la Sierra 435 col. Reforma
> C.P. 86086, Villahermosa, Tabasco.
> Tel. 52 + 993 + 310 40 00 Ext. 7127
> http://saf.tabasco.gob.mx/
>
> IMPORTANTE: Esta transmisión electrónica, incluyendo sus anexos,  
> archivos insertados o "attachments", puede constituir información  
> confidencial o reservada, en los términos de la Ley de Acceso a la  
> Información Pública del Estado de Tabasco, y estar protegida por el  
> derecho fundamental a la privacidad. Se prohibe el uso de esta  
> información por cualquier persona distinta al receptor intencional o  
> previsto. Si usted ha recibibido esta transmisión electrónica por  
> error, por favor responda inmediatamente al emisor y borre esta  
> información de su sistema. El uso, diseminación, distribución o  
> reproducción de esta transmisión electrónica por receptores no  
> intencionados o no previstos por el emisor, no está autorizada y  
> puede considerarse ilícita en los términos de la legislación penal y  
> civil vigente.
> _______________________________________________
> seam-dev mailing list
> seam-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/seam-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/seam-dev/attachments/20081213/cb6e3bca/attachment.html 


More information about the seam-dev mailing list