Custom converter in JSF 2 with arguments

后端 未结 4 1106
一生所求
一生所求 2020-12-14 20:54

I\'m trying to implement a custom truncate converter, which truncates a string at a given index and adds a continuation symbol. The converter works fine, only when i hard co

4条回答
  •  感动是毒
    2020-12-14 21:05

    Based on @Maks solution: It's possible to combine the converter and the attribute in one tag:

    
        http://mycompany.com/some-identifier
        
            truncate
            
                bla.blablabla.Truncate
            
            
                truncateIndex
            
        
    
    

    Then you can use the converter like this:

    
    
      
    
    
    

    You also don't need to grab the parameter from the component-attributes. A bean-property with the same name will be populated automatically:

    @FacesConverter("bla.blablabla.Truncate")
    public class Truncate implements Converter {
    
        private String truncateIndex;
    
        // getters + setters
    
        ...
    
    }
    

提交回复
热议问题