<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body 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="actionButtons" rendered="${'#'}{empty from}"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;s:button view="/${editPageName}.xhtml"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id="create"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; propagation="none"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; value="Create ${componentName}"&gt;<br>
&lt;#assign idName = componentName +
pojo.identifierProperty.name?cap_first&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>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;f:param name="${cidName}"/&gt;<br>
&lt;/#foreach&gt;<br>
&lt;#else&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;f:param name="${idName}"/&gt;<br>
&lt;/#if&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/s:button&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/s:div&gt;<br>
<br>
That generates a &lt;f:param name="${idName}"/&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="${idName}"/&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>
&nbsp;public void set${idName}(${idType} id)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setId(id);<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
But that set is never going to be called for &lt;f:param
name="${idName}"/&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>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String viewId = getViewId(facesContext);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for ( Page page: getPageStack(viewId) )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for ( Param pageParameter: page.getParameters() )<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ValueExpression valueExpression =
pageParameter.getValueExpression();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (valueExpression!=null)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b> Object object = Contexts.getEventContext().get(
pageParameter.getName() );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (object!=null) //&lt;--- HERE IS THE PROBLEM<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; valueExpression.setValue(object);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</b><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp; }<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="${idName}"/&gt;<br>
<br>
A workaround I use when the id is Integer is this the -1 value: <br>
<br>
&lt;f:param name="${idName}" value="-1"/&gt;<br>
<br>
&nbsp;public void set${idName}(${idType} id)<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(id&lt;0){<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; setId(null);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }else{<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; setId(id);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<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 "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). <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&nbsp; &lt;f:param name="${idName}"/&gt; actually does something.<br>
<br>
I already created a related JIRA a while ago
(<a class="moz-txt-link-freetext" href="https://jira.jboss.org/jira/browse/JBSEAM-3693">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 class="moz-signature" cols="72">-- 
Direcci&oacute;n Inform&aacute;tica de Servicios Financieros
Direcci&oacute;n General de Modernizaci&oacute;n e Innovaci&oacute;n Gubernamental
Secretar&iacute;a de Administraci&oacute;n y Finanzas
Paseo de la Sierra 435 col. Reforma
C.P. 86086, Villahermosa, Tabasco.
Tel. 52 + 993 + 310 40 00 Ext. 7127
<a class="moz-txt-link-freetext" href="http://saf.tabasco.gob.mx/">http://saf.tabasco.gob.mx/</a>

IMPORTANTE: Esta transmisi&oacute;n electr&oacute;nica, incluyendo sus anexos, archivos insertados o "attachments", puede constituir informaci&oacute;n confidencial o reservada, en los t&eacute;rminos de la Ley de Acceso a la Informaci&oacute;n P&uacute;blica del Estado de Tabasco, y estar protegida por el derecho fundamental a la privacidad. Se prohibe el uso de esta informaci&oacute;n por cualquier persona distinta al receptor intencional o previsto. Si usted ha recibibido esta transmisi&oacute;n electr&oacute;nica por error, por favor responda inmediatamente al emisor y borre esta informaci&oacute;n de su sistema. El uso, diseminaci&oacute;n, distribuci&oacute;n o reproducci&oacute;n de esta transmisi&oacute;n electr&oacute;nica por receptores no intencionados o no previstos por el emisor, no est&aacute; autorizada y puede considerarse il&iacute;cita en los t&eacute;rminos de la legislaci&oacute;n penal y civil vigente.</pre>
</body>
</html>