Announcement Announcement Module
Collapse
No announcement yet.
Use MessageContext directly from webflow xml configuration file Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Use MessageContext directly from webflow xml configuration file

    Hello,

    In one of my views, I catch an exception « OptimisticLockException » to let me know that between the moment where I edited the record and the moment when I try to save it, there is another user that has already changed this record.

    Until this point, that’s simple…
    So my “Flow” looks like:
    Code:
    <view-state id="edit_contact_details" model="CreateEditPersonModel" view="edit_contact_details">
            ...
            <transition on-exception="javax.persistence.OptimisticLockException" to="back_to_search_person_OptimisticLockException" />
            ...
        </view-state>
    What I would like, that’s when I come back to “back_to_search_person_OptimisticLockException , I show a message to the user, something along those lines: “This record has updated by another user from the starting of his modification”…

    I could created a function:
    Code:
    public class setupFormEditContactDetails extends FormAction {
     
        public Event messageError(RequestContext context) throws Exception {
            MessageContext messages = context.getMessageContext();
     
            messages.addMessage(new MessageBuilder().error().source(null).code("OptimisticLockException").build());
        }    
     
    }
    Instantiate the bean:
    Code:
           <bean id="setupFormEditContactDetails" class="monPackage.setupFormEditContactDetails">
               <property name="formObjectName">
                   <value>CreateEditPersonModel</value>
               </property>
               <property name="formObjectClass">
                   <value>entites.Personne</value>
               </property>
               <property name="formObjectScope">
                   <value>FLOW</value>
               </property>
           </bean>
    And finally in the webflow, it could be:
    Code:
    <view-state id="edit_contact_details" model="CreateEditPersonModel" view="edit_contact_details">
            ...
            <transition on-exception="javax.persistence.OptimisticLockException" to="back_to_search_person_OptimisticLockException">
                 <evaluate expression="setupFormEditContactDetails.messageError" />
            </transition>
            ...
        </view-state>
    But to be obliged to create a bean, a function, … just to show a message…
    So I am wondering if does exist a solution to handle messageContext directly from the configuration file of the webflow that should looks like:
    Code:
      <view-state id="edit_contact_details" model="CreateEditPersonModel" view="edit_contact_details">
            <transition on-exception="javax.persistence.OptimisticLockException" to="back_to_search_person_OptimisticLockException" >
                    <evaluate expression="requestScope.messageContext.addMessage(new MessageBuilder().error().source(null).code('OptimisticLockException').build())" />
            </transition>
        </view-state>
    Any idea?

    Many thanks,
    Alain

  • #2
    I finally found out the solution...

    That was simply:
    Code:
            <transition on-exception="javax.persistence.OptimisticLockException" to="back_to_search_person_OptimisticLockException" >
                    <evaluate expression="messageContext.addMessage(new org.springframework.binding.message.MessageBuilder().error().source(null).code('...').build())" />
            </transition>

    Comment

    Working...
    X