0

I access the Attributes of my composite component this way:

enum PropertyKeys {comments, currentUserUsername}

@SuppressWarnings("unchecked")
private <T> T getAttribute(PropertyKeys propertyKey){
    return (T) getStateHelper().eval(propertyKey);
}

private <T> void setAttribute(PropertyKeys propertyKey, T value){
    getStateHelper().put(propertyKey, value);
}

private List<Comment> getComments() {
    return getAttribute(PropertyKeys.comments);
}

private String getCurrentUserUsername() {
    return getAttribute(PropertyKeys.currentUserUsername);
}

This works for the list (comment) but not for the String (CurrentUserUsername), when i pass the username this way:

<tr:commentBox comments="#{main.comments}" currentUserUsername="Hans" [...] />

But when i pass it this way:

<tr:commentBox comments="#{main.comments}" currentUserUsername="#{'Hans'}" [...] />

It works.

I dont want that anybody who will use my component have to put strings in as EL ...

Is there a solution so i can pass strings in as in the first snippet ?

Nick Russler
  • 4,608
  • 6
  • 51
  • 88

1 Answers1

0

I found a workarround but i don't think that i should do it this way.. :

@SuppressWarnings("unchecked")
private <T> T getAttribute(PropertyKeys propertyKey){
    T result = (T) getStateHelper().eval(propertyKey);

    if (result == null) {
        result = (T) this.getAttributes().get(propertyKey + "");
    }

    return result;
}
Nick Russler
  • 4,608
  • 6
  • 51
  • 88