我写了一个自定义转换器,代码如下:
package tn.talan.testFramework.converter;
import java.util.ArrayList;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import org.objectweb.salome_tmf.data.User;
import org.objectweb.salome_tmf.ihm.admin.AdministrationFinalOld;
@FacesConverter (value="userConverter")
public class UserConverter implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
User selectedUserfield = null;
ArrayList<User> usersList;
String userLogin;
System.out.println("converter getAsObject ");
AdministrationFinalOld administration=new AdministrationFinalOld();
administration.onInit();
usersList = administration.getAllUsers();
if (usersList!=null){
for(int i=0 ;i<usersList.size();i++)
{ selectedUserfield=usersList.get(i);
userLogin=selectedUserfield.getLoginFromModel();
if (userLogin.equals(value))
return usersList.get(i);
}
}
return null;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
System.out.println("converter getAsString "+value);
if (value==null) return "";
return ((User) value).getName();
}
这是我的面孔配置:
<?xml version="1.0"?>
<faces-config
version="2.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee
/web-facesconfig_2_0.xsd">
<converter>
<converter-id>userConverter</converter-id>
<converter-class>tn.talan.testFramework.converter.UserConverter</converter-class>
</converter>
<converter>
<converter-id>projectConverter</converter-id>
<converter-class>tn.talan.testFramework.converter.ProjectConverter</converter-class>
</converter>
<converter>
<converter-id>URLCustomValidator</converter-id>
<converter-class>tn.talan.testFramework.converter.URLCustomValidator</converter-class>
</converter>
但是当我运行时出现此错误:
java.lang.ClassNotFoundException: tn.talan.testFramework.converter.UserConverter
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
at com.sun.faces.util.Util.loadClass(Util.java:287)
at com.sun.faces.application.ApplicationImpl.newThing(ApplicationImpl.java:1659)
at com.sun.faces.application.ApplicationImpl.createConverter(ApplicationImpl.java:1275)
at com.sun.faces.facelets.tag.jsf.ValueHolderRule$LiteralConverterMetadata.applyMetadata(ValueHolderRule.java:81)
at com.sun.faces.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:77)
at javax.faces.view.facelets.MetaTagHandler.setAttributes(MetaTagHandler.java:125)
at javax.faces.view.facelets.DelegatingMetaTagHandler.setAttributes(DelegatingMetaTagHandler.java:98)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.doNewComponentActions(ComponentTagHandlerDelegateImpl.java:398)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:155)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:116)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:94)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:133)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:180)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:116)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:94)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:133)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:180)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:116)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:94)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:133)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:180)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:116)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:133)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:180)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:116)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:94)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:133)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:180)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:116)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:94)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:133)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:180)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:116)
at com.sun.faces.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:99)
at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:174)
at com.sun.faces.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:392)
at com.sun.faces.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:363)
at com.sun.faces.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:104)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:94)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:133)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:180)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:116)
at com.sun.faces.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:163)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:94)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:89)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:94)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:79)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:304)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:363)
at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:342)
at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:196)
at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:151)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:89)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:79)
at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:148)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:734)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:96)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:135)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:335)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)