I want to dynamically create controls in my bean. I am using JSF 2.0
HtmlOutputTag objHtmlOutputTag = new HtmlOutputTag();
Now which property of HtmlOutputTag should I set to set the content of HtmlOutputTag?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
HtmlOutputTagrepresents a tag, not a component. Rather useHtmlOutputText. Then, you can just set thevalueproperty, exactly as you would do in a real component in the JSF page. If you need it to be aValueExpressionrather than a rawvalue, then you need to create it usingExpressionFactory#createValueExpression(). Here’s a kickoff example:where the convenience method
createValueExpression()here look like:hide it far away in some utility class so that you don’t need to repeat all that code again and again 😉 The
valueTypeargument obviously should represent the actual type of the property.The final result in the JSF page should then look like this:
That said, depending on the functional requirement, there may indeed be better and cleaner ways to solve the functional requirement. If you want, you can elaborate a bit more about it so that we can if necessary suggest better ways.