Validation and hidden input problem

Hi..

Unfortunatelly, I have a request-scoped bean and a simple edit form:

<h:form>

<h:inputHidden id="id" value="#{ItemBean.selectedId}"/>

<h:panelGrid columns="3" styleClass="InnerGrid">

<f:facet name="header">

<h:panelGroup>

<h:outputText value="#{msg.NewRecord}"

rendered="#{ItemBean.selectedId == 0}" />

<h:outputText value="#{msg.EditRecord}"

rendered="#{ItemBean.selectedId != 0}" />

</h:panelGroup>

</f:facet>

<h:outputText value="#{msg.Name}:" />

<h:inputText id="name" value="#{ItemBean.Item.name}"

maxlength="50" required="true"/>

<h:message for="name" styleClass="Error" />

<h:outputText value="#{msg.Stock}:" />

<h:inputText id="stock" value="#{ItemBean.Item.stock}"

maxlength="5" required="true"/>

<h:message for="stock" styleClass="Error" />

</h:panelGrid>

<h:commandButton styleClass="Button" value="#{msg.Submit}"

action="#{ItemBean.saveOrUpdate}"/>

</h:form>

If any validation/conversation error occurs value ofItemBean.selectedId disappears. (Since values are not submitted)

How can I saveItemBean.selectedId if a If any validation/conversation error occurs ?

thanks.

[2029 byte] By [GBerberoglua] at [2007-11-26 16:21:58]
# 1
I suggest you to put it in the DTO called "Item".Also see http://balusc.xs4all.nl/srv/dev-jep-dat.html#ShowSelectedDataItem
BalusCa at 2007-7-8 22:45:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Ok thats strange,

<input id="body:j_id_jsp_1532320384_12i2:id" type="hidden" name="body:j_id_jsp_1532320384_12i2:id" value="12" />

I can see that hidden value is saved so I expect "EditRecord" to be rendered. But instead, "NewRecord" is rendered.. why!?!? (and how can I fix it ?)

<h:panelGroup>

<h:outputText value="#{msg.NewRecord}" rendered="#{ItemBean.Item.id == 0}" />

<h:outputText value="#{msg.EditRecord}" rendered="#{ItemBean.Item.id != 0}" />

</h:panelGroup>

GBerberoglua at 2007-7-8 22:45:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Which value type is the id? int? Integer? String?
BalusCa at 2007-7-8 22:45:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Integer.

and here is my complete code:

<h:form>

<h:dataTable id="items" value="#{ItemBean.allItems}"

var="item" styleClass="List" headerClass="ListHeader"

rowClasses="EvenRow,OddRow" rendered="#{ItemBean.item.id == 0}"

binding="#{ItemBean.dataTable}">

<h:column>

<f:facet name="header">

<h:outputText value="#{msg.Name}" />

</f:facet>

<h:outputText value="#{item.name}" />

</h:column>

<h:column>

<f:facet name="header">

<h:outputText value="#{msg.Stock}" />

</f:facet>

<h:outputText value="#{item.stock}" />

</h:column>

<h:column>

<f:facet name="header">

<h:outputText value="" />

</f:facet>

<h:commandLink value="#{msg.Edit}" action="#{ItemBean.select}"

/>

</h:column>

</h:dataTable>

</h:form>

<h:form>

<h:inputHidden id="id" value="#{ItemBean.item.id}"/>

<h:panelGrid columns="3" styleClass="InnerGrid">

<f:facet name="header">

<h:panelGroup>

<h:outputText value="#{msg.NewRecord}"

rendered="#{ItemBean.item.id == 0}" />

<h:outputText value="#{msg.EditRecord}"

rendered="#{ItemBean.item.id != 0}" />

</h:panelGroup>

</f:facet>

<h:outputText value="#{msg.Name}:" />

<h:inputText id="name" value="#{ItemBean.item.name}"

maxlength="50" required="true"/>

<h:message for="name" styleClass="Error" />

<h:outputText value="#{msg.Stock}:" />

<h:inputText id="stock" value="#{ItemBean.item.stock}"

maxlength="5" required="true"/>

<h:message for="stock" styleClass="Error" />

</h:panelGrid>

<h:commandButton styleClass="Button" value="#{msg.Submit}"

action="#{ItemBean.saveOrUpdate}"/>

</h:form>

GBerberoglua at 2007-7-8 22:45:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...