6 Replies Latest reply on Jun 25, 2007 9:05 AM by franciscoacb

    Question: Can static parameters be used in *.page.xml?

      Hi,

      I would like to use this code.

      <navigation from-action="#{abcHome.remove}">
       <end-conversation/>
       <redirect view-id="/AbcList.xhtml">
       <param name="order" value="name asc"/>
       </redirect>
       </navigation>


      But the framework throws an exception about the "value" in the param tag:
      javax.faces.el.ReferenceSyntaxException: Invalid expression: 'name asc'. Parsed Expression of unexpected type java.lang.String


      If I use this code instead it works fine (where listOrder is a bean in application scope):
      <param name="order" value="#{listOrder.abcListOrder}"/>


      But it seems so damn complicated, I need to define a Java component/attribute for each parameter I want to use in an XML file.

      Is there possible to use a static parameter, like I want to? Am I doing something wrong?

      I'm using Seam 1.2.1.


        • 1. Re: Question: Can static parameters be used in *.page.xml?
          pmuir

          No you can't. Can you explain the use case?

          • 2. Re: Question: Can static parameters be used in *.page.xml?
            christian.bauer

            You can, using value="#{'foo'}" but please promise me you will not append the "name asc" to a database query!

            • 3. Re: Question: Can static parameters be used in *.page.xml?

              Yes, here it is:

              It is a Seam generated application, with some modifications, so we have
              AbcList & AbcEdit for some of the entities.

              It was required that the AbcList be ordered when you open the page by the first column.

              So I have 3 way to open AbcList:
              1) From the menu (s:link)
              2) From the AbcEdit screen, by clicking the "back" button (also s:link)
              3) From the AbcEdit screen, by clicking the "delete" button (which is a h:commandButton), this returns to the AbcList by using a navigation rule defined in AbcEdit.page.xml

              In cases 1) & 2) I can add this:

              <f:param name="order" value="name asc"/>

              And it works fine.
              For 3) I tried to use the same but it is ignored. Then I placed the parameter in the AbcEdit.page.xml as in the first post, with the static value and it doesn't work. So I defined a Java bean with an attribute to keep the defeult order and now it works. But, as I said, it is so damn complicated to do.

              Since there is no alternative I'll guess we'll stick with this solution.

              • 4. Re: Question: Can static parameters be used in *.page.xml?

                 

                "christian.bauer@jboss.com" wrote:
                You can, using value="#{'foo'}" but please promise me you will not append the "name asc" to a database query!



                Hei, tnx

                Well, I guess it is used in a hibernate query. It is used to order the list of objects by the first column. But this is what the generated pages do anyway, only that they do it only when you click on the column headers:


                <h:column>
                 <f:facet name="header">
                 <s:link styleClass="columnHeader"
                 value="Name #{abcList.order=='name asc' ? messages.down : ( abcList.order=='name desc' ? messages.up : '' )}">
                 <f:param name="order" value="#{abcList.order=='name asc' ? 'name desc' : 'name asc'}"/>
                 </s:link>
                 </f:facet>
                 #{abc.name}
                </h:column>


                We just need a default order when the page is loaded the first time.

                • 5. Re: Question: Can static parameters be used in *.page.xml?
                  pmuir

                  The reason that you can't easily provide static parameters to pages.xml is that it is not normally a good design choice.

                  If you are using seam-gen/seam application framework then you would be much better off using an EntityQuery and components.xml to specify the default order. This also gets around the problem of ql injection christian discusses.

                  • 6. Re: Question: Can static parameters be used in *.page.xml?
                    franciscoacb

                    If you are installing your Query components by configuring them in components.xml then you can specify a default order like this (from docs):

                    <framework:entity-query name="people"
                    ejbql="select p from Person p"
                    order="lastName"
                    max-results="20"/>

                    but if you are using extension you can do this (there's no examples from docs about query objects usage by extension, but of course you can look at a Seam-Gen code generated):

                    public class PapelList extends EntityQuery {
                    ...
                    @Override
                    public String getOrder() {
                    if ( super.getOrder() != null )
                    return super.getOrder();
                    else
                    return "sigla asc";
                    }

                    It worked for me, but since I'm very new to Seam (and to web dev at all) I'm not sure if it is the best solution for default order of if it's a "good code"