1
私はprettyface 3.3.2とJSF 2.2.1を使用しています。私はエンティティオブジェクトにかなりのURLの文字列を変換し、Webページでオブジェクトを使用したい。かなり-config.xmlに:Prettyfacesとコンバータの使い方は?
<url-mapping id="country">
<pattern value="/country/#{countryBean.selectedCountry}">
<convert param="#{countryBean.selectedCountry}" converterId="countryConverter" converterClass="Test.CountryBean" />
</pattern>
<view-id value="/faces/countries/country.xhtml" />
</url-mapping>
country.xhtml:
<f:metadata>
<f:viewParam name="country" value="#{countryBean.selectedCountry}">
<f:converter converterId="countryConverter" />
</f:viewParam>
</f:metadata>
<ui:define name="content">
#{countryBean.selectedCountry.country}
</ui:define>
CountryConverter:
public static EntityCountry country = new EntityCountry();
EntityManagerFactory emf = Persistence.createEntityManagerFactory("testPU");
public EntityCountry getAsObject(FacesContext context, UIComponent component, String value) {
EntityManager em = emf.createEntityManager();
Query query = em.createQuery("SELECT c FROM EntityCountry c WHERE c.url = :countryUrl")
.setParameter("countryUrl", value);
country = (EntityCountry) query.getSingleResult();
return country;
}
public String getAsString(FacesContext context, UIComponent component, Object value) {
EntityCountry c = (EntityCountry) value;
return c.getUrl();
}
私はgetAsObjectメソッドにブレークポイントを切り替えますが、それはブレークポイントにヒットしません。 -config.xmlが直面している:
<converter>
<converter-id>countryConverter</converter-id>
<converter-class>Test.CountryConverter</converter-class>
</converter>
<managed-bean>
<managed-bean-name>countryBean</managed-bean-name>
<managed-bean-class>Test.CountryBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
CountryBean:
@Named("countryBean")
@SessionScoped
public class CountryBean implements Serializable {
private EntityCountry selectedCountry;
public EntityCountry getSelectedCountry() { return selectedCountry; }
public void setSelectedCountry(EntityCountry newValue) { selectedCountry = newValue; }
}
とエラー:
PrettyFaces: Exception occurred while processing <country:#{countryBean.selectedCountry}> for URL </country/turkiye>
- Stack Trace
com.ocpsoft.pretty.PrettyException: PrettyFaces: Exception occurred while processing <country:#{countryBean.selectedCountry}> for URL
</country/turkiye>
at com.ocpsoft.pretty.faces.beans.ParameterInjector.injectPathParams(ParameterInjector.java:96)
at com.ocpsoft.pretty.faces.beans.ParameterInjector.injectParameters(ParameterInjector.java:54)
at com.ocpsoft.pretty.faces.event.PrettyPhaseListener.afterPhase(PrettyPhaseListener.java:98)
at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:189)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:107)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:785)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:649)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:483)
at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:454)
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:350)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:300)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:110)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.el.ELException: java.lang.IllegalArgumentException: Cannot convert turkiye of type class
java.lang.String to class Test.EntityCountry
at com.sun.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:68)
at org.jboss.weld.util.el.ForwardingExpressionFactory.coerceToType(ForwardingExpressionFactory.java:37)
at com.ocpsoft.pretty.faces.util.FacesElUtils.setValue(FacesElUtils.java:86)
at com.ocpsoft.pretty.faces.beans.ParameterInjector.injectPathParams(ParameterInjector.java:90)
... 46 more
Caused by: java.lang.IllegalArgumentException: Cannot convert turkiye of type class java.lang.String to
class Test.EntityCountry
at com.sun.el.lang.ELSupport.coerceToType(ELSupport.java:397)
at com.sun.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:66)
... 49 more
ありがとうございました。現在は動作しています。私はf:metadataとviewparamsなしで試してみました。私は変換できません。あなたはviewparamsなしで変換する方法を言うことができますか? – Deniz
PrettyFaces4は、この機能を追加するのを待たなければなりませんが、PrettyFaces 3には入っていません。安定して動作するには、あまりにも多くの問題があります。 – Lincoln