Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Struts and the fly likes <s:if test= Need help for this tag in struts 2" title="Bye IE" /> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "<s:if test="hasFieldErrors()"></s:field> Need help for this tag in struts 2" Watch "<s:if test="hasFieldErrors()"></s:field> Need help for this tag in struts 2" New topic
Author

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

Jibin Najeeb
Greenhorn

Joined: Nov 27, 2012
Posts: 6
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..
 
Consider Paul's rocket mass heater.
 
subject: <s:if test="hasFieldErrors()"></s:field> Need help for this tag in struts 2