jsf - custom boolean converter to set style class -


a converter defined in faces-config.xml changes boolean string "yes" or "no"

<converter>     <converter-id>booleanconverter</converter-id>     <converter-class>com.example.booleanconverter</converter-class> </converter> 

this works fine using

<h:outputtext value="#{bean.booleanvalue}" converter="booleanconverter" /> 

but if intention style surrounding div element possible using converter? example if converter defined return string "booleantrue" , "booleanfalse" (which defined in css)

<converter>     <converter-id>booleanstyleconverter</converter-id>     <converter-class>com.example.booleanstyleconverter</converter-class> </converter> 

could like:

<div class="#{booleanstyleconverter.getasstring(null,null,bean.booleanvalue)}">     <h:outputtext value="#{bean.booleanvalue}" converter="booleanconverter" /> </div> 

defining in backing bean works seems unsatisfactory

public string booleanstyle(boolean value) {     booleanstyleconverter bsc = new booleanstyleconverter();     return bsc.getasstring(null, null, value); } 

the whole point of converter change value that's saved backing bean desirable. why not using class="#{bean.booleanvalue}"?

or simpler still : class="textbox.value eq 'true'? 'booleantrue': 'booleanfalse'", textbox binding of textbox:

<div class="#{textbox.value eq 'true'? 'booleantrue': 'booleanfalse'}">     <h:outputtext binding="#{textbox}" id="textbox" value="#{bean.booleanvalue}"/>  </div> 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -