Quick way to create JSF custom component -
i know of 2 ways of creating custom jsf components: 1. native jsf way: creating jsf component class, tag, etc. 2. facelets way: defining component in xhtml file , creating appropriate decrption in facelets taglib.
currently work on project in introducing facelets unfortunately out of question. on other hand, creating custom components standard jsf way seems pain in ass.
is there maybe third party library allows creating custom components in way similar facelets doesn't entail need of using non-standard renderer?
you can limited amount of templating using (for example) jsp:include , f:subview.
alternatively, can extend uicomponent overriding selected methods , provide via existing tag , managed bean using binding
attribute. still requires reasonably detailed understanding of component development (and consequences of choice), cut down number of files/volume of code significantly.
this approach bit of hack, might ok short-term stuff. wouldn't component libraries want distribute or components requiring long term maintenance.
the new component:
public class quickcomponent extends htmloutputtext { @override public void encodeall(facescontext context) throws ioexception { responsewriter writer = context.getresponsewriter(); writer.writetext("i'm not htmloutputtext", null); (uicomponent kid : getchildren()) { if (kid instanceof uiparameter) { uiparameter param = (uiparameter) kid; writer.startelement("br", this); writer.endelement("br"); writer.writetext(param.getname() + "=" + param.getvalue(), null); } } } }
the bean providing instance:
/**request-scope managed bean defined in faces-config.xml*/ public class quickcomponentproviderbean { private quickcomponent quick; public void setquick(quickcomponent quick) { this.quick = quick; } public quickcomponent getquick() { if (quick == null) { quick = new quickcomponent(); } return quick; } }
note: don't reuse single bean property multiple tags in views, or they'll reference same object instance.
adding new component view:
<h:outputtext binding="#{quickcomponentproviderbean.quick}"> <f:param name="hello" value="world" /> </h:outputtext>
note: attributes can defined have not changed. they're fixed tld.
Comments
Post a Comment