Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Language selection

  1. #1
    Join Date
    Jul 2006
    Posts
    21

    Default Language selection

    Can anyone recommend how to deal with a page using SWF when there is a language selection dropdown? When the language is selected, I want to post the 'locale' parameter so the LocaleChangeInterceptor will grab the selected local, but then just redisplay the current view state. The page also has 'continue' and 'back' buttons to deal with so I don't think I can use a hidden input.

    Thoughts?

  2. #2
    Join Date
    Jan 2006
    Location
    Zürich, Switzerland
    Posts
    423

    Default

    Hi jerkoch,

    Quote Originally Posted by jerkoch
    Can anyone recommend how to deal with a page using SWF when there is a language selection dropdown? When the language is selected, I want to post the 'locale' parameter so the LocaleChangeInterceptor will grab the selected local, but then just redisplay the current view state. The page also has 'continue' and 'back' buttons to deal with so I don't think I can use a hidden input.

    Thoughts?
    I think it really depends on whether or not you are using a continuations based repository with SWF.

    * If you're using continuations, I have a working example of doing just that. The only difference is that I have language selection links instead of a drop-down, but that should be easy enough to change. The example is part of my Wizard Validator code that I wrote for use with SWF and Commons Validator from Spring Modules.

    Check out my forum post here:

    http://forum.springframework.org/sho...6&postcount=10

    FYI: the latest release is 0.2, which is based on SWF 1.0 EA and Spring Modules 0.4.

    Note: I am not implying that you need to use any of my code or the wizard validator for that matter. I am only suggesting that you download the example and try it out, in case you prefer to see a working example.

    * If you are not using continuations, you will need to define new transitions in your flow to handle the language selection event and then automatically transition back to your original view-state. That would of course be a bit trickier to implement. Though there are examples somewhere on this forum for how to accomplish similar feats with decision states, flow execution listeners, tracking the previous state, etc.

    Hope this helps,

    Sam

  3. #3
    Join Date
    Jul 2006
    Posts
    21

    Default

    Thanks for the suggestions.

    I'm not using continuations, so If I do ask you suggest and name the dropdown "_eventId_language" (at least I think thats what you meant), my form will always be posted with that event EVEN when the "continue" button is pressed. I will never be able to flow forward.

    Also, I won't be able to use the LocaleChangeInterceptor to automatically set the locale. I'll need to pull the language selected from the event and set the locale manually.

    Here's the code I wrote to pull the language from the eventId:

    Code:
       public Event processLanguageChange(RequestContext context) throws Exception {
          String lang = context.getRequestParameters().get("_eventId_language");
          
          context.getExternalContext().getSessionMap().put(
                SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,
                new Locale(lang));
          
          LOG.debug("Language changed: " + lang);
          return success();
       }
    Seems to work OK for language changes.

    But I'm still stuck because I can never flow forward since the dropdown eventId gets included in each request and superceeds the button eventId.
    Last edited by jerkoch; Jul 20th, 2006 at 04:12 PM.

  4. #4
    Join Date
    Jul 2006
    Posts
    21

    Default

    OK, I think I solved my problem. I ended up putting two separate forms on the page. One for the dropdown language selection, and the other for the nav buttons. Both forms contain the hidden flowExecutionKey. Seems to be working fine.

    Does this seem reasonable?

  5. #5
    Join Date
    Jan 2006
    Location
    Zürich, Switzerland
    Posts
    423

    Default

    Hi jerkoch,

    Quote Originally Posted by jerkoch
    I'm not using continuations, so If I do as you suggest and name the dropdown "_eventId_language" (at least I think thats what you meant), my form will always be posted with that event EVEN when the "continue" button is pressed. I will never be able to flow forward.
    That's actually not what I meant.

    I meant that you could have the name of the drop-down set to "locale" (or "lang" or whatever you configured it as for your LocaleChangeInterceptor).

    Then you would basically have two options.

    1. If you choose to have a single form, you would need to create a decision-state to determine if the "locale" request parameter is not null, and if so then guide the flow back to the previous view-state to redisplay the form.
    2. On the other hand, if you choose to have two separate forms (which you mention later on), you could handle the logic by defining a new event ID for the language selection form.


    In the latter scenario (2 forms), your view-state would have at least two transitions: one (e.g., on="continue") to flow forward and a second (e.g., on="languageSelection") to return to the same view-state.

    In both situations, you would not need to write any custom processing of the locale, since your LocaleChangeInterceptor would handle that for you automatically.


    Quote Originally Posted by jerkoch
    Also, I won't be able to use the LocaleChangeInterceptor to automatically set the locale. I'll need to pull the language selected from the event and set the locale manually.

    Here's the code I wrote to pull the language from the eventId:

    Code:
       public Event processLanguageChange(RequestContext context) throws Exception {
          String lang = context.getRequestParameters().get("_eventId_language");
          
          context.getExternalContext().getSessionMap().put(
                SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,
                new Locale(lang));
          
          LOG.debug("Language changed: " + lang);
          return success();
       }
    Seems to work OK for language changes.

    But I'm still stuck because I can never flow forward since the dropdown eventId gets included in each request and superceeds the button eventId.
    Your above two assumptions, that you cannot use the LocaleChangeInterceptor and that you cannot flow forward, are incorrect. If I didn't do an adequate job explaining this above, just let me know.

    HTH,

    Sam

  6. #6
    Join Date
    Jan 2006
    Location
    Zürich, Switzerland
    Posts
    423

    Default

    Quote Originally Posted by jerkoch
    OK, I think I solved my problem. I ended up putting two separate forms on the page. One for the dropdown language selection, and the other for the nav buttons.
    Using two forms is definitely reasonable and probably the simplest solution.

    Quote Originally Posted by jerkoch
    Both forms contain the hidden flowExecutionKey.
    That is also essential. It's actually the key (no pun intended) to getting it to work for a non-continuation based repository.

    The only issue is that you don't really need to write the custom language processing method in your action. See my previous post for an explanation.

    - Sam

  7. #7
    Join Date
    Jul 2006
    Posts
    21

    Default

    The only issue is that you don't really need to write the custom language processing method in your action. See my previous post for an explanation.
    Good point, if I keep my dropdown named "locale", then wouldn't I need to put the "_eventId_language" as a hidden field in my first form? Otherwise, how would SWF know how to transition? I'm testing this now, but I can't seem to get the LocaleChangeInterceptor to catch the new local. Arg...

  8. #8
    Join Date
    Jul 2006
    Posts
    21

    Default

    Another update: I fixed my LocaleChangeInterceptor problem. Now everything seems to work without the hidden eventId in the first form. Actually, it even works without the hidden flowExecutionKey. Not sure why?

    Thanks again for your help!

    Jer.

  9. #9
    Join Date
    Jan 2006
    Location
    Zürich, Switzerland
    Posts
    423

    Default

    Quote Originally Posted by jerkoch
    Another update: I fixed my LocaleChangeInterceptor problem.
    Great!

    Quote Originally Posted by jerkoch
    Now everything seems to work without the hidden eventId in the first form. Actually, it even works without the hidden flowExecutionKey. Not sure why?
    Well, what does your URL look like? And what did you set the action of your form to?

    Quote Originally Posted by jerkoch
    Thanks again for your help!
    You're welcome!

    - Sam

  10. #10
    Join Date
    Jul 2006
    Posts
    21

    Default

    The is the JSP:

    Code:
    <form>
    <select name="locale" size="1" onChange="javascript:document.forms[0].submit();">
    <option value="null">Select</option>
    <option value="en">English</option>
    <option value="fr">Francais</option>
    </form>
    This is the URL after selecting a language:

    Code:
    http://localhost:9080/app/app.htm?locale=fr
    This is my flow.xml (notice I only have an eventId for the continue button):

    Code:
    	<view-state id="someState" view="someState">
    		<entry-actions>
    			<action bean="some.formAction" method="setupForm" />
    		</entry-actions>
    		<transition on="continue" to="nextState">
    			<action bean="some.formAction" method="bindAndValidate"/>
    		</transition>
    	</view-state>
    So it seems to redisplay the same view state. I dont think its actually getting to SWF.

Posting Permissions

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