1 2 3 Previous Next 31 Replies Latest reply on Aug 9, 2007 4:44 AM by Orsier Adrien

    Evaluation of action attibute in s:link

    Alex Ka Novice

      Hi,

      I have a problem with evaluating a value to pass to localeSelector.selectLanguage(). Here is the example:

       <ui:repeat var="locale" value="#{localeSelector.supportedLocales}">
       <h:outputText value="#{locale.label}"
       rendered="#{localeSelector.locale.toString().equals(locale.value)}"/>
       <s:link value="#{locale.label}"
       action="#{localeSelector.selectLanguage('${locale.value}')}"
       rendered="#{not localeSelector.locale.toString().equals(locale.value)}"/>
       </ui:repeat>
      


      The problem is that the generated link looks like this:
      http://localhost:8080/AuthWebApp/noauth/login.seam?cid=1&actionMethod=noauth%2Flogin.xhtml%3AlocaleSelector.selectLanguage%28%27%24%7Blocale.value%7D%27%29


      The javadoc of selectLanguage() says :

      Set the language and force resource bundle reload, useful for quick action links:
      <h:commandLink value="DE" action="#{localeSelector.selectLanguage('de')}"/>


      My question is how can I pass the language string with the expression language by evaluating locale.value?

      PS Hope this isn't a very stupid question. I have searched on the internet but couldn't find an answer. The evaluation for MethodBinding looks fishy...

        • 1. Re: Evaluation of action attibute in s:link
          Alex Ka Novice

          Hi again,

          It's strange to me that no one has submitted even a suggestion to help my problem.

          I have performed another search on the internet. The problem still stays. Even found this other thread on the forum from January:
          http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4056220

          Dustin says for the "Parameterized Method Bindings" (as specified here: http://docs.jboss.com/seam/2.0.0.B1/reference/en/html/elenhancements.html)

          that

          you can't use the method params within a 'repeat'


          Gavin's response:
          What do you mean? The booking example does this.

          tells me that he didn't see the problem in the given example. This being that the 'item' parameter comes from var="item" (i.e. is not a component name) and cannot be evaluated when the action is executed. It must be evaluated when the page is processed at first.

          I know that Deved doesn't have the right to pass 'item' to it's method (from the ref: "You can not pass objects as arguments!") but for my case I don't see a problem to have my string evaluated. As the reference says:
          You may however pass literal strings using single or double quotes


          Is it possible to make ${} be evaluated in "Parameterized Method Bindings"?

          • 2. Re: Evaluation of action attibute in s:link
            Orsier Adrien Newbie

            I'm having the same problem, I can't retrieve any parameter with a s:link in my action, it's simply always null.
            At the moment I simply dodged the problem by using h:commandLink instead of s:link.

            • 3. Re: Evaluation of action attibute in s:link
              Alex Ka Novice

              Hi Zerg,

              My problem is being unable to construct the MethodBinding that I need. I think that yours is a different one.

              I tried to play with h:commandLink and c:forEach but none of this makes sense in my case.


              Also wanted to note that I don't find the src of org.jboss.seam.ui.component.html.* in my Seam distribution (jboss-seam-2.0.0.BETA1). I wanted to see the source of the HtmlLink class but the java file is not included.

              Can anyone please explain how can one use MethodBinding with Facelets' repeat tag? Do you think this can be done? Will be done?

              Should I create a facelet component as explained here:
              http://www-128.ibm.com/developerworks/java/library/j-facelets/#N103FE or
              http://wiki.java.net/bin/view/Projects/FaceletsFAQ#Can_I_pass_a_MethodBinding_to_a

              Something like:

              <a:localeLink locale="${locale.value}" label=${locale.label}/>
              


              to become:
              <s:link value="#{label}"
              action="#{localeSelector.selectLanguage('${locale}')}"
              rendered="#{not localeSelector.locale.toString().equals('${locale}')}"/>
              


              Any comments are very welcome. Thanks

              • 4. Re: Evaluation of action attibute in s:link
                Alex Ka Novice

                I checked if source files were really missing.

                HtmlLink.java is found in :
                jboss-seam-1.2.1.GA\src\ui\org\jboss\seam\ui
                jboss-seam-1.3.0.ALPHA\src\ui\org\jboss\seam\ui

                HtmlLink.html :
                jboss-seam-2.0.0.BETA1\doc\ui\apidocs\org\jboss\seam\ui\component\html
                jboss-seam-2.0.0.BETA1\doc\ui\apidocs\org\jboss\seam\ui\component\html\class-use

                Is this supposed to be like that?

                • 5. Re: Evaluation of action attibute in s:link
                  Orsier Adrien Newbie


                  action="#{localeSelector.selectLanguage('${locale.value}')}

                  I think it's simply that you have to remove the ' that are surrounding #{locale.value}.
                  Not sure about it though.

                  • 6. Re: Evaluation of action attibute in s:link
                    Alex Ka Novice

                    Hi Zerg,

                    No, you cannot have embedded el like this:

                    action="#{localeSelector.selectLanguage(#{locale.value})}


                    As I have noted the generated href is:
                    http://localhost:8080/AuthWebApp/noauth/login.seam?cid=1&actionMethod=noauth%2Flogin.xhtml%3AlocaleSelector.selectLanguage%28%27%24%7Blocale.value%7D%27%29


                    The quotes are there. If I remove them from the code they are simply not generated. This is not the problem as there is no way an expression inside the MethodBinding to be evaluated.

                    Of course I tried what you have suggested and several other options. My guess with 'immediate' evaluation using ${} is also not correct.

                    I guess the solutions are two:
                    - create a custom facelet component
                    - pass a request param to change the language

                    I think Facelet's repeat just can't work with MethodBinding with simple EL.

                    • 7. Re: Evaluation of action attibute in s:link
                      Orsier Adrien Newbie

                      Just in case, what are you trying to do with that code exactly?
                      I guess you don't won't to simply change the local, or you have customized the Resource Bundles.

                      • 8. Re: Evaluation of action attibute in s:link
                        Alex Ka Novice

                        I'm just trying to change the locale, yes :)

                        But wanted to use an s:link and selectLanguage(). There is an example in the javadoc. To enumerate the locales I wanted to use localeSelector.supportedLocales. And this obviously is hard to do.

                        All examples provided by the seam team are with a combo box and a button while I wanted to generate some links. I guess they just didn't try to do that and haven't seen the problems one can run into. I don't think that the code in this portion is mature. This is why I asked for help from the team. Unfortunately they are not available to answer today...

                        • 9. workaround
                          Alex Ka Novice

                          OK, finally I came up with a workaround:

                          <s:link value="#{localeProvider.getDisplayString(locale.value)}"
                           action="#{localeProvider.updateLocale()}"
                           rendered="#{not localeSelector.locale.toString().equals(locale.value)}">
                           <f:param name="l" value="#{locale.value}"/>
                          </s:link>
                          


                          The request parameter is processed by localeProvider.updateLocale():

                          public void updateLocale() {
                           if (l != null && l.length() > 0) {
                           localeSelector.selectLanguage(l);
                           }
                           }
                          




                          I'm still interested if someone has a comment on what to do with the action parameter of s:link and the fact that he is unable to include page variables i.e. the following code cannot be realized
                          <s:link value="#{localeProvider.getDisplayString(locale.value)}"
                           action="#{localeSelector.selectLanguage('#{locale.value}')}"
                           rendered="#{not localeSelector.locale.toString().equals(locale.value)}"/>
                          


                          Note
                          The locale variable comes from:
                          <ui:repeat var="locale" value="#{localeSelector.supportedLocales}">
                          


                          • 10. Re: Evaluation of action attibute in s:link
                            Gavin King Master

                             

                            action="#{localeSelector.selectLanguage(locale.value)}"


                            • 11. Re: Evaluation of action attibute in s:link
                              Alex Ka Novice

                              Thank you for the answer Gavin. Unfortunately I think you haven't got my point. The code you provided is my first implementation of the thing. When I run the application the result of clicking the link is the Seam Debug Page:

                              Caused by javax.el.PropertyNotFoundException with message: "Property 'value' not found on type java.util.Locale"

                              I have reopened the issue since I think there is more to the question to comment about:
                              "locale" should not be thought of as being the component "locale". There should be a syntax to allow the use of the "locale" variable coming from Facelets' repeat tag.

                              Thank you for the attention.

                              • 12. Re: Evaluation of action attibute in s:link
                                Gavin King Master

                                locale is the name of a built-in component. Name your page-scoped variable something else.

                                • 13. Re: Evaluation of action attibute in s:link
                                  Alex Ka Novice

                                  Yes, maybe 'locale' should be renamed but first there should be a way to evaluate it as a page variable. Renaming the variable now does not make the code perform what it is supposed to do.

                                  I would really like to know that you have understood what I see as a problem here. I am ready to accept that the feature I request may not be feasible.

                                  • 14. Re: Evaluation of action attibute in s:link
                                    Gavin King Master

                                    This can only possibly work if the value of the UIRepeat is a DataModel. Otherwise how on earth can the EL expression (which is evaluated during the invoke phase of the second request) possibly know about the JSF page variable (which is only defined during the render phase of the first request)??

                                    1 2 3 Previous Next