Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<s:if test="hasFieldErrors()"></s:field> Need help for this tag in struts 2

 
Jibin Najeeb
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to use the above code for two fields.
<s:form theme="simple" >
<s:if test=hasFieldErrors()">
<div class="errorMessage">Enter Bank Account</div><br>
</s:if>
<s:textfield name="bankaccount" cssClass="input-xlarge text-tip" id="input01" title="Bank account"/>
<s:if test="hasFieldErrors()">
<div class="errorMessage">Amount Problem</div><br>
</s:if>
<s:textfield name="amount" cssClass="input-xlarge text-tip" id="input01" title="Amount"/>
</s:form>
Note:Theme is simple

The validate function in the action class is

public void validate(){
if((bankaccount==null)||bankaccount.length()==0){
this.addFieldError("bankaccount", "ERROR bank");
}
if((amount==0.0)){
this.addFieldError("Amount", "ERROR amount");
}

}

The problem is whenever there is a field error in any one of the two field. The validation message corresponding to each is displayed for two fields.
ie ""Error bank"" above bank account field and ""ERROR amount"" above amount field.

I need to work the validation like that worked in default form theme. Any Help Appreciated..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic