Monday, May 18, 2009

Different ways of using seam s:decorate and s:validate – Sample are based on Seamgen based applications.


 

1)    <s:decorate> without template attribute and with <s:validateAll>, requiredMessage, validateLength samples.

<s:decorate>

<s:validateAll>

<div class="prop">

<s:label id="editLabel" styleClass="#{invalid?'errors':''}">

created by

<s:span styleClass="required" rendered="true">*</s:span>

</s:label>

<span id="editSpan" class="#{invalid?'errors':''}">

invalid value > #{invalid}

<ice:inputText id="createdById" requiredMessage="This field value is required." partialSubmit="true" size="100" maxlength="130" value="#{userHome.instance.createdBy}">

<f:validateLength maximum="5" minimum="1" />

</ice:inputText>

</span>

<s:message styleClass="error errors" />

</div>

</s:validateAll>

</s:decorate>


 

Note: The reason being used s:decorate is that #{invalid} and #{required} are available inside s:decorate; #{required} evaluates to true if you have set the input component being decorated as required, and #{invalid} evaluates to true if a validation error occurs.


 


 

2)    <s:decorate> without template attribute and <s:validateAll>, validateLength and with only required="true" also work!!!.


 

<s:decorate>

<div class="prop">

<s:label id="editLabel" styleClass="#{invalid?'errors':''}">

created by

<s:span styleClass="required" rendered="true">*</s:span>

</s:label>

<span id="editSpan" class="#{invalid?'errors':''}">

invalid value > #{invalid}

<ice:inputText id="createdById" requiredMessage="This field value is required." partialSubmit="true" required="true" size="100" maxlength="130" value="#{featureSetHome.instance.createdBy}">

</ice:inputText>

</span>

<s:message styleClass="error errors" />

</div>

</s:decorate>


 


 

3)    With just <s:decorate>, required="true", s:message and without requiredMessage attribute.

<s:decorate>

<div class="prop">

<s:label id="editLabel" styleClass="#{invalid?'errors':''}">

created by

<s:span styleClass="required" rendered="true">*</s:span>

</s:label>

<span id="editSpan" class="#{invalid?'errors':''}">

invalid value > #{invalid}

<ice:inputText id="createdById" partialSubmit="true" required="true" size="100" maxlength="130" value="#{featureSetHome.instance.createdBy}">

</ice:inputText>

</span>

<s:message styleClass="error errors" />

</div>

</s:decorate>

No comments: