WebSheetValidation

Use Case 5: Validation

Support validation for each cell, also support cells in dynamic rows. Plsease see the demo for deails.

Demo

How to Setup Validation Rule

Use $validate{rule="...." error="...."} in the cell's comment.

  • rule:validation rule.
  • error: error message to show up if validation failed.

Note: One cell can define multiple rules. Use $value to present the current input value. For example, the following rules are defined for the price cell:

$validate{rule="$value>0" error="Value must be greater than zero (0)."}
$validate{rule="$value<=500000" error="Value must be less than or equal to 500,000."}.

Excel Template

ABCDEF
1Sale Price Report
2Sale Report Input
3Line NumberItem NumberNameSales
4Price (>0 and <=500000)Quantity (>0)Amount
51${item.code}${item.name}${item.price}${item.quantity}
6Total
7Note

Validation Demo

ABCDEF
1Sale Price Report
2Sale Report Input
3Line NumberItem NumberNameSales
4Price (>0 and <=500000)Quantity (>0)Amount
51$0.00
6Total$0.00
7Note

Source code
<h3>How to Setup Validation Rule</h3>

<p>Use $validate{rule="...." error="...."} in the cell's comment.</p>
    <ul>
<li>rule:validation rule.</li>
<li>error: error message to show up if validation failed.</li>
    </ul>

    <p>Note: One cell can define multiple rules. Use $value to present the current input value. For example, the following rules are defined for the price cell:</p>
    

    <div class="source"><pre class="prettyprint">$validate{rule="$value&gt;0" error="Value must be greater than zero (0)."}
$validate{rule="$value&lt;=500000" error="Value must be less than or equal to 500,000."}.</pre>
    </div>
    

<h:form id="form1">    

   <h3>Excel Template</h3>

    <tie:websheet id="sheet1" webSheetBean="#{webSheetValidation_Config}"
        maxRowsPerPage="30" readOnly="true">
    </tie:websheet>
    <p:commandButton id="cmdExportTemplate" value="Download the template"
        ajax="false" actionListener="#{webSheetValidation_Config.doExport()}">
        <p:fileDownload value="#{webSheetValidation_Config.exportFile}" />
    </p:commandButton>


    <h3>Validation Demo</h3>

    <tie:websheet id="sheet2" webSheetBean="#{webSheetValidation}"
        maxRowsPerPage="30">
    </tie:websheet>
    <p>
    <p:commandButton id="cmdExportResult" value="Download the result"
        ajax="false" actionListener="#{webSheetValidation.doExport()}">
        <p:fileDownload value="#{webSheetValidation.exportFile}" />
    </p:commandButton>
    </p>            
</h:form>