This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Struts and the fly likes <s:if test= Need help for this tag in struts 2" title="" /> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


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..
 
GeeCON Prague 2014
 
subject: <s:if test="hasFieldErrors()"></s:field> Need help for this tag in struts 2