Struts 2
  1. Struts 2
  2. WW-3174

Update UI tags in freemarker to allow custom html tag attributes

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.8
    • Fix Version/s: 2.3.3
    • Component/s: None
    • Labels:
      None
    • Flags:
      Important
    1. WW-3174-2.patch
      3 kB
      zhouyanming
    2. WW-3174.patch
      3 kB
      zhouyanming
    3. patch.txt
      2 kB
      zhouyanming

      Issue Links

        Activity

        Hide
        Jasper Rosenberg added a comment -

        Also known as Dynamic Attributes.

        Show
        Jasper Rosenberg added a comment - Also known as Dynamic Attributes.
        Hide
        zhouyanming added a comment -

        seems only you are active this time

        Show
        zhouyanming added a comment - seems only you are active this time
        Hide
        musachy added a comment -

        dont we already have this?

        Show
        musachy added a comment - dont we already have this?
        Hide
        Wes Wannemacher added a comment -

        Yeah, as far as I know most of the tags already do this... Is there a particular tag that isn't doing what you want?

        Show
        Wes Wannemacher added a comment - Yeah, as far as I know most of the tags already do this... Is there a particular tag that isn't doing what you want?
        Hide
        Jasper Rosenberg added a comment -

        I need it form elements (so I can pass in some random facebook form attribute extensions.) It has been a while since I entered this issue, but my memory is that it doesn't work with freemarker.

        Show
        Jasper Rosenberg added a comment - I need it form elements (so I can pass in some random facebook form attribute extensions.) It has been a while since I entered this issue, but my memory is that it doesn't work with freemarker.
        Hide
        zhouyanming added a comment -

        done with jsp not freemarker

        Show
        zhouyanming added a comment - done with jsp not freemarker
        Hide
        musachy added a comment -

        I am not sure this can be done with freemarker, unless we create a super attribute that will take a map of the dynamic attributes, like

        <@s.a dyn="%

        {'key', 'value', 'key2', 'val2'}

        " ../>

        Show
        musachy added a comment - I am not sure this can be done with freemarker, unless we create a super attribute that will take a map of the dynamic attributes, like <@s.a dyn="% {'key', 'value', 'key2', 'val2'} " ../>
        Hide
        zhouyanming added a comment -

        http://freemarker.sourceforge.net/docs/ref_directive_macro.html

        <#macro img src extra...>
        <img src="/context$

        {src?html}

        "
        <#list extra?keys as attr>
        $

        {attr}

        ="$

        {extra[attr]?html}

        "
        </#list>
        >
        </#macro>
        <@img src="/images/test.png" width=100 height=50 alt="Test"/>

        Show
        zhouyanming added a comment - http://freemarker.sourceforge.net/docs/ref_directive_macro.html <#macro img src extra...> <img src="/context$ {src?html} " <#list extra?keys as attr> $ {attr} ="$ {extra[attr]?html} " </#list> > </#macro> <@img src="/images/test.png" width=100 height=50 alt="Test"/>
        Hide
        zhouyanming added a comment -

        here is a patch

        Show
        zhouyanming added a comment - here is a patch
        Hide
        zhouyanming added a comment -

        <@s.textfield label="%

        {getText('username')}

        " name="username" cssClass="required" placeholder="input username" autocomplete="off" />
        placeholder and autocomplete are not supported before apply this patch

        Show
        zhouyanming added a comment - <@s.textfield label="% {getText('username')} " name="username" cssClass="required" placeholder="input username" autocomplete="off" /> placeholder and autocomplete are not supported before apply this patch
        Hide
        zhouyanming added a comment -

        here is latest version patch
        read standard attribute names for each component not only UIBean

        Show
        zhouyanming added a comment - here is latest version patch read standard attribute names for each component not only UIBean
        Hide
        zhouyanming added a comment -

        please consider apply WW-3174.patch,thanks.

        Show
        zhouyanming added a comment - please consider apply WW-3174 .patch,thanks.
        Hide
        zhouyanming added a comment -

        here is the latest version patch,I have use it for a long time in production environment,please consider it

        Show
        zhouyanming added a comment - here is the latest version patch,I have use it for a long time in production environment,please consider it
        Hide
        Lukasz Lenart added a comment -

        I'm not really sure if this is correct:

        if (Modifier.isProtected(f.getModifiers()) 
            && (f.getType().equals(String.class) || clz.equals(ListUIBean.class) && f.getName().equals("list")))
                standardAttributes.add(f.getName());
        

        field must be String or ListUIBean and name == list ...

        Show
        Lukasz Lenart added a comment - I'm not really sure if this is correct: if (Modifier.isProtected(f.getModifiers()) && (f.getType().equals( String .class) || clz.equals(ListUIBean.class) && f.getName().equals( "list" ))) standardAttributes.add(f.getName()); field must be String or ListUIBean and name == list ...
        Hide
        zhouyanming added a comment -

        UIBean:

        protected String templateSuffix;
        protected String template;
        protected String templateDir;
        protected String theme;
        protected String key;
        protected String id;
        protected String cssClass;
        protected String cssStyle;
        protected String ...;

        ListUIBean:
        protected Object list;
        protected String listKey;
        protected String listValue;

        I know it's not strict,but it's satisfied in current version,maybe it needs refactor when adding new subclass of UIBean contains field type is not protected String in the future

        Show
        zhouyanming added a comment - UIBean: protected String templateSuffix; protected String template; protected String templateDir; protected String theme; protected String key; protected String id; protected String cssClass; protected String cssStyle; protected String ...; ListUIBean: protected Object list; protected String listKey; protected String listValue; I know it's not strict,but it's satisfied in current version,maybe it needs refactor when adding new subclass of UIBean contains field type is not protected String in the future
        Hide
        Lukasz Lenart added a comment -

        I meant, that there is one parenthesis missing

        if (Modifier.isProtected(f.getModifiers()) 
            && (f.getType().equals(String.class) || (clz.equals(ListUIBean.class) && f.getName().equals("list"))))
            standardAttributes.add(f.getName());
        

        so it should be either String or (ListUIBean and list)

        Show
        Lukasz Lenart added a comment - I meant, that there is one parenthesis missing if (Modifier.isProtected(f.getModifiers()) && (f.getType().equals( String .class) || (clz.equals(ListUIBean.class) && f.getName().equals( "list" )))) standardAttributes.add(f.getName()); so it should be either String or (ListUIBean and list)
        Hide
        zhouyanming added a comment -

        yes,please consider WW-3174-2.patch in attachments

        Show
        zhouyanming added a comment - yes,please consider WW-3174 -2.patch in attachments
        Hide
        Lukasz Lenart added a comment - - edited

        Both patches are identical in terms of if clause

        Show
        Lukasz Lenart added a comment - - edited Both patches are identical in terms of if clause
        Hide
        zhouyanming added a comment -

        WW-3174-2.patch supports "dynamicAttributes" as dynamicAttributes like this
        <@s.textfield name="test" dynamicAttributes=

        {"placeholder":"input...","foo":"bar"}

        />

        Show
        zhouyanming added a comment - WW-3174 -2.patch supports "dynamicAttributes" as dynamicAttributes like this <@s.textfield name="test" dynamicAttributes= {"placeholder":"input...","foo":"bar"} />
        Hide
        Lukasz Lenart added a comment -

        I understand that, but I'm referring to the >>if<< clause above which isn't clear for me. And without unit test it's hard to grasp why is it this way :/

        Show
        Lukasz Lenart added a comment - I understand that, but I'm referring to the >>if<< clause above which isn't clear for me. And without unit test it's hard to grasp why is it this way :/
        Hide
        zhouyanming added a comment -

        fields which is "protected String" or named "list" in ListUIBean are stardard attributes,so the others are dynamic attributes,and should put into dynamicAttributes,that's all I modified,there is no magic.
        it's not so easy to write a unit test for UI rendering,but I have patch it in many projects,it works perfect.

        Show
        zhouyanming added a comment - fields which is "protected String" or named "list" in ListUIBean are stardard attributes,so the others are dynamic attributes,and should put into dynamicAttributes,that's all I modified,there is no magic. it's not so easy to write a unit test for UI rendering,but I have patch it in many projects,it works perfect.
        Hide
        Lukasz Lenart added a comment - - edited

        Patch committed, test case added, thanks for support! Docs updated as well
        https://cwiki.apache.org/confluence/display/WW/Freemarker+Support

        Show
        Lukasz Lenart added a comment - - edited Patch committed, test case added, thanks for support! Docs updated as well https://cwiki.apache.org/confluence/display/WW/Freemarker+Support
        Hide
        zhouyanming added a comment -

        https://cwiki.apache.org/confluence/display/WW/Freemarker+Support

        <@s.textfield name="test" dynamicAttributes=

        {"placeholder":"input","foo":"bar"}

        />
        should be
        <@s.textfield name="test" placeholder="input" foo="bar"/>

        Show
        zhouyanming added a comment - https://cwiki.apache.org/confluence/display/WW/Freemarker+Support <@s.textfield name="test" dynamicAttributes= {"placeholder":"input","foo":"bar"} /> should be <@s.textfield name="test" placeholder="input" foo="bar"/>
        Hide
        Lukasz Lenart added a comment -

        but you put the same example above ?

        Show
        Lukasz Lenart added a comment - but you put the same example above ?
        Hide
        Hudson added a comment -

        Integrated in Struts2 #444 (See https://builds.apache.org/job/Struts2/444/)
        WW-3174 adds logic to support dynamic attributes in tags used with FreeMarker templates (Revision 1310221)

        Result = SUCCESS
        lukaszlenart :
        Files :

        • /struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java
        • /struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
        • /struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/freemarker/dynaAttributes.ftl
        • /struts/struts2/trunk/core/src/test/resources/struts.xml
        Show
        Hudson added a comment - Integrated in Struts2 #444 (See https://builds.apache.org/job/Struts2/444/ ) WW-3174 adds logic to support dynamic attributes in tags used with FreeMarker templates (Revision 1310221) Result = SUCCESS lukaszlenart : Files : /struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java /struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java /struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/freemarker/dynaAttributes.ftl /struts/struts2/trunk/core/src/test/resources/struts.xml
        Hide
        Lukasz Lenart added a comment -

        I think I got it

        Without your patch, support for Dynamic Attributes looks like this:

        <@s.textfield name="test" dynamicAttributes={"placeholder":"input","foo":"bar"}/>
        

        with your patch in place, alternative syntax is possible:

        <@s.textfield name="test" placeholder="input" foo="bar"/>
        

        Both are supported

        Show
        Lukasz Lenart added a comment - I think I got it Without your patch, support for Dynamic Attributes looks like this: <@s.textfield name= "test" dynamicAttributes={ "placeholder" : "input" , "foo" : "bar" }/> with your patch in place, alternative syntax is possible: <@s.textfield name= "test" placeholder= "input" foo= "bar" /> Both are supported
        Hide
        Hudson added a comment -

        Integrated in Struts2 #445 (See https://builds.apache.org/job/Struts2/445/)
        WW-3174 additional test case for Dynamic Attributes support (Revision 1310417)

        Result = SUCCESS
        lukaszlenart :
        Files :

        • /struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java
        • /struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java
        • /struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/freemarker/dynaAttributes.ftl
        Show
        Hudson added a comment - Integrated in Struts2 #445 (See https://builds.apache.org/job/Struts2/445/ ) WW-3174 additional test case for Dynamic Attributes support (Revision 1310417) Result = SUCCESS lukaszlenart : Files : /struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/UIBean.java /struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/freemarker/FreeMarkerResultTest.java /struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/freemarker/dynaAttributes.ftl

          People

          • Assignee:
            Lukasz Lenart
            Reporter:
            zhouyanming
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development