jsf 2 - Why hidden input causes ClassCastException -



jsf 2 - Why hidden input causes ClassCastException -

consider example.

web page:

<h:form> <h:outputlabel value="enter text:"/> <h:inputtext value="#{testcontroller.vo.teststring}" /> <h:inputhidden id="test" value="#{testcontroller.vo.id}" /> <h:commandbutton value="click me" action="#{testcontroller.submitform}"/> </h:form>

controller:

@named @sessionscoped public class testcontroller implements serializable { private static final long serialversionuid = 1l; private valueobject vo = new valueobject(); public string submitform() { homecoming null; } public valueobject getvo() { homecoming vo; } public void setvo(valueobject vo) { this.vo = vo; } }

valueobject:

public class valueobject { private long id; private string teststring; public string getteststring() { homecoming teststring; } public void setteststring(string teststring) { this.teststring = teststring; } public long getid() { homecoming id; } public void setid(long id) { this.id = id; } }

as see, valueobject class has setid/getid methods. far, fine.

now, want introduce interface:

public interface identifiable<t> { t getid(); void setid(t id); }

and have valueobject implement it:

public class valueobject implements identifiable<long> { // remainder omitted }

nothing changed in valueobject class, rather implements identifiable. when seek submit form again, next stack-trace:

caused by: javax.el.elexception: /index.xhtml @16,61 value="#{testcontroller.vo.id}": java.lang.classcastexception: java.lang.string cannot cast java.lang.long @ com.sun.faces.facelets.el.tagvalueexpression.setvalue(tagvalueexpression.java:139) @ javax.faces.component.uiinput.updatemodel(uiinput.java:818) ... 34 more caused by: java.lang.classcastexception: java.lang.string cannot cast java.lang.long @ com.test.vo.valueobject.setid(valueobject.java:1)

as see, during update model values phase classcastexception thrown when trying phone call setid method. happens hidden inputs. if seek modify xhtml adding converter, works fine:

<h:inputhidden id="test" value="#{testcontroller.vo.id}" converter="javax.faces.long"/>

so, why input behavior alter when create valueobject implement interface generic parameter? glassfish bug?

edit: turned out, doesn't depend on whether input hidden or not. glassfish version on issue reproducible 3.1-b43.

jsf-2 glassfish-3 classcastexception

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -