You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2011/01/25 20:05:47 UTC
svn commit: r1063405 - in
/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main:
java/org/apache/myfaces/examples/jsf20/converter/ webapp/ webapp/converter/
Author: jakobk
Date: Tue Jan 25 19:05:47 2011
New Revision: 1063405
URL: http://svn.apache.org/viewvc?rev=1063405&view=rev
Log:
EXTCDI-127 Injection in FacesConverter does not work (sample)
Added:
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/Pojo.java
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/PojoBean.java
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/PojoConverter.java
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/PojoFactory.java
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/webapp/converter/
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/webapp/converter/index.xhtml
Modified:
myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/webapp/helloMyFacesCodi.xhtml
Added: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/Pojo.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/Pojo.java?rev=1063405&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/Pojo.java (added)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/Pojo.java Tue Jan 25 19:05:47 2011
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.examples.jsf20.converter;
+
+/**
+ * @author Jakob Korherr
+ */
+public class Pojo
+{
+
+ private int id;
+ private String name;
+
+ public Pojo(int id, String name)
+ {
+ this.id = id;
+ this.name = name;
+ }
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public void setId(int id)
+ {
+ this.id = id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ Pojo pojo = (Pojo) o;
+
+ if (id != pojo.id)
+ {
+ return false;
+ }
+ if (name != null ? !name.equals(pojo.name) : pojo.name != null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = id;
+ result = 31 * result + (name != null ? name.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ return id + "-" + name;
+ }
+
+}
Added: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/PojoBean.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/PojoBean.java?rev=1063405&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/PojoBean.java (added)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/PojoBean.java Tue Jan 25 19:05:47 2011
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.examples.jsf20.converter;
+
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ViewAccessScoped;
+
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.inject.Named;
+import java.io.Serializable;
+
+/**
+ * @author Jakob Korherr
+ */
+@Named
+@ViewAccessScoped
+public class PojoBean implements Serializable
+{
+
+ private Pojo selectedPojo;
+
+ public Converter getConverter()
+ {
+ // workaround for EXTCDI-127
+ return FacesContext.getCurrentInstance().getApplication().createConverter("pojoConverter");
+ }
+
+ public Pojo getSelectedPojo()
+ {
+ return selectedPojo;
+ }
+
+ public void setSelectedPojo(Pojo selectedPojo)
+ {
+ this.selectedPojo = selectedPojo;
+ }
+
+}
Added: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/PojoConverter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/PojoConverter.java?rev=1063405&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/PojoConverter.java (added)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/PojoConverter.java Tue Jan 25 19:05:47 2011
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.examples.jsf20.converter;
+
+import org.apache.myfaces.extensions.cdi.core.api.Advanced;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.convert.FacesConverter;
+import javax.inject.Inject;
+
+/**
+ * @author Jakob Korherr
+ */
+@Advanced
+@FacesConverter("pojoConverter")
+public class PojoConverter implements Converter
+{
+
+ public PojoConverter()
+ {
+ // set breakpoint for instance creation debugging here
+ }
+
+ @Inject
+ private PojoFactory pojoFactory;
+
+ public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) throws ConverterException
+ {
+ return pojoFactory.getPojo(s);
+ }
+
+ public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object o) throws ConverterException
+ {
+ if (o instanceof Pojo)
+ {
+ Pojo pojo = (Pojo) o;
+
+ return Integer.toString(pojo.getId());
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+}
Added: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/PojoFactory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/PojoFactory.java?rev=1063405&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/PojoFactory.java (added)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/converter/PojoFactory.java Tue Jan 25 19:05:47 2011
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.examples.jsf20.converter;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Jakob Korherr
+ */
+@Singleton
+@Named
+public class PojoFactory
+{
+
+ private List<Pojo> pojos;
+
+ public List<Pojo> getPojos()
+ {
+ if (pojos == null)
+ {
+ // some demo values
+ pojos = new ArrayList<Pojo>();
+ pojos.add(new Pojo(1, "Frank"));
+ pojos.add(new Pojo(2, "Karl"));
+ pojos.add(new Pojo(3, "Adam"));
+ }
+
+ return pojos;
+ }
+
+ public Pojo getPojo(String idString)
+ {
+ if (idString == null)
+ {
+ return null;
+ }
+
+ return getPojo(parseId(idString));
+ }
+
+ public Pojo getPojo(int id)
+ {
+ for (Pojo pojo : getPojos())
+ {
+ if (pojo.getId() == id)
+ {
+ return pojo;
+ }
+ }
+
+ return null;
+ }
+
+ private int parseId(String idString) throws IllegalArgumentException
+ {
+ try
+ {
+ return Integer.parseInt(idString);
+ }
+ catch (NumberFormatException e)
+ {
+ throw new IllegalArgumentException("Illegal Pojo id: idString", e);
+ }
+ }
+
+}
Added: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/webapp/converter/index.xhtml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/webapp/converter/index.xhtml?rev=1063405&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/webapp/converter/index.xhtml (added)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/webapp/converter/index.xhtml Tue Jan 25 19:05:47 2011
@@ -0,0 +1,51 @@
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:ui="http://java.sun.com/jsf/facelets">
+
+ <head><title>CODI JSF 2.0 Demo - Advanced Converter</title></head>
+
+ <body>
+ <h3>CODI JSF 2.0 Demo - Advanced Converter</h3>
+
+ <h:outputText value="Selected Pojo: #{pojoBean.selectedPojo}"
+ rendered="#{not empty pojoBean.selectedPojo}" />
+
+ <br/><br/>
+
+ <h:form>
+ <!-- converter="pojoConverter" does not work due to EXTCDI-127 -->
+ <h:selectOneMenu converter="#{pojoBean.converter}" value="#{pojoBean.selectedPojo}">
+ <f:selectItems value="#{pojoFactory.pojos}" var="pojo" itemValue="#{pojo}" itemLabel="#{pojo.name}" />
+ </h:selectOneMenu>
+
+ <h:commandButton value="Select" />
+ </h:form>
+
+ <h:messages />
+ </body>
+</html>
+
\ No newline at end of file
Modified: myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/webapp/helloMyFacesCodi.xhtml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/webapp/helloMyFacesCodi.xhtml?rev=1063405&r1=1063404&r2=1063405&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/webapp/helloMyFacesCodi.xhtml (original)
+++ myfaces/extensions/cdi/trunk/examples/jsf-examples/hello_myfaces-codi_jsf20/src/main/webapp/helloMyFacesCodi.xhtml Tue Jan 25 19:05:47 2011
@@ -36,7 +36,8 @@
<h:link value="ViewAccessScoped example" outcome="viewAccessBeanPage.xhtml"/><br/>
<h:outputLink value="noCodiPage.xhtml">Page without Codi scoped beans</h:outputLink><br/>
- <h:outputLink value="listsample/sampleList.xhtml">List sample</h:outputLink>
+ <h:outputLink value="listsample/sampleList.xhtml">List sample</h:outputLink><br />
+ <h:outputLink value="converter/index.xhtml">Advanced Converter sample</h:outputLink>
<h:messages globalOnly="true"/>
</body>