Results 1 to 3 of 3

Thread: MessageContext API

  1. #1

    Default MessageContext API

    Hi ..
    I want to know more about MessageContext API used with SWF2.0.
    When is messageContext initialized and if there is any error in view state it gets value set.
    but does it get reset with each new error in next view statein same flow.

    In my application ,error is carried along next states means messageContext wont clear up.
    Should i explicitly clearMessages() in each state.?

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

    Hello

    I want to know more about MessageContext API used with SWF2.0.
    1) We have available SWF 2.3.x
    2) have you read the API for MessageContext SWF2.0.X?

    When is messageContext initialized and if there is any error in view state it gets value set.
    but does it get reset with each new error in next view statein same flow.
    Post your code, this is weird

    The error(s) shown are related with the model referenced for your view-state?
    If yes, the error(s) must exists until you leave such view-state because you fixed all the suggested error messages, therefore such error(s) should not exists anymore

    If you are saving customized error(s) messages in flowScope it going to remain until you complete the flow process or if yourself delete or make null such saved data in such scope

    Perhaps was a bug, but again post your code

    In my application ,error is carried along next states means messageContext wont clear up.
    Should i explicitly clearMessages() in each state.?
    If you would post the error messages, would be better to get a clear idea
    Last edited by dr_pompeii; Aug 23rd, 2011 at 07:57 PM.
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3

    Default code posting for validation issues in swf

    I have a validationBean which have validation methods.This validationBean is defined as flow instance variable in flows and thus validation methods are called in each next-state.
    On NEXt -validationMethods are called and i added resetMessage1() with them so if CURRENT state wont propogate validation error message in NEXT state( which otherwise was,even if validation passes but failed first.)

    Problem : From CURRENT state to BACK state still propogates validation error message .
    and i am not calling validation methods on back-button transitions thus reset is not calling.
    What are my alternatives.
    1 should i call resetMessage on each BACK transition?
    2.Can i somehow change the scope of var -validationBean from flow scope to requestscope so message1 clears up automatically.
    43.Would defining validationBean as a bean help instead of defining as flow instance var.

    HTML Code:
    <var name="validationBean" class="com.cti.ew8.validator.ValidationBean"/>
     <view-state id="Q1" view="name" model="validationBean">		
    <on-render>
    <set name="requestScope.pageName" value="Name" />
    </on-render>
    <transition on="prev" to="selectionPage" />
    <transition on="next" to="Q2">
    <evaluate expression="validationBean.validateOneText(requestParameters.text_1, 'message1', messageContext, 'validation.enterName')" />
    </transition>
    <transition on="saveAndExit" to="finish" />
    </view-state>
    HTML Code:
    public class ValidationBean implements Serializable {
    	private static final long	serialVersionUID	= 1L;
    
    	private Message[]			messages;
    
    	private final List<Message>	message1			= new ArrayList<Message>();
    
    	public List<Message> getMessage1() {
    		return message1;
    	}
    
    	private void resetMessage1() {
    		message1.clear();
    
    	}
    
    
    	}
    
    	
    	private void buildMessages(String sourceKey, MessageContext messageContext,
    						String resourceKey) {
                                  MessageBuilder builder = new MessageBuilder();
    		messageContext.addMessage(builder.error().source(sourceKey).code(resourceKey).build());
    
                                  messages = messageContext.getAllMessages();
    		for (Message m : messages) 
    			message1.add(m);
    	}
    
    	private boolean fieldEmptyCheck(String fieldValue, boolean isValid,String sourceKey, MessageContext messageContext,String resourceKey) {
    		if (!org.springframework.util.StringUtils.hasText(fieldValue)) {
    			buildMessages(sourceKey, messageContext, resourceKey);
    			isValid = false;
    		}
    		return isValid;
    	}
    
    	public boolean validateOneCombo(String field, String sourceKey,
    						MessageContext messageContext, String resourceKey) {
    		resetMessage1();
    		if ((field == null) || (field.equalsIgnoreCase("0"))) {
    		buildMessages(sourceKey, messageContext, resourceKey);
    			return false;
    		}
    
    		else {
    
    			return true;
    
    		}
    
    	}
    
    	public boolean validateRadio(String field, String sourceKey,MessageContext messageContext, String resourceKey) {
    		
                                 resetMessage1(); //this helps clear out validation error or messages on NEXt view state but PREV still shows.
    		boolean isValid = true;
    		if (field == null) {
    		buildMessages(sourceKey, messageContext, resourceKey);
    		isValid = false;
    		}
    		return isValid;
    	}


    My JSP.---
    HTML Code:
    This is portion of my jsp that shows error messages.
    <c:forEach var="errorMsg" items="${validationBean.message1}">
     <c:if test="${errorMsg != null}"> 
    <div id="errorWrapper">
    ${errorMsg.text}
    
    
    </div>
    </c:if>
    </c:forEach>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •