I've a problem extendign the UISelectOne component...
My classes:
package holderTagClasses;
import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.el.MethodBinding;
import javax.faces.el.ValueBinding;
import javax.faces.event.ValueChangeEvent;
import javax.faces.webapp.UIComponentTag;
public class BDE_IAS_ComboTag extends UIComponentTag{
String lista;
String listaValores;
String value;
String valueChangeListener;
public String getValueChangeListener() {
return valueChangeListener;
}
public void setValueChangeListener(String valueChangeListener) {
this.valueChangeListener = valueChangeListener;
}
public void setLista(String lista){
this.lista=lista;
}
public String getLista(){
return lista;
}
public void setListaValores(String lista){
this.listaValores=lista;
}
public String getListaValores(){
return listaValores;
}
public void setValue(String valor){
this.value=valor;
}
public String getValue(){
return value;
}
public void release() {
// the super class method should be called
super.release();
lista=null;
value=null;
valueChangeListener=null;
listaValores=null;
}
protected void setProperties(UIComponent component) {
super.setProperties(component);
if (lista != null) {
if (isValueReference(lista)) {
ValueBinding vb =
FacesContext.getCurrentInstance().getApplication().createValueBinding(lista);
component.setValueBinding("lista", vb);
} else {
if(lista.length()==0){
lista=null;
}
else{
component.getAttributes().put("lista",lista);
}
}
}
if (listaValores != null) {
if (isValueReference(listaValores)) {
ValueBinding vb
=FacesContext.getCurrentInstance().getApplication().createValueBinding(listaValores);
component.setValueBinding("listaValores", vb);
} else {
if(listaValores.length()!=0){
component.getAttributes().put("listaValores",listaValores);
}
else{
if(lista!=null){
if(lista.length()>0){
ValueBinding vb
=FacesContext.getCurrentInstance().getApplication().createValueBinding(lista);
component.setValueBinding("listaValores", vb);
}
}
}
}
}
if (value!=null) {
if (isValueReference(value)) {
ValueBinding vb =
FacesContext.getCurrentInstance().getApplication().createValueBinding(value);
component.setValueBinding("value", vb);
}
else {
if(value.length()==0){
value=null;
}
else{
component.getAttributes().put("value",value);
}
}
}
if (valueChangeListener != null) {
if (isValueReference(valueChangeListener)) {
FacesContext context =
FacesContext.getCurrentInstance();
Application app = context.getApplication();
MethodBinding mb =
app.createMethodBinding(valueChangeListener, new Class[] {
ValueChangeEvent.class });
component.getAttributes().put("valueChangeListener",
mb);
}
}
}
public String getRendererType() { return "combo"; }
public String getComponentType() { return "combo"; }
}
package rendererClasses;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.Renderer;
public class ComboRenderer extends Renderer{
public void encodeBegin(FacesContext context, UIComponent combo)
throws IOException {
ResponseWriter writer = context.getResponseWriter();
char salto ='\n';
try{
//ArrayList lista = (ArrayList)getLista();
ArrayList lista =
(ArrayList)combo.getAttributes().get("lista");
ArrayList listaValores= new ArrayList();;
if(lista!=null){
listaValores =
(ArrayList)combo.getAttributes().get("listaValores");
if(listaValores==null){
listaValores=lista;
}
else{
if(listaValores.size()==0){
listaValores=lista;
}
}
}
writer.startElement("select", combo);
writer.writeAttribute("name", combo.getId(), "id");
writer.writeAttribute("id", combo.getId(), "id");
writer.writeAttribute("size", new Integer(1), "size");
int i=0;
String valor;
for(i=0;i<lista.size();i++){
valor = (String)combo.getAttributes().get("value");
if(valor.equals(listaValores.get(i))){
writer.write("<option
value=\""+listaValores.get(i)+"\"
selected>"+lista.get(i)+"</option>"+salto);
}
else{
writer.write("<option
value=\""+listaValores.get(i)+"\">"+lista.get(i)+"</option>"+salto);
}
}
writer.endElement("select");
}
catch(Exception e){
System.out.println(e);
}
}
public void decode(FacesContext context, UIComponent component) {
EditableValueHolder combo = (EditableValueHolder) component;
Map requestMap =
context.getExternalContext().getRequestParameterMap();
String clientId = component.getClientId(context);
if(requestMap.containsKey("Combo"+component.getId())){
String submittedValue = (String)
requestMap.get("Combo"+component.getId());
combo.setSubmittedValue((String) requestMap.get(clientId));
}
}
}
package uIClasses;
import javax.faces.component.UISelectOne;
public class BDE_IAS_UICombo extends UISelectOne{
public BDE_IAS_UICombo() {
setRendererType("combo"); // this component has a renderer
}
}
Faces-config:
<component>
<component-type>combo</component-type>
<component-class>uIClasses.BDE_IAS_UICombo</component-class>
</component>
<render-kit>
<renderer>
<component-family>javax.faces.component.UISelectOne</component-family>
<renderer-type>combo</renderer-type>
<renderer-class>rendererClasses.ComboRenderer</renderer-class>
</renderer>
</render-kit>
TLD:
<tag>
<name>combo</name>
<tag-class>holderTagClasses.BDE_IAS_ComboTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>lista</name>
</attribute>
<attribute>
<name>listaValores</name>
</attribute>
<attribute>
<name>value</name>
</attribute>
<attribute>
<name>valueChangeListener</name>
</attribute>
<attribute>
<name>id</name>
<required>true</required>
</attribute>
</tag>
Someone can help me???
The error I've recieved from the servlet is:
[15/09/05 12:00:45:645 CEST] 2c602c60 WebGroup E SRVE0026E:
[Error de servlet]-[]: java.lang.NullPointerException
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.Throwable.<init>(Throwable.java)
at
java.lang.NullPointerException.<init>(NullPointerException.java:61)
at
javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:675)
at
javax.faces.webapp.UIComponentTag.encodeBegin(UIComponentTag.java:572)
at
javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:459)
at
org.apache.jsp._pruebasIndividuales._jspService(pruebasIndividuales.jsp
)
at
com.ibm.ws.webcontainer.jsp.runtime.HttpJspBase.service(HttpJspBase.java:89)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
com.ibm.ws.webcontainer.jsp.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:344)
at
com.ibm.ws.webcontainer.jsp.servlet.JspServlet.serviceJspFile(JspServlet.java:683)
at
com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java:781)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at
com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at
com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at
com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at
com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at
com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at
com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:1019)
at
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:592)
at
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:204)
at
com.ibm.faces.context.MultipartExternalContextImpl.dispatch(MultipartExternalContextImpl.java:320)
at
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:295)
at
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
at
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
at
com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at
com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at
com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at
com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at
com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at
com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at
com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher..java:1019)
at
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:592)
at
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:204)
at
com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:125)
at
com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:286)
at
com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at
com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at
com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at
com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at
com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:615)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java)
But I'm unable to repair it...PLEASE HELP!!!! ;)