You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Martin Gainty <mg...@hotmail.com> on 2009/06/01 02:57:44 UTC

RE: customize fielderror

velocity example which references parameters.name index resolution for fieldErrors
#*--example from controlheader.vm
*#
## Only show message if errors are available. This will be done if ActionSupport is used.
#if( $fieldErrors.get($parameters.name) )

#OGNL stack finds a fieldError depending on value extracted from 'bean'
 <form name="myForm" action="${validationAction}" method="POST">
         <input type="hidden" name="validationAction" value="${validationAction}"/>
         Action Properties:
         <br>
         <table>
            #tag( TextField "label=Name" "name=name" "value=name" )
         </table>
            Bean Properties:
            #if( $stack.findValue("fieldErrors") )
               #set( $beanErrors = $stack.findValue("fieldErrors.get('bean')") )

//bean is encapsulated ValidatedBean contained within Action Class as referenced here
//it must exist for fieldErrors.get('bean') to resolve correctly
public class ValidatedAction extends ActionSupport {
    private ValidatedBean bean = new ValidatedBean();
    private String name;
    private String validationAction = "basicValidation.action";

    public ValidatedBean getBean() {
        return bean;
    }

    public void setBean(ValidatedBean bean) {
        this.bean = bean;
//a clear example of listing fieldErrors 
		<form action="${validationAction}" method="POST">
			<input type="hidden" name="validationAction" value="${validationAction}" />
			<#if (fieldErrors?keys?seq_contains("name"))>
			   <br/>
			   <font color="red">
			      <b>Field Errors:</b><br/>
			      <ul>
			      <#list fieldErrors.name as fieldError>
			         <li>${fieldError}</li>
			      </#list>
			      </ul>
			   </font>
			</#if>
			Action Properties:
			<br/>
			<table>
				<tr><td>
					Name:<input type="text" name="name" />
				</td></tr>
			</table>
			Bean Properties:
//reference individual Bean attributes and match fieldErrors according to bean attribute match
			<#if ((fieldErrors?keys?seq_contains("bean.text")) || 
			     (fieldErrors?keys?seq_contains("bean.date")) ||
			     (fieldErrors?keys?seq_contains("bean.number")))> 
				<br/>
				<font color="red">
					<b>Bean Errors:</b><br/>
					<ul>
					<#if fieldErrors?keys?seq_contains("bean.text")>
//wonderfully clear example of listing fieldErrors 
				   	<#list fieldErrors["bean.text"] as beanTextError>
				   		<li>${beanTextError}</li>
				   	</#list>
				   	</#if>

//finally an ActionSupport.addFieldError which allows you to add specific
//actionErrors which correspond to known keys of field1, field2
public class MessageStoreInterceptorTest extends StrutsTestCase {
46  
47      public void testStoreMessage() throws Exception {
48          MessageStoreInterceptor interceptor = new MessageStoreInterceptor();
49          interceptor.setAllowRequestParameterSwitch(true);
50          interceptor.setOperationMode(MessageStoreInterceptor.STORE_MODE);
51  
52  
53          Map paramMap = new LinkedHashMap();
54          Map sessionMap = new LinkedHashMap();
55  
56          ActionSupport action = new ActionSupport();
57          action.addActionError("some action error 1");
58          action.addActionError("some action error 2");
59          action.addActionMessage("some action message 1");
60          action.addActionMessage("some action message 2");
61          action.addFieldError("field1", "some field error 1");
62          action.addFieldError("field2", "some field error 2");

i could'nt see any of these examples with white font on white background in the posted example
Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> Date: Sun, 31 May 2009 17:59:33 -0400
> From: newton.dave@yahoo.com
> To: user@struts.apache.org
> Subject: Re: customize fielderror
> 
> Martin Gainty wrote:
> > can we assume fieldErrors is some sort of List<E> ?
> > http://java.sun.com/javase/6/docs/api/java/util/List.html#get(int)
> 
> No, fieldErrors is a map, the entries of which are a list--as the JSP 
> snippet implied, and as in the docs.
> 
> >> <s:if test="fieldErrors.get('email').size() > 0"><s:property
> >> value="fieldErrors.get('email').get(0)" /></s:if>
> > (would be easier to follow example if we could see referenced variables)
> 
> What referenced variables?
> 
> Dave
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

_________________________________________________________________
Hotmail® has a new way to see what's up with your friends.
http://windowslive.com/Tutorial/Hotmail/WhatsNew?ocid=TXT_TAGLM_WL_HM_Tutorial_WhatsNew1_052009

Re: customize fielderror

Posted by Dave Newton <ne...@yahoo.com>.
O_o

I have no idea why you posted that.

Martin Gainty wrote:
> velocity example which references parameters.name index resolution for fieldErrors
> #*--example from controlheader.vm
> *#
> ## Only show message if errors are available. This will be done if ActionSupport is used.
> #if( $fieldErrors.get($parameters.name) )
> 
> #OGNL stack finds a fieldError depending on value extracted from 'bean'
>  <form name="myForm" action="${validationAction}" method="POST">
>          <input type="hidden" name="validationAction" value="${validationAction}"/>
>          Action Properties:
>          <br>
>          <table>
>             #tag( TextField "label=Name" "name=name" "value=name" )
>          </table>
>             Bean Properties:
>             #if( $stack.findValue("fieldErrors") )
>                #set( $beanErrors = $stack.findValue("fieldErrors.get('bean')") )
> 
> //bean is encapsulated ValidatedBean contained within Action Class as referenced here
> //it must exist for fieldErrors.get('bean') to resolve correctly
> public class ValidatedAction extends ActionSupport {
>     private ValidatedBean bean = new ValidatedBean();
>     private String name;
>     private String validationAction = "basicValidation.action";
> 
>     public ValidatedBean getBean() {
>         return bean;
>     }
> 
>     public void setBean(ValidatedBean bean) {
>         this.bean = bean;
> //a clear example of listing fieldErrors 
> 		<form action="${validationAction}" method="POST">
> 			<input type="hidden" name="validationAction" value="${validationAction}" />
> 			<#if (fieldErrors?keys?seq_contains("name"))>
> 			   <br/>
> 			   <font color="red">
> 			      <b>Field Errors:</b><br/>
> 			      <ul>
> 			      <#list fieldErrors.name as fieldError>
> 			         <li>${fieldError}</li>
> 			      </#list>
> 			      </ul>
> 			   </font>
> 			</#if>
> 			Action Properties:
> 			<br/>
> 			<table>
> 				<tr><td>
> 					Name:<input type="text" name="name" />
> 				</td></tr>
> 			</table>
> 			Bean Properties:
> //reference individual Bean attributes and match fieldErrors according to bean attribute match
> 			<#if ((fieldErrors?keys?seq_contains("bean.text")) || 
> 			     (fieldErrors?keys?seq_contains("bean.date")) ||
> 			     (fieldErrors?keys?seq_contains("bean.number")))> 
> 				<br/>
> 				<font color="red">
> 					<b>Bean Errors:</b><br/>
> 					<ul>
> 					<#if fieldErrors?keys?seq_contains("bean.text")>
> //wonderfully clear example of listing fieldErrors 
> 				   	<#list fieldErrors["bean.text"] as beanTextError>
> 				   		<li>${beanTextError}</li>
> 				   	</#list>
> 				   	</#if>
> 
> //finally an ActionSupport.addFieldError which allows you to add specific
> //actionErrors which correspond to known keys of field1, field2
> public class MessageStoreInterceptorTest extends StrutsTestCase {
> 46  
> 47      public void testStoreMessage() throws Exception {
> 48          MessageStoreInterceptor interceptor = new MessageStoreInterceptor();
> 49          interceptor.setAllowRequestParameterSwitch(true);
> 50          interceptor.setOperationMode(MessageStoreInterceptor.STORE_MODE);
> 51  
> 52  
> 53          Map paramMap = new LinkedHashMap();
> 54          Map sessionMap = new LinkedHashMap();
> 55  
> 56          ActionSupport action = new ActionSupport();
> 57          action.addActionError("some action error 1");
> 58          action.addActionError("some action error 2");
> 59          action.addActionMessage("some action message 1");
> 60          action.addActionMessage("some action message 2");
> 61          action.addFieldError("field1", "some field error 1");
> 62          action.addFieldError("field2", "some field error 2");
> 
> i could'nt see any of these examples with white font on white background in the posted example
> Martin Gainty 
> ______________________________________________ 
> Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
>  
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
> Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.
> 
> 
> 
> 
>> Date: Sun, 31 May 2009 17:59:33 -0400
>> From: newton.dave@yahoo.com
>> To: user@struts.apache.org
>> Subject: Re: customize fielderror
>>
>> Martin Gainty wrote:
>>> can we assume fieldErrors is some sort of List<E> ?
>>> http://java.sun.com/javase/6/docs/api/java/util/List.html#get(int)
>> No, fieldErrors is a map, the entries of which are a list--as the JSP 
>> snippet implied, and as in the docs.
>>
>>>> <s:if test="fieldErrors.get('email').size() > 0"><s:property
>>>> value="fieldErrors.get('email').get(0)" /></s:if>
>>> (would be easier to follow example if we could see referenced variables)
>> What referenced variables?
>>
>> Dave
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
> 
> _________________________________________________________________
> Hotmail® has a new way to see what's up with your friends.
> http://windowslive.com/Tutorial/Hotmail/WhatsNew?ocid=TXT_TAGLM_WL_HM_Tutorial_WhatsNew1_052009

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org