Uploaded image for project: 'Seam 2'
  1. Seam 2
  2. JBSEAM-1124

Make ThemeSelector and LocaleSelector implement valueChanged(ValueChangeEvent event), and some more...

    Details

    • Type: Feature Request
    • Status: Closed (View Workflow)
    • Priority: Optional
    • Resolution: Done
    • Affects Version/s: 1.2.1.GA
    • Fix Version/s: 1.3.0.ALPHA
    • Component/s: Framework
    • Labels:
      None
    • Environment:

      All

      Description

      Neither LocaleSelector nor ThemeSelector currently provide a method valueChanged(ValueChangeEvent event). Such method is needed to get some auto-submit without the need for a lot of JavaScript, to change the locale or theme without clicking a Submit button. The following would create a dropdown list, for which selecting a new value would change the look and feel right away – thus loosing any changes made in other forms on the very same page...

      <h:form>
      <h:selectOneMenu
      immediate="true"
      value="#

      {themeSelector.theme}"
      onchange="submit();"
      valueChangeListener="#{themeSelector.valueChanged}">
      <f:selectItems value="#{themeSelector.themes}" />
      </h:selectOneMenu>
      </h:form>

      And while extending ThemeSelector, why not add a method selectTheme(String), just like LocaleSelector#selectLanguage(String).

      And one might also make the cookie name available for injection. This, however, also needs some work in the xmlns:theme="http://jboss.com/products/seam/theme" namespace.

      http://fisheye.labs.jboss.com/browse/JBoss/jboss-seam/src/main/org/jboss/seam/theme/ThemeSelector.java?r=1.15#l41
      public class ThemeSelector extends Selector
      {
      :
      :
      private String cookieName = "org.jboss.seam.core.Theme";

      public String getCookieName() { return cookieName; }

      public void setCookieName(String cookieName) { this.cookieName = cookieName; }

      /**
      * Sets the theme and forces it to load, useful for auto-submit dropdown
      * lists using the JavaScript onchange event: <br>
      * <code>
      * <h:form>
      * <h:selectOneMenu
      * immediate="true"
      * value="#{themeSelector.theme}

      "

      • onchange="submit();"
      • valueChangeListener="# {themeSelector.valueChanged}

        ">

      • <f:selectItems value="# {themeSelector.themes}

        " />

      • </h:selectOneMenu>
      • </h:form>
      • </code>
      • @param event
      • the JavaServer Faces ValueChangedEvent
        */
        public void valueChanged(ValueChangeEvent event) { setTheme((String) event.getNewValue()); select(); }

      /**

      • Sets the theme and force it to load, useful for quick action links: <br>
      • <code>
      • <h:commandLink value="# {messages['org.jboss.seam.theme.default']}

        "

      • action="# {themeSelector.selectTheme('default')}

        "/>

      • </code>
      • @param theme the name of the theme to be loaded
        */
        public void selectTheme(String theme) { setTheme(theme); select(); }


        :
        }

      In fact, the current LocaleSelector somehow does support the auto-submit without any changes:

      <h:form>
      <h:selectOneMenu
      value="#

      {localeSelector.localeString}"
      onchange="submit();"
      valueChangeListener="#{localeSelector.select}">
      <f:selectItems value="#{localeSelector.supportedLocales}" />
      </h:selectOneMenu>
      </h:form>

      However, I guess this works by accident; in fact org.jboss.seam.core.LocaleSelector#select() does not accept ValueChangeEvent as a parameter; so I don't know why the above works – no guarantees for future releases of JavaServer Faces? So for LocaleSelector as well a method valueChanged(ValueChangeEvent event) could be added, just to be sure:

      http://fisheye.labs.jboss.com/browse/JBoss/jboss-seam/src/main/org/jboss/seam/core/LocaleSelector.java?r=1.19#l38
      public class LocaleSelector extends Selector
      {
      :
      :
      /**
      * Sets the locale and forces it to load, useful for auto-submit dropdown
      * lists using the JavaScript onchange event: <br>
      * <code>
      * <h:form>
      * <h:selectOneMenu
      * immediate="true"
      * value="#{localeSelector.localeString}

      "

      • onchange="submit();"
      • valueChangeListener="# {localeSelector.valueChanged}

        ">

      • <f:selectItems value="# {localeSelector.supportedLocales}

        " />

      • </h:selectOneMenu>
      • </h:form>
      • </code>
      • @param event
      • the JavaServer Faces ValueChangedEvent
        */
        public void valueChanged(ValueChangeEvent event) { select(); }

        :
        }

      That's all...!

      Arjan.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                avbentem Arjan van Bentem
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: