How to repeat output of text via simple for loop in Facelets without model?

后端 未结 2 1456
轻奢々
轻奢々 2021-01-30 17:48

How to repeat output of some content in JSF using only standard tags (ui:, h: etc) ? In other words - how to do equivalent to PHP code below in JSF ? I immediat

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-30 18:38

    Either use instead (true, mixing JSTL with JSF is sometimes frowned upon, but this should not harm in your particular case because you seem to want to create the view "statically"; it does not depend on any dynamic variables):

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

    Or create an EL function to create a dummy array for :

    package com.example.util;
    
    public final class Functions {
    
        private Functions() {
            //
        }
    
        public static Object[] createArray(int size) {
            return new Object[size];
        }
    }
    

    which is registered in /WEB-INF/util.taglib.xml:

    
    
        http://example.com/util/functions 
        
            createArray
            com.example.util.Functions
            Object[] createArray(int)
        
    
    

    and is been used as follows

    xmlns:util="http://example.com/util/functions"
    ...
    
        
    content

    Update: I just posted an enhancement request to add the begin and end attributes to : http://java.net/jira/browse/JAVASERVERFACES-2240

    Update 2: I have personally implemented it for JSF 2.3 as per https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1102 Since Mojarra 2.3-m06 you must be able to use

    
        
    content

提交回复
热议问题