NullPointerException in UIComponentBase decode using Shale test framework

View: New views
3 Messages — Rating Filter:   Alert me  

NullPointerException in UIComponentBase decode using Shale test framework

by Zhen, Jane :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I simply created a Form and inside an inputTextField and tried to do decoding. But I got a java.lang.NullPointerException

at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:685)

at javax.faces.component.UIInput.decode(UIInput.java:484)

at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:905)

at javax.faces.component.UIInput.processDecodes(UIInput.java:400)

at com.hp.ed.configui.credential.CredentialBeanTest.testLabelUpdate(CredentialBeanTest.java:70)



This has happened before, but I couldn't find an answer for that. I'm just giving it another try, as Shale test framework is really not well documented.



<<Code segment>>

UIViewRoot root=facesContext.getViewRoot();

List<UIComponent> children = root.getChildren();

UIForm credForm = new HtmlForm();

credForm.setId("credForm");

credForm.setParent(root);



UIInput label = new HtmlInputText();

label.setId("label");

label.setParent(credForm);

ValueBinding vb = facesContext.getApplication().createValueBinding("#{credentialBean.passwordAgain}");

label.setValueBinding("value", vb);



facesContext.getExternalContext().getRequestMap().put("credentialBean", vc);

facesContext.getExternalContext().getRequestParameterMap().put("credForm.label","myLabel");

label.processDecodes(facesContext);  //if I don't call label.processDecodes, but root.processDecodes, then I don't get the exception, however, the submittedValue of inputText is null.



thanks for any help



Jane

RE: NullPointerException in UIComponentBase decode using Shale test framework

by kito99 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jane,

Can you give us a full stack trace (not sure which line threw the exception)
and the snippet of code where you initialize the components that you're
testing? I'm guessing that you just didn't initialize the components
properly -- Shale Test leaves that all up to the developer.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Kito D. Mann - Author, JavaServer Faces in Action
http://www.virtua.com - JSF/Java EE consulting, training, and mentoring
http://www.JSFCentral.com - JavaServer Faces FAQ, news, and info
phone: +1 203-653-2989
fax: +1 203-653-2988


> -----Original Message-----
> From: Zhen, Jane [mailto:jane.zhen@...]
> Sent: Tuesday, April 15, 2008 9:22 AM
> To: user@...
> Subject: NullPointerException in UIComponentBase decode using Shale
> test framework
>
> I simply created a Form and inside an inputTextField and tried to do
> decoding. But I got a java.lang.NullPointerException
>
> at
> javax.faces.component.UIComponentBase.decode(UIComponentBase.java:685)
>
> at javax.faces.component.UIInput.decode(UIInput.java:484)
>
> at
> javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.ja
> va:905)
>
> at javax.faces.component.UIInput.processDecodes(UIInput.java:400)
>
> at
> com.hp.ed.configui.credential.CredentialBeanTest.testLabelUpdate(Creden
> tialBeanTest.java:70)
>
>
>
> This has happened before, but I couldn't find an answer for that. I'm
> just giving it another try, as Shale test framework is really not well
> documented.
>
>
>
> <<Code segment>>
>
> UIViewRoot root=facesContext.getViewRoot();
>
> List<UIComponent> children = root.getChildren();
>
> UIForm credForm = new HtmlForm();
>
> credForm.setId("credForm");
>
> credForm.setParent(root);
>
>
>
> UIInput label = new HtmlInputText();
>
> label.setId("label");
>
> label.setParent(credForm);
>
> ValueBinding vb =
> facesContext.getApplication().createValueBinding("#{credentialBean.pass
> wordAgain}");
>
> label.setValueBinding("value", vb);
>
>
>
> facesContext.getExternalContext().getRequestMap().put("credentialBean",
> vc);
>
> facesContext.getExternalContext().getRequestParameterMap().put("credFor
> m.label","myLabel");
>
> label.processDecodes(facesContext);  //if I don't call
> label.processDecodes, but root.processDecodes, then I don't get the
> exception, however, the submittedValue of inputText is null.
>
>
>
> thanks for any help
>
>
>
> Jane


Parent Message unknown RE: NullPointerException in UIComponentBase decode using Shale test framework

by Zhen, Jane :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I figured that problem out, I needed to setRendererType, although just need to be null. Could anyone tell me why a component needs a null renderer?

I have a general question though. I am trying to create a view from a jsp page, normally you would do it in a backing bean in running environment where request and everything are set. All you need to do is to call ViewHandler.createView. But in shale framework, how would i set up everything in order to make it work? Is it even possible?
thanks
Jane