Karthikeyan
Karthikeyan

Reputation: 767

command link is not working inside a page with URL query string

i am having a in a page which is redirected using a an Outputlink with query string, for ex,

   http://localhost:8070/ChennaiVolunteer/faces/gallery.xhtml?usrId=22

In gallery.xhtml, i have a command link

  <p:commandLink value="List of Activities" action="#{listingActivityData.listofactivities}"  ajax="false">
                    </p:commandLink>

And also i have called an function in the getter of the QueryString "usrId"

whenever i click the the commandLink i got a exception as below:

SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/ChennaiVolunteer] threw exception [java.lang.IllegalArgumentException] with root cause
   java.lang.IllegalArgumentException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at javax.el.BeanELResolver.setValue(BeanELResolver.java:135)
at javax.el.CompositeELResolver.setValue(CompositeELResolver.java:83)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.setValue(FacesCompositeELResolver.java:182)
at org.apache.myfaces.config.ManagedBeanBuilder.initializeProperties(ManagedBeanBuilder.java:349)
at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:169)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.createManagedBean(ManagedBeanResolver.java:303)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:266)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:65)
at org.apache.myfaces.el.convert.VariableResolverToELResolver.getValue(VariableResolverToELResolver.java:96)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:71)
at org.apache.el.parser.AstValue.getValue(AstValue.java:147)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at org.apache.myfaces.view.facelets.el.TagValueExpression.getValue(TagValueExpression.java:85)
at javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:243)
at javax.faces.component.UIData.getValue(UIData.java:1153)
at javax.faces.component.UIData.createDataModel(UIData.java:1101)
at javax.faces.component.UIData.getDataModel(UIData.java:1078)
at javax.faces.component.UIData.setRowIndex(UIData.java:514)
at javax.faces.component.UIData.visitTree(UIData.java:1342)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:770)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:991)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:770)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:991)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:770)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:991)
at org.apache.myfaces.lifecycle.DefaultRestoreViewSupport.processComponentBinding(DefaultRestoreViewSupport.java:84)
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:142)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:304)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

then the page redirected to the same Outputlink without query String http://localhost:8070/ChennaiVolunteer/faces/gallery.xhtml

Upvotes: 0

Views: 690

Answers (1)

BalusC
BalusC

Reputation: 1108672

I'm not sure why exactly you got this exception and it's not helpful to not show a SSCCE, but based on the stacktrace you're using MyFaces and you have this link inside a <h:dataTable> and the exception occurred while creating the managed bean associated with table's value. The bean seems to be request scoped and setting a managed property has failed.

There should be another root cause further down in the stacktrace which tells you in detail what exactly failed suring setting a managed bean property.

Depending on the exact functional requirement and how you've designed the page so far, I can think of 2 solutions:

  1. Put the bean in the view scope instead of the request scope. This way the bean won't be garbaged and recreated everytime you interact with the same view. It will just live as long as you interact with the same view.

    @ManagedBean
    @ViewScoped
    public class ListingActivityData {
        // ...
    }
    
  2. Pass the request parameter to the subsequent request by <f:param>.

    <p:commandLink ...>
        <f:param name="usrId" value="#{param.usrId}" />
    </p:commandLink>
    

Upvotes: 2

Related Questions