I was wondering if and how it is possible to display an <o:graphicImage> as thumbnail inside a <p:lightbox>. To be more precise, I wanted to achieve something like this:
<p:dataTable id="articles" var="article"
value="#{articleMB.articles}" selectionMode="single"
rowKey="#{articles.id}"
selection="#{articleMB.selectedArticle}">
<p:column>
<p:lightBox styleClass="imagebox" id="lighbox">
<h:outputLink value="#{imageBean.getFirstImage(article, true)}">
<o:graphicImage value="#{imageBean.getFirstImage(article, true)}" dataURI="true" height="80" />
</h:outputLink>
</p:lightBox>
</p:column>
</p:dataTable>
Which isn't working obviously, since there's no proper URL passed to the lightbox.
imageBean.getFirstImage(Article article, boolean thumbnail) returns a byte[] of the image, since the images I want to access are stored on an external source.
Edit: So I've done as BalusC mentioned and it seems to be the proper approach. But now I'm getting the following exception:
Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException#2eae887c
at sun.reflect.GeneratedMethodAccessor307.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.omnifaces.resourcehandler.GraphicResource.getInputStream(GraphicResource.java:259)
at com.sun.faces.application.resource.ResourceHandlerImpl.handleResourceRequest(ResourceHandlerImpl.java:335)
at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:153)
at org.primefaces.application.resource.PrimeResourceHandler.handleResourceRequest(PrimeResourceHandler.java:87)
at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:153)
at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:153)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:655)
... 32 more
This is the method that actually returns the image. It is working fine in every other context:
public byte[] getFirstImage(final Article article, boolean thumbnail)
{
try
{
File dir = new File(getImageFolder(article.getImageFolder(), thumbnail));
File[] files = dir.listFiles(new FilenameFilter()
{
#Override
public boolean accept(File dir, String name)
{
return name.startsWith(String.valueOf(article.getArticleId()));
}
});
Arrays.sort(files);
return Files.readAllBytes(files[0].toPath());
}
catch (Exception e)
{
return new byte[1];
}
}
Edit 2: As mentioned in the comments, I'm facing another weird behaviour. It runs perfectly fine on my local machine but on the server it throws following exception:
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.omnifaces.resourcehandler.GraphicResource.getInputStream(GraphicResource.java:259)
at com.sun.faces.application.resource.ResourceHandlerImpl.handleResourceRequest(ResourceHandlerImpl.java:335)
at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:153)
at org.primefaces.application.resource.PrimeResourceHandler.handleResourceRequest(PrimeResourceHandler.java:87)
at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:153)
at javax.faces.application.ResourceHandlerWrapper.handleResourceRequest(ResourceHandlerWrapper.java:153)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:655)
... 32 more
For exactly this reason, OmniFaces 2.5 introduced the #{of:graphicImageURL()} EL function. This works only if your ImageBean is annotated with #GraphicImageBean.
import org.omnifaces.cdi.GraphicImageBean;
#GraphicImageBean
public class ImageBean {
// ...
}
<h:outputLink value="#{of:graphicImageURL('imageBean.getFirstImage(article, false)')}">
<o:graphicImage value="#{imageBean.getFirstImage(article, true)}" dataURI="true" height="80" />
</h:outputLink>
See also the #GraphicImageBean showcase.
Update: to be clear, you need a converter for non-standard types such as Article. Why such a converter is needed and how to create it is detailed in Conversion Error setting value for 'null Converter'. If you create a #FacesConverter(forClass=Article.class), then the OmniFaces GraphicImage will automatically pickup it.
In your particular case it's however more efficient to just pass the identifier to the image streamer method right away, this saves an additional conversion step. Provided that your Article object has an id property, here's how:
<h:outputLink value="#{of:graphicImageURL('imageBean.getFirstImage(article.id, false)')}">
<o:graphicImage value="#{imageBean.getFirstImage(article.id, true)}" dataURI="true" height="80" />
</h:outputLink>
public byte[] getFirstImage(Long articleId, boolean thumbnail) {
// ...
}
Namely, JSF already has builtin converters for standard types such as Long and boolean.
Related
I'm getting this error with f:setPropertyActionListener and i can't figure out why:
HTTP Status 500 - For input string: "selectedItem"
exception:
javax.servlet.ServletException: For input string: "selectedItem"
javax.faces.webapp.FacesServlet.service(FacesServlet.java:667)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause:
java.lang.NumberFormatException: For input string: "selectedItem"
java.lang.NumberFormatException.forInputString(Unknown Source)
java.lang.Integer.parseInt(Unknown Source)
java.lang.Integer.parseInt(Unknown Source)
javax.el.ListELResolver.coerce(ListELResolver.java:157)
javax.el.ListELResolver.getType(ListELResolver.java:50)
com.sun.faces.el.DemuxCompositeELResolver._getType(DemuxCompositeELResolver.java:215)
com.sun.faces.el.DemuxCompositeELResolver.getType(DemuxCompositeELResolver.java:242)
org.apache.el.parser.AstValue.getType(AstValue.java:60)
org.apache.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:168)
com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
com.sun.faces.facelets.tag.jsf.core.SetPropertyActionListenerHandler$SetPropertyListener.processAction(SetPropertyActionListenerHandler.java:209)
javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
javax.faces.component.UICommand.broadcast(UICommand.java:300)
javax.faces.component.UIData.broadcast(UIData.java:1108)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:654)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Table Class:
// imports omitted
public class Table<E> extends ArrayList<E> {
private E selectedItem;
public E getSelectedItem() { return selectedItem; }
public void setSelectedItem(E value) { selectedItem = value; }
}
MyTable Bean:
// Imports omitted
#ManagedBean
#ViewScoped
public class MyTable extends Table<File> {
#PostConstruct
public void initBean() {
// Loading some files into the list
}
}
This is the XHTML:
<html> <!-- Namespaces and stuff omitted -->
<h:head>...</h:head>
<h:body>
<h:form>
<h:dataTable var="item" value="#{myTable}">
<h:column>
<h:commandButton value="Try Me!">
<f:setPropertyActionListener value="#{item}" target="#{myTable.selectedItem}"/>
<!-- I'm getting a warning from eclipse here: property not found -->
</h:commandButton>
</h:column>
</h:dataTable>
</h:form>
</h:body>
</html>
I'm using Eclipse Luna (Java EE IDE) with Tomcat 8 and JSF 2.2.11 (mojarra). Any hints are accepted, thank you!
You kind of coded your self into a corner with your fancy bean implementation. Take a look at the processing steps for the f:setActionPropertyListener. Your code is choking at step 3:
If the value of the "value" expression is not null, call getType() on the "value" and "target" ValueExpressions to determine their property types
for the following reasons:
The EL processor has determined that myTable is a List. Because of this, it has delegated the evaluation of the expression myTable.selectedItem to the javax.el.ListELResolver class
The ELResolver, on encountering the myTable base object, determines it's a List and automatically assumes that the following string is referring to a list index, i.e. myTable.selectedItem, where selectedItem is supposed to be a list index (per the EL specification, the [] and . are interchangeable for lists). You can see it in action here. While it may not be immediately apparent in the tomcat source, if you check the comment in a similar implementation in Jboss for example, you have the following comment:
If the base object is a list, returns the value at the given index. The index is specified by the property argument, and coerced into an integer
"property argument" here is referring to the selectedItem portion of your expression
The EL processor now attempts to convert the string selectedItem to an integer (to be used as a list index) which in turn explodes in a 500
You'll make your work a whole lot easier by not combining your data structure and your backing bean, like Rami. Q suggested. Much cleaner that way IMO
my Answer should be a comment, but its too long for that, so i write it as an answer.
i see some "ERRORS" in your code:
ALL JSF Beans & objects have to be Serializable
if you use Generic Types, they should be Serializable TOO:
public class GenericObject<T extends Serializable> implements Serializable {...}
Setter & Getter of a JSF Object should be like (this.attr = ...;):
public void setSelectedItem(E value) { this.selectedItem = value;}
be sure that you import the managedBean correctly:
import javax.faces.bean.ManagedBean;
instead of <h:dataTable var="item" value="#{myTable}"> you should use <h:dataTable var="item" value="#{myTable.items}">
and declare items as List Attribute of your bean with getter and setter
I am using
Primefaces 5.0,
JSF 2.0,
Weblogic 10.3(11g),
J2ee 5.
When i use p:graphicImage to render streamed content from my bean,i notice an ajaxresponse exception in the logs and finally and el exception which is below. Is adding el2.0 an option to solve this, if yes then i am not sure if i can add el2.0 only to my project, as i dont want to add it to the domain files of Weblogic. Please help.
java.lang.NoClassDefFoundError: javax/el/ValueReference
at org.primefaces.el.InterceptingResolver.setValue(InterceptingResolver.java:28)
at com.sun.el.parser.AstValue.setValue(Unknown Source)
at com.sun.el.ValueExpressionImpl.setValue(Unknown Source)
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
at org.primefaces.el.ValueExpressionAnalyzer.getExpression(ValueExpressionAnalyzer.java:49)
at org.primefaces.util.DynamicResourceBuilder.build(DynamicResourceBuilder.java:49)
at org.primefaces.component.graphicimage.GraphicImageRenderer.getImageSrc(GraphicImageRenderer.java:74)
at org.primefaces.component.graphicimage.GraphicImageRenderer.encodeEnd(GraphicImageRenderer.java:40)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:884)
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:85)
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:68)
at org.primefaces.component.overlaypanel.OverlayPanelRenderer.encodeMarkup(OverlayPanelRenderer.java:59)
at org.primefaces.component.overlaypanel.OverlayPanelRenderer.encodeEnd(OverlayPanelRenderer.java:37)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:884)
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:85)
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:68)
Below is my code
<p:graphicImage value="#{lev.viewFile}" width="300" cache="false">
<f:param name="id" value="#{lev.levId}" />
</p:graphicImage>
Below is my bean code which is viewscoped...
public StreamedContent getViewFile() {
try{
File viewfileobj = new File("C:/LEAVEMODULEFOLDER/p1.jpeg");
log.debug("viewfileobj.length() = "+viewfileobj.length());
InputStream stream = new FileInputStream(viewfileobj);
log.debug("stream = "+stream);
this.viewFile = new DefaultStreamedContent(stream,"image/jpeg",Utility.getRandomString());
}catch(Exception e){
log.error("Error in Leave.toString() ::"+e);
log.error(Utility.getStackTrace(e));
}
return viewFile;
}
Changing view scope to session scope should work.
In my JSF 2.1 facelets environment, I would like to set a bean property of int type:
facelets template:
<c:set target="#{mybean}" property="size" value="3"/>
java setter:
public void setSize(int size){
this.size = size;
}
But it throws an exception:
javax.el.ELException: Can't set property 'size' on class 'MyBean' to value '3'.
at javax.el.BeanELResolver.setValue(BeanELResolver.java:398)
...
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
Looking into the code of BeanELResolver, I have noticed that the value "3" is unfortunately simply passed to the setter method without any coercion, which obviously does not work. It is a pity that BeanELResolver does not make use of the type knowledge it has there.
Is there a way to coerce the value to an int somehow? I already tried value="#{3}" but this yields a Long. Next thing that comes to my mind is value="#{f:toInt(3)}" using a custom function.
I tried to reproduce the problem you're having. I created a simple RequestScoped bean with a single property.
public class IndexBean {
private int value;
public void setValue(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
Then When I used a defered expression (the one that starts with a #) within the target attribute...
<c:set target="#{indexBean}" property="value" value="5"/>
<h:outputText value="#{indexBean.value}"/>
...I received a JSP exception, saying
Its illegal to specify deferred expression for dynamic attribute.
...which lead me to change the expression to be immediate evaluated.
<c:set target="${indexBean}" property="value" value="5"/>
<h:outputText value="#{indexBean.value}"/>
...and the value was correctly shown on the screen.
How about using fmt:formatNumber?
<fmt:formatNumber var="i" type="number" value="3" />
<c:set target="#{mybean}" property="size" value="${i}"/>
I have a problem with passing method parameters to nested composite component.
I have a first component wose composite:interface looks like :
<composite:interface>
<composite:attribute name="onRowEditListener" required="false" method-signature="void listener(org.primefaces.event.RowEditEvent)"/>
</composite:interface>
It uses another composite component component which has a similar interface.
The first level component is used this way :
<mynamespace:compo1 onRowEditListener=#{bean.method}"/>
The nested one is used this way :
<mynamespace:compo2 onRowEditListener=#{cc.attrs.onRowEditListener}"/>
If I insert in both controls, I got :
in the first level control, an output like org.apache.el.MethodExpressionImpl#358f0647, which looks good to me
in the second (nested) level control, an output like org.apache.myfaces.view.facelets.el.LocationValueExpression#ff381f45 .
Raised exception looks like :
19/07/2012 19:39:02 fr.senat.faces.exceptions.DetailedExceptionHandler INFO [DetailedExceptionHandler.java:40] [http-8080-7] - Stack trace: javax.faces.FacesException: Exception while calling broadcast on component : {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /editSenateur.xhtml][Class: javax.faces.component.html.HtmlBody,Id: j_id_5][Class: org.primefaces.component.layout.Layout,Id: j_id_6][Class: org.primefaces.component.layout.LayoutUnit,Id: j_id_v][Class: org.primefaces.component.outputpanel.OutputPanel,Id: detailCommissions][Class: javax.faces.component.html.HtmlForm,Id: j_id_x][Class: org.primefaces.component.tabview.TabView,Id: tabFonctionsInternes][Class: org.primefaces.component.tabview.Tab,Id: fonctionsCommissions][Class: javax.faces.component.UINamingContainer,Id: j_id_10][Class: javax.faces.component.UIPanel,Id: j_idj_id_10__f_cc_facet][Class: org.primefaces.component.outputpanel.OutputPanel,Id: panelTabViewCommissions][Class: org.primefaces.component.tabview.TabView,Id: tabViewCommissions][Class: org.primefaces.component.tabview.Tab,Id: commissionTab][Class: org.primefaces.component.panelgrid.PanelGrid,Id: j_id_15][Class: org.primefaces.component.row.Row,Id: j_id_1b][Class: org.primefaces.component.column.Column,Id: j_id_1c][Class: javax.faces.component.UINamingContainer,Id: j_id_1d][Class: javax.faces.component.UIPanel,Id: j_idj_id_1d__f_cc_facet][Class: org.primefaces.component.datatable.DataTable,Id: sheetFonctions]} created from: /resources/sen/fonctionsCommission.xhtml at line 27 and column 162
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:430)
at javax.faces.component.UIData.broadcast(UIData.java:1610)
at javax.faces.component.UIData.broadcast(UIData.java:1596)
at javax.faces.component.UIData.broadcast(UIData.java:1596)
at javax.faces.component.UIData.broadcast(UIData.java:1596)
at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:1023)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:286)
at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1360)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:38)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at org.apache.myfaces.extensions.cdi.jsf2.impl.listener.phase.CodiLifecycleWrapper.execute(CodiLifecycleWrapper.java:95)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at fr.senat.faces.filters.HibernateSessionConversationFilter.doFilter(HibernateSessionConversationFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.apache.myfaces.view.facelets.el.ContextAwareELException: javax.el.ELException: java.lang.IllegalArgumentException: wrong number of arguments
at org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:108)
at org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxBehaviorListenerImpl.java:42)
at org.primefaces.event.RowEditEvent.processListener(RowEditEvent.java:41)
at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:74)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:406)
... 31 more
Caused by: javax.el.ELException: java.lang.IllegalArgumentException: wrong number of arguments
at org.apache.el.parser.AstValue.invoke(AstValue.java:195)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at org.apache.myfaces.view.facelets.el.ValueExpressionMethodExpression.invoke(ValueExpressionMethodExpression.java:68)
at org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:96)
... 35 more
Caused by: java.lang.IllegalArgumentException: wrong number of arguments
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.el.parser.AstValue.invoke(AstValue.java:191)
... 38 more
It looks like the method is properly passed to the first control, but that the EL expression gets a bullet when passed to the second...
I am using :
MyFaces 2.1.7
Tomcat 6.0.33
Thanks in advance for your help.
UPDATE
The only "progress" I can assess is a kludge...
The kludge class :
/**
*
* #author lpenet
*
* This class is a workaround kluge. Methods passed as a parameter to a
* composite component then to a PrimeFaces p:ajax seems to get a bullet
* somewhere in the process, at least with Tomcat 6 + MyFaces
* 2.1 + CODI 1.0.5 + OpenWebbeans 1.0.3 See :
* http://forum.primefaces.org/viewtopic.php?f=3&t=23558&p=72885#p72885
*
* Using this class as "componentType", one can forward the methode call.
*
* Not so nice, but... works.
*
*/
#FacesComponent(value = "fr.senat.beans.PrimefacesListenerKludge")
public class PrimefacesListenerKludge extends UINamingContainer {
#Override
public String getFamily() {
return "javax.faces.NamingContainer"; // Important! Required for
// composite components.
}
public void forwardRowEditListener(RowEditEvent event) {
FacesContext context = FacesContext.getCurrentInstance();
Object listener = getAttributes().get("onRowEditListener");
if (listener == null) {
return;
}
MethodExpression ajaxEventListener = (MethodExpression) listener;
ajaxEventListener
.invoke(context.getELContext(), new Object[] { event });
}
}
Sample use :
<composite:interface componentType="fr.senat.beans.PrimefacesListenerKludge">
...
<composite:attribute name="onRowEditListener" required="false"
method-signature="void listener(org.primefaces.event.RowEditEvent)"
default="#{cc.parent.attrs.onRowEditListener}" />
</composite:interface>
<composite:implementation>
...
</composite:implementation>
To be honest, I do not know if it is still required with my current stack (PrimeFaces 4/MyFaces 2.1.13/OWB 1.2.1/Tomcat 7.0.32) but lacks the time to test.
This is a Seam application.
HTML
<h:selectManyCheckbox value="#{officeCriteria.carrier}">
<f:selectItem itemValue="ATT" itemLabel="ATT" />
<f:selectItem itemValue="VZB" itemLabel="VZB" />
</h:selectManyCheckbox>
backing bean OfficeCriteria:
private List<String> carrier;
public List<String> getCarrier() {
return carrier;
}
public void setCarrier(List<String> carrier) {
this.carrier = carrier;
}
When I load the page I get a null pointer exception on carrier. What am I doing wrong?
2:10,963 ERROR [viewhandler] Error Rendering View[/ONDSearchPage.xhtml]
javax.faces.FacesException: javax.el.ELException: /ONDSearchPage.xhtml #264,81 value="#{officeCriteria.carrier}": Error reading 'carrier' on type dne.nmt.ond.model.OfficeCriteria_$$_javassist_seam_6
at javax.faces.component.UIOutput.getValue(UIOutput.java:187)
at com.sun.faces.renderkit.html_basic.MenuRenderer.getCurrentSelectedValues(MenuRenderer.java:593)
at com.sun.faces.renderkit.html_basic.SelectManyCheckboxListRenderer.encodeEnd(SelectManyCheckboxListRenderer.java:117)
....
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.el.ELException: /ONDSearchPage.xhtml #264,81 value="#{officeCriteria.carrier}": Error reading 'carrier' on type dne.nmt.ond.model.OfficeCriteria_$$_javassist_seam_6
at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76)
at javax.faces.component.UIOutput.getValue(UIOutput.java:184)
... 95 more
Caused by: java.lang.NullPointerException
at dne.nmt.ond.model.OfficeCriteria.getCarrier(OfficeCriteria.java:108)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
.....
at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53)
at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
... 96 mor
What is in OfficeCriteria.java line 108? Something you are referencing there is null, and I guess you aren't expecting it to be.
What I suggest is that you set an empty list (and not null) for the property carrier:
private List<String> carrier = new ArrayList<String>();
public List<String> getCarrier() {
return carrier;
}
public void setCarrier(List<String> carrier) {
this.carrier = carrier;
}
The answer is that my original code works as it is.
The difficulty (and what I left out) was a debugging statement that referenced an element in the list. Thanks to the person who suggested I actually look at line 108. :-)
And BTW to the person who suggested initializing this with a new List, I had tried that already and got some error (I can't remember what).
Thanks for the help.