8 Replies Latest reply on Feb 6, 2010 2:57 PM by looseleaf

    custom component: using c:foreach in the template (SOLVED)

      Hi!

       

        Me again

      I am trying to implement a <select> HTML element with some <option> sub elements. One should be selected, depending on the value. I don't think that the problem would be to mark the right one selected, but I am having troubles creating the list of options. It is a predefined list of tumor stati. I tried to create an ArrayList<String> in the rendrer base class and use foreach in the template:

       

      in the renderer

      {code:Java}

      private ArrayList<String> statesT = new ArrayList();

      ...

      public ArrayList<String> getStatesT() {

        if (statesT.isEmpty()) {

          statesT.add("0");

          statesT.add("1");

          // and so on.

        }

        return this.statesT;

      }

      {code}

       

       

      in the template:

      {code:xml}

      <c:forEach var="stateT" items="#{this:getStatesT()}">

        #{stateT}

      </c:forEach>

      {code}

       

      When building, there's an error in the generated component, that a semicolon is expected. The generated code for the forEach-loop is this:

       


      variables.setVariable("stateT", $from);
      Integer.getInteger(variables.getVariable("stateT").toString()).intValue() < Integer.getInteger($to).toString()).intValue();
      variables.addValueToVariable("stateT", new Integer(1) )

       

      Hm, so how do I accomplish what I am seeking for?

       

      Thanks for pointers,

      Stefan

       

      p.s.: Sorry about the declaration as "question". I was confused by the warning that this thread is not a question.

        • 1. Re: custom component: using c:foreach in the template
          nbelaevski

          I've copied your code and got the following correct statements:

                   Collection com_1 = (Collection)getStatesT();
          for (Iterator iter =  com_1 .iterator(); iter.hasNext();) {
               variables.setVariable("stateT", iter.next());
          writer.writeText(convertToString(variables.getVariable("stateT")),null);
          
          }
          

          It seems that "#{this:getStatesT()}" expression is not resolved correctly - can you please try defining separate variable via cdk:object tag to check this?

          • 2. Re: custom component: using c:foreach in the template

            Thanks for checking Nick!

             

            {code:XML}

            <c:object var="statesT" type="java.util.ArrayList" value="#{this:getStatesT()}" />

            {code}

             

            results in

             

            {code:Java}

            java.util.ArrayList statesT  = getStatesT() ;

            {code}

             


            But using

            {code:xml}

            <c:forEach var="stateT" items="#{statesT}">

              #{stateT}

            </c:forEach>

            {code}

             

            still produces

             

            {code:Java}

            for (

                variables.setVariable("stateT", $from);

                Integer.getInteger(variables.getVariable("stateT").toString()).intValue() < Integer.getInteger($to).toString()).intValue();

                variables.addValueToVariable("stateT", new Integer(1) )

                ) {

            writer.writeText(convertToString(variables.getVariable("stateT")),null);

            {code}

             

            Hm. We're using the RichFaces 3.3.2GA libraries and CDK, if that matters.

             

            Ahhh, stupid - what's the correct namespace for the CDK tags as described in chapter 10 of the CDK developer guide? The namespace is not mentioned there. And it's probably not http://java.sun.com/jsf/core, which the c: prefix is used in our component. Is it?

             

            Stefan

            • 3. Re: custom component: using c:foreach in the template

              I searched the Richfaces SVN and found the implementation of "columns". The namespace there is xmlns:c="http://java.sun.com/jstl/core".

               

              I tried that, no effect.

               

              After taking a look at the CDK guide again,  I simply tried returning a comma separated string, which should work as well:

               

              {code:xml}

              <?xml version="1.0" encoding="UTF-8"?>

              <f:root

                   xmlns:f="http://ajax4jsf.org/cdk/template"

                   xmlns:c="http://java.sun.com/jstl/core"

                   xmlns:ui=" http://ajax4jsf.org/cdk/ui"

                   xmlns:u=" http://ajax4jsf.org/cdk/u"

                   xmlns:x=" http://ajax4jsf.org/cdk/x"

                   xmlns:h="http://ajax4jsf.org/cdk/h"

                   class="at.ac.meduniwien.hno.hnoonconet.faces.renderkit.html.InputTNMRenderer"

                   baseclass="at.ac.meduniwien.hno.hnoonconet.faces.renderkit.InputTNMRendererBase"

                   component="at.ac.meduniwien.hno.hnoonconet.faces.component.UIInputTNM"

                    >

               

                   <h:styles>/at/ac/meduniwien/hno/hnoonconet/faces/renderkit/html/css/inputTNM.xcss</h:styles>

                   <f:clientid var="clientId"/>

                <c:object var="statesT" type="java.lang.String" value="#{this:getStatesT()}" />


                <c:forEach var="st" items="#{this:getStatesT()}">

                    #{st}

                </c:forEach>


                <c:forEach var="st" items="statesT">

                    #{st}

                </c:forEach>

              </f:root>

              {code}

               

              and this in my InputTNMRendererBase

              {code:Java}public String getStatesT() {

                  return "0,1,2";

              }{code}

               

              Same error as before.

               

              I am becoming desperate with that...

               

              Stefan

              p.s.: The AJAX editor doesn't work properly in Firefox 3.0.4 neither...The cursor jumps around at will, when using Home, End and cursor keys. Whoever is responsible for the web forum: Please provide a simple <textarea> for posting messages. Or NNTP, pretty please

              • 4. Re: custom component: using c:foreach in the template

                Today I tried using the 3.3.1.GA RichFaces libraries, as it is described in the Richfacses 3.3.2 CDK guide. It didn't work neither

                 

                [...]

                 

                I made it even simpler:

                {code:xml}<c:forEach var="t" items="1,2,3">

                  #{t}

                </c:forEach>{code}

                 

                Using xmlns:c="http://java.sun.com/jstl/core" as namespace still produces this output:

                {code:Java}for (

                  variables.setVariable("t", $from);

                  Integer.getInteger(variables.getVariable("t").toString()).intValue() < Integer.getInteger($to).toString()).intValue();

                  variables.addValueToVariable("t", new Integer(1) )

                )

                {code}


                Hm....

                • 5. Re: custom component: using c:foreach in the template
                  nbelaevski

                  Stefan,

                   

                  Can you please create small example project, so I'll be able to reproduce the issue locally?

                  • 6. Re: custom component: using c:foreach in the template

                    OK, I followed the procedure in Chapters 3+4 of the CDK developer guide for version 3.3.2.GA.

                     

                    The only differences: Sometimes the guide mentions 3.3.1.GA as version (in creating the archetype, and some pom.xml files). I changed those to 3.3.2.GA.

                     

                    Maven is 2.2.1, Ant is 1.8.0RC1

                     

                    I attached sandbox.zip which is a rudimentary project followed from the inputDate example but with the actual setup that we're using. I just skipped the UIInputTNM implementation and the RendererBase class apart from the desired ArrayList. And the template is also very basic.

                     

                    The only changes to the template are the <c:*> elements.

                     

                    setings.xml is Maven's configuration.

                     

                    Stefan


                    • 7. Re: custom component: using c:foreach in the template
                      nbelaevski

                      Hi Stefan,

                       

                      Looks like a bug in 3.3.2 CDK. 3.3.3.BETA1 should work ok (you can still use 3.3.3.BETA1 CDK & RF 3.3.2).

                      • 8. Re: custom component: using c:foreach in the template

                        Thanks for checking, Nick!

                         

                          Works like a charm with the maven-cdk-plugin 3.3.3.BETA1.

                         

                        I really appreciate your help.