I actually came across this issue while working on the design of view parameters for JSF 2.0. It&#39;s a tricky problem because sometimes you just want the parameter to be discarded if it is null and sometimes you want that null value to clear the property on the model.<br>
<br>If we think about the goal of page parameters, they are there to map an inbound request parameter to the property of a model. The mapping is there to kick things off. The absence of a request parameter cannot be assumed to mean that you want to nullify the model. Otherwise, the page parameters would always be required and thus overstepping their bounds (which is exactly the situation you have with using them w/ a long-running conversation). If you want to clear the model out of the conversation, you should be using a command, whether it be a command button or a page action. Only then can you be sure that setting the value to null is the desired operation. You can easily pass a parameter hint like create=true to tell the page action to clear out any previous model value and start with a fresh form.<br>
<br>Keep in mind that the application seam-gen creates is a starting point, not a design best practice. If the button it creates is not handling the situation properly, then add some extra code to make it work.<br><br>-Dan<br>
<br><div class="gmail_quote">On Mon, Dec 8, 2008 at 12:52 PM, Francisco Jose Peredo <span dir="ltr">&lt;<a href="mailto:franciscoperedo@tabasco.gob.mx">franciscoperedo@tabasco.gob.mx</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">




<div bgcolor="#ffffff" text="#000000">
Hi!<br>
The code for the create button in list.xhtml.ftl looks like this:<br>
<br>
&lt;s:div styleClass=&quot;actionButtons&quot; rendered=&quot;${&#39;#&#39;}{empty from}&quot;&gt;<br>
        &lt;s:button view=&quot;/${editPageName}.xhtml&quot;<br>
                    id=&quot;create&quot;<br>
           propagation=&quot;none&quot;<br>
                 value=&quot;Create ${componentName}&quot;&gt;<br>
&lt;#assign idName = componentName +
<a href="http://pojo.identifierProperty.name?cap_first" target="_blank">pojo.identifierProperty.name?cap_first</a>&gt;<br>
&lt;#if c2j.isComponent(pojo.identifierProperty)&gt;<br>
&lt;#foreach componentProperty in
pojo.identifierProperty.value.propertyIterator&gt;<br>
&lt;#assign cidName = componentName +
componentProperty.name?cap_first&gt;<br>
            &lt;f:param name=&quot;${cidName}&quot;/&gt;<br>
&lt;/#foreach&gt;<br>
&lt;#else&gt;<br>
            &lt;f:param name=&quot;${idName}&quot;/&gt;<br>
&lt;/#if&gt;<br>
        &lt;/s:button&gt;<br>
    &lt;/s:div&gt;<br>
<br>
That generates a &lt;f:param name=&quot;${idName}&quot;/&gt; for the
primarykey(s). Why is that done? My best guess is that it is to clear
the value <br>
of the primary key for the new object that is going to be created.<br>
<br>
But the &lt;f:param name=&quot;${idName}&quot;/&gt; 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:<br>
<br>
 public void set${idName}(${idType} id)<br>
    {<br>
        setId(id);<br>
    }<br>
<br>
But that set is never going to be called for &lt;f:param
name=&quot;${idName}&quot;/&gt; 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:<br>
<br>
private void applyConvertedValidatedValuesToModel(FacesContext
facesContext)<br>
   {<br>
      String viewId = getViewId(facesContext);<br>
      for ( Page page: getPageStack(viewId) )<br>
      {<br>
         for ( Param pageParameter: page.getParameters() )<br>
         {         <br>
            ValueExpression valueExpression =
pageParameter.getValueExpression();<br>
            if (valueExpression!=null)<br>
            {<br>
              <b> Object object = Contexts.getEventContext().get(
pageParameter.getName() );<br>
               if (object!=null) //&lt;--- HERE IS THE PROBLEM<br>
               {<br>
                  valueExpression.setValue(object);<br>
               }</b><br>
            }<br>
         }<br>
      }<br>
   }<br>
<br>
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 &lt;f:param name=&quot;${idName}&quot;/&gt;<br>
<br>
A workaround I use when the id is Integer is this the -1 value: <br>
<br>
&lt;f:param name=&quot;${idName}&quot; value=&quot;-1&quot;/&gt;<br>
<br>
 public void set${idName}(${idType} id)<br>
    {<br>
        if(id&lt;0){<br>
             setId(null);<br>
        }else{<br>
            setId(id);<br>
        }<br>
    }<br>
<br>
But that, as it was commented in another null related discussion, a
really ugly way to deal with stuff we want to be &quot;undefined&quot;. So what
can be done to fix this in Seam/seam-gen? (And of course offer a
solution
that can be used as a &quot;best practice&quot; for dealing with this even in
applications that do not use seam-gen). <br>
<br>
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...).<br>
<br>
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  &lt;f:param name=&quot;${idName}&quot;/&gt; actually does something.<br>
<br>
I already created a related JIRA a while ago
(<a href="https://jira.jboss.org/jira/browse/JBSEAM-3693" target="_blank">https://jira.jboss.org/jira/browse/JBSEAM-3693</a>) but guess I was not
able to correctly explain this problem, I hope to have better luck this
time.<br>
<br>
Regards,<br>
Francisco Peredo<br>
<br>
<br>
<pre cols="72">-- 
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
<a href="http://saf.tabasco.gob.mx/" target="_blank">http://saf.tabasco.gob.mx/</a>

IMPORTANTE: Esta transmisión electrónica, incluyendo sus anexos, archivos insertados o &quot;attachments&quot;, 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.</pre>

</div>

<br>_______________________________________________<br>
seam-dev mailing list<br>
<a href="mailto:seam-dev@lists.jboss.org">seam-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/seam-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/seam-dev</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Dan Allen<br>Senior Software Engineer, Red Hat | Author of Seam in Action<br><br><a href="http://mojavelinux.com">http://mojavelinux.com</a><br><a href="http://mojavelinux.com/seaminaction">http://mojavelinux.com/seaminaction</a><br>
<br>NOTE: While I make a strong effort to keep up with my email on a daily<br>basis, personal or other work matters can sometimes keep me away<br>from my email. If you contact me, but don&#39;t hear back for more than a week,<br>
it is very likely that I am excessively backlogged or the message was<br>caught in the spam filters.  Please don&#39;t hesitate to resend a message if<br>you feel that it did not reach my attention.<br>