java - JSF 2: property on bean assumed to be written instead of read? -
i have following simple view main.xhtml
, request url like:
http://localhost:8080/myproj/main.jsf?pq=2
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich" template="/templating/layout-2col.xhtml"> <ui:define name="metadata"> <f:metadata> <f:viewparam name="pq" value="#{pqhome.id}" required="true"> <f:convertnumber integeronly="#{true}" /> </f:viewparam> <f:event type="prerenderview" listener="#{pqhome.init}" /> </f:metadata> </ui:define> ... <ui:define name="content-right"> <h:form> <rich:panel> <f:facet name="header"> menu </f:facet> <rich:tabpanel binding="#{pqhome.tabpanel}"> </rich:tabpanel> </rich:panel> </h:form> </ui:define> </ui:composition>
my bean:
@managedbean @requestscoped public class pqhome implements serializable { @inject private pqservice pqservice; //@managedproperty(value="#{param.pq}") private integer id; private prequalification instance; @inject private pqpartnerlistquery pplq; private list<partner> partners; private uitabpanel tabpanel; private list<uicomponent> tabs; //@postconstruct public void init() { system.out.println("id " + id); instance = pqservice.findsingleinstance(id); partners = pplq.getitemsforpq(id); system.out.println("building tab manually..."); // rf way... facescontext fc = facescontext.getcurrentinstance(); application application = facescontext.getcurrentinstance().getapplication(); tabpanel = (uitabpanel)application.createcomponent(uitabpanel.component_type); tabpanel.setswitchtype(switchtype.client); tabs = tabpanel.getchildren(); ( partner partner : partners ) { company co = partner.getcompany(); string companyname = co.getname(); uitab tab = (uitab)application.createcomponent(uitab.component_type); //tab.settitle(companyname); tab.setname(companyname); tab.setid(co.getdndtype()); tabs.add(tab); } string firsttabname = partners.get(0).getcompany().getname(); system.out.println("first tab name = " + firsttabname); tabpanel.setactiveitem(firsttabname); } public integer getid() { return id; } public void setid(integer id) { this.id = id; } public prequalification getinstance() { return instance; } public uitabpanel gettabpanel() { return tabpanel; } }
when requesting above page error saying:
an error occurred: /main.xhtml @221,53 binding="#{pqhome.tabpanel}": class 'de.mycomp.myproj.beans.pqhome' not have writable property 'tabpanel'. +- stack trace javax.el.propertynotwritableexception: /main.xhtml @221,53 binding="#{pqhome.tabpanel}": class 'de.mycomp.myproj.beans.pqhome' not have writable property 'tabpanel'. @ com.sun.faces.facelets.el.tagvalueexpression.setvalue(tagvalueexpression.java:136) @ com.sun.faces.application.applicationimpl.createcomponentapplyannotations(applicationimpl.java:1897) @ com.sun.faces.application.applicationimpl.createcomponent(applicationimpl.java:1109) @ org.jboss.as.weld.webtier.jsf.forwardingapplication.createcomponent(forwardingapplication.java:122) @ com.sun.faces.facelets.tag.jsf.componenttaghandlerdelegateimpl.createcomponent(componenttaghandlerdelegateimpl.java:511) @ com.sun.faces.facelets.tag.jsf.componenttaghandlerdelegateimpl.apply(componenttaghandlerdelegateimpl.java:157) @ javax.faces.view.facelets.delegatingmetataghandler.apply(delegatingmetataghandler.java:120) @ javax.faces.view.facelets.compositefacelethandler.apply(compositefacelethandler.java:98) @ javax.faces.view.facelets.delegatingmetataghandler.applynexthandler(delegatingmetataghandler.java:137) @ org.richfaces.view.facelets.html.behaviorsaddingcomponenthandlerwrapper.applynexthandler(behaviorsaddingcomponenthandlerwrapper.java:55) ... @ org.jboss.weld.servlet.conversationpropagationfilter.dofilter(conversationpropagationfilter.java:67) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:280) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:248) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:275) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:161) @ org.jboss.as.web.namingvalve.invoke(namingvalve.java:57) @ org.jboss.as.jpa.interceptor.webnontxemcloservalve.invoke(webnontxemcloservalve.java:49) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:154) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:102) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:109) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:362) @ org.apache.coyote.http11.http11processor.process(http11processor.java:877) @ org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:667) @ org.apache.tomcat.util.net.jioendpoint$worker.run(jioendpoint.java:951) @ java.lang.thread.run(unknown source)
why jsf assume tab panel el binding="#{pqhome.tabpanel}"
written/writable here? there way fix this, tell jsf read here?
note: workaround uncomment @managedproperty
, @postconstruct
annotations in bean , outcomment <f:event ...>
in view, don't see why should using <f:viewparam>
, <f:metadata>
@ all...
thanks
jsf needs set obtained or auto-created non-null component in backing bean told binding
. need provide setter method. no excuses. if getter returned manually created component, same component set. jsf won't set auto-created one.
Comments
Post a Comment