Bug? p:inputText

UI Components for JSF
Daniel B. Chapman
Posts: 8
Joined: 19 Mar 2011, 01:23

27 Apr 2011, 19:32

This is relatively minor (but I would like to use the p:inputText in this manner)

Relevant Info:
  • + version: Primefaces 2.2.1
    + Server: JBoss 5.1.X GA override to JSF 2
    + Windows: JVM 1_6_024-b07
Its actually pretty simple:

This code fails with:

Code: Select all

									
//STACK
17:30:38,877 WARNING [lifecycle] Argument Error: Parameter targetClass is null
java.lang.NullPointerException: Argument Error: Parameter targetClass is null
	at com.sun.faces.util.Util.notNull(Util.java:305)
	at com.sun.faces.application.ApplicationImpl.createConverter(ApplicationImpl.java:1294)
	at org.primefaces.component.inputtext.InputTextRenderer.getConvertedValue(InputTextRenderer.java:114)
//JSF
 ...
<p:inputText value="#{requestScope.searchString}" />
  <p:commandButton 
    value="Search"
    actionListener="#{inventoryBean.wardrobe.searchViaParameters}"
    update="inventoryWardrobe:searchForm"
    style="margin-left:15px;"
  >
    <f:attribute name="searchString" value="#{requestScope.searchString}"/>
  </p:commandButton>
 ...
changing the component to a standard <h:inputText /> works perfectly. Obviously I can work around this with a request scoped bean. My environment isn't exactly standard, but it isn't that out there so I'm curious if it can be easily reproduced in another production environment.

Its a great component suite--keep up the great work.

aliirawan
Posts: 26
Joined: 15 Nov 2010, 20:09
Location: Jakarta, Indonesia
Contact:

27 Apr 2011, 23:09

It seems there's something wrong with the Converter
Do you use any kind of Converter for the POJO used.
I like to explore new things. There's a way for everything. I believe.

Daniel B. Chapman
Posts: 8
Joined: 19 Mar 2011, 01:23

27 Apr 2011, 23:19

There are not converters registered (facesconfig or web.xml) or used in that element. As you can see it is all inside the requestScope object. I believe the problem is a NPE within the PrimeFaces extension.

EDIT:
I should clarify:

Code: Select all

 <!-- JSF Source Page -->
 ... #{requestScope} ... <!-- Request scope is available as an object so that we don't have to register a lot of request scope beans, instead the map is there, obviously this is null when the element is not used, but the component should notice it is null and not attempt to get the class for the converter -->

Lars-Blumberg
Posts: 4
Joined: 11 Apr 2011, 11:44

19 May 2011, 12:29

I have the same problem using JSF 2.0.4-b09, Primefaces 2.2.1 and Tomcat 7. No converters registered neither.

Is there any workaround so that I can still use p:inputText? As for Daniel, h:inputText works fine.

Code: Select all

WARNING: Argument Error: Parameter targetClass is null
java.lang.NullPointerException: Argument Error: Parameter targetClass is null
   at com.sun.faces.util.Util.notNull(Util.java:309)
   at com.sun.faces.application.ApplicationImpl.createConverter(ApplicationImpl.java:1305)
   at org.primefaces.component.inputtext.InputTextRenderer.getConvertedValue(InputTextRenderer.java:114)
   at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1028)
   at javax.faces.component.UIInput.validate(UIInput.java:958)
   at javax.faces.component.UIInput.executeValidate(UIInput.java:1209)
   at javax.faces.component.UIInput.processValidators(UIInput.java:698)
   at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1085)
   at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1085)
   at javax.faces.component.UIForm.processValidators(UIForm.java:244)
   at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1085)
   at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1085)
   at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1165)
   at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
   at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
   at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:383)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
   at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
   at java.lang.Thread.run(Thread.java:680)

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

19 May 2011, 15:09

Hi guys,

I have the same environment as Daniel. I think this is a bug in PrimeFaces. I have a similar method in my utility class, but a little bit different. There is a lot of example how to get a converter in a proper way. I do it as follows:

Code: Select all

	/**
	 * Returns converter {@link Converter} to the given component. Only components implemented
	 * {@link EditableValueHolder} have a converter.
	 *
	 * @param  context   current faces context
	 * @param  component UIComponent
	 * @return Converter converter {@link Converter} or <code>null</code>
	 */
	public static Converter getConverter(final FacesContext context, final UIComponent component)
	{
		if (!(component instanceof EditableValueHolder)) {
			return null;
		}

		Converter converter = ((EditableValueHolder) component).getConverter();
		if (converter != null) {
			return converter;
		}

		ValueExpression valueExpression = component.getValueExpression("value");
		if (valueExpression == null) {
			return null;
		}

		Class<?> converterType = valueExpression.getType(context.getELContext());
		if (converterType == null
		    || converterType == String.class
		    || converterType == Object.class) {
			// no conversation is needed
			return null;
		}

		return context.getApplication().createConverter(converterType);
	}
and now how PrimeFaces does it in InputTextRenderer

Code: Select all

	@Override
	public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException {
		InputText inputText = (InputText) component;
		String value = (String) submittedValue;
		Converter converter = inputText.getConverter();

		//first ask the converter
		if(converter != null) {
			return converter.getAsObject(context, inputText, value);
		}
		//Try to guess
		else {
            ValueExpression ve = inputText.getValueExpression("value");
            
            if(ve != null) {
                Class<?> valueType = ve.getType(context.getELContext());
                Converter converterForType = context.getApplication().createConverter(valueType);

                if(converterForType != null) {
                    return converterForType.getAsObject(context, inputText, value);
                }
            }
		}

		return value;
	}
You see, context.getApplication().createConverter(valueType) is always called if even no conversion is needed (see my check for converterType). valueType is null in your case. Therefore, a check valueType (null or String.class, Object.class) is quite important.

You can create an issue if it's really an issue. Actually, Cagatay, I would write / move the method getConverter(final FacesContext context, final UIComponent component) to ComponentUtils or whatever PrimeFaces has.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

19 May 2011, 19:08

PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

marco
Posts: 66
Joined: 14 Jun 2010, 17:25

25 May 2011, 09:40

the issue status was set 5 days ago to "wontfix" by cagatay.

Can I ask why? I have the same issue and the code is unchanged even in latest 3.0.M2-SNAPSHOT builds.

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

25 May 2011, 10:25

Hi Marco,

Sometimes issues are set to "Won't fix" without comments. This issue is exactly this case and I was scared to ask Cagatay :-) I guess he thinks this expression ve.getType(context.getELContext()) can never return null or we do something wrong. I don't know.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

25 May 2011, 10:47

I can't replicate it.

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

25 May 2011, 11:00

I can't replicate it.
That's okey. Maybe someone can provide a very small replicable example?
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 41 guests