0

I have a JSF hidden input on my app view that holds some object's attribute:

<h:inputHidden id="hidMyData" value="#{bean.myList.get(bean.listIndex).someAttr}" immediate="true"/>

Index that determines the right object, is also saved in session bean and is an integer:

public void setListIndex(int listIndex) {
    this.listIndex = listIndex;
}

public int getListIndex() {
    return listIndex;
}

If I run my app on Websphere Application Server 8.5.5, I'm getting a conversion error:

PrimeExceptio E   /pages/MyView.xhtml at line 566 and column 50 value="#{bean.myList.get(bean.listIndex).someAttr}": Cannot convert get of type class java.lang.String to class java.lang.Integer

At the same time if I run it as a portlet on IBM Portal 7, there's no error. In both cases I use MyFaces implementation version 2.0.17 and Primefaces 6.2.27.

What could cause this error?

EDIT1: Just realized that using square brackets instead of get method works fine:

<h:inputHidden id="hidMyData" value="#{bean.myList[bean.listIndex].someAttr}" immediate="true"/>

Anyway if someone has an explanation why this method works and the first one doesn't, I'll appreciate it.

peterremec
  • 488
  • 1
  • 15
  • 46
  • What is the value of `#{bean.myList.get(bean.listIndex).someAttr}`? – Jasper de Vries Jun 24 '22 at 10:50
  • @JasperdeVries It's a string, value depends on `listIndex`. – peterremec Jun 24 '22 at 11:15
  • Yes, I know it's a string, but what is the value of the item that is failing? – Jasper de Vries Jun 27 '22 at 09:55
  • @JasperdeVries I've tried with 0, an int, not a String. I don't understand why the conversion is even made. Bean attribute is an integer, not a String. What am I missing? – peterremec Jun 27 '22 at 11:22
  • Basically all bound values are transferred as string (that's just how HTTP works). JSF will convert the string to the correct type. See also https://stackoverflow.com/questions/4734580/conversion-error-setting-value-for-null-converter-why-do-i-need-a-converter – Jasper de Vries Jun 27 '22 at 11:53
  • @JasperdeVries that makes sense, I agree. But I still don't understand why does it work on IBM Portal 7, but not on IBM WAS 8.5.5. Same code, different result. The only thing I see is that I use resolvers `com.ibm.faces20.portlet.PortletELResolverorg.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver` on Portal, should I also include some in web application? I've never done that so far and I've never had any similar problems. – peterremec Jun 28 '22 at 10:29

0 Answers0