I would like to call a setter directly from a command button and pass a value. My problem is that the setter is expecting a Character and jsf if passing it back as a String. Is
This is unfortunately by design. Everything in quotes is in EL treated as String
. A workaround would be to pass String#charAt()
instead.
#{manageItemHandler.dataEntryOp.setBomComplete('Y'.charAt(0))}
This is only ugly. An alternative is to pass its int
codepoint instead, which is 89
for Y
.
#{manageItemHandler.dataEntryOp.setBomComplete(89)}
But this is not exactly self-documenting. Much better is to just make use of enums.
public enum Choice {
Y, N;
}
with
protected Choice bomComplete;
which you can just invoke the desired way
#{manageItemHandler.dataEntryOp.setBomComplete('Y')}
The string 'Y'
will be automatically converted to that enum. As a bonus, enums have many more additional advantages, such as compile time type safety.