Consider the following Primefaces 5.3 JSF code fragment:
<p:column sortBy="#{benutzer.emailAdresse}" headerText="#{res.com_lbl_column_header_email}"
filterBy="#{benutzer.emailAdresse}" filterStyle="margin-top:5px;" filterPosition="bottom" filterOptions="contains">
<f:facet name="filter">
<p:autoComplete id="dynaEmail" dropdown="true" inputStyleClass="inputFilterM" queryDelay="300"
value="#{benutzerListBean.dyna_search_email}" completeMethod="#{benutzerListBean.completeTextEmail}"
style="margin-left:10px;" cache="false" onchange="PF('tblBenutzer').filter()">
<p:ajax event="keyup" update="dynaVorname, dynaNachname" listener="#{benutzerListBean.dynaSearchStringValueChanged}" />
<p:ajax event="itemSelect" update="dynaVorname, dynaNachname"
listener="#{benutzerListBean.dynaSearchStringValueChanged}" />
</p:autoComplete>
<p:commandButton icon="ui-icon-trash" style="margin-left:35px;">
<f:param name="sender" value="dyna_search_email" />
<p:ajax event="click" update="tblBenutzer, dynaEmail" listener="#{benutzerListBean.resetCurrentFilter}" />
</p:commandButton>
</f:facet>
<h:outputText value="#{benutzer.emailAdresse}" />
</p:column>
So autocomplete in filter.The autocomplete dropdown menu works perfectly, but as I type something in I have a strange exception:
2015-12-21 19:08:30,739 INFO [javax.enterprise.resource.webcontainer.jsf.context] (http-/0.0.0.0:8443-5) java.lang.ClassCastException: javax.faces.component.UIPanel cannot be cast to javax.faces.component.ValueHolder: java.lang.ClassCastException: javax.faces.component.UIPanel cannot be cast to javax.faces.component.ValueHolder
at org.primefaces.component.datatable.feature.FilterFeature.populateFilterMetaDataWithoutColumnGroups(FilterFeature.java:346) [primefaces-5.3.jar:5.3]
at org.primefaces.component.datatable.feature.FilterFeature.populateFilterMetaData(FilterFeature.java:259) [primefaces-5.3.jar:5.3]
at org.primefaces.component.datatable.feature.FilterFeature.decode(FilterFeature.java:90) [primefaces-5.3.jar:5.3]
at org.primefaces.component.datatable.DataTable.processValidators(DataTable.java:716) [primefaces-5.3.jar:5.3]
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:575) [jsf-impl-2.2.12.jar:2.2.12]
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) [jsf-impl-2.2.12.jar:2.2.12]
at org.primefaces.component.api.UIData.visitTree(UIData.java:822) [primefaces-5.3.jar:5.3]
I've tried to move the code to "header" facet, and it worked.. but this way the sorting works weard.
How can I fix the exception?
Related
I have this JSF snippet which works fine. When the commandbutton is clicked it should reload the page by redirecting to itself.
<p:dataTable value="#{fileModel.files}"
var="file" scrollable="true" scrollHeight="400">
<p:column headerText="#{msgs.lbl_file}">
#{file.name}
</p:column>
<p:column width="150">
<p:commandButton value="#{msgs.lbl_import}"
actionListener="#{fileModel.importFile(file, module)}"
**action="mypage.jsf?faces-redirect=true"**/>
</p:column>
<p:column width="150">
<p:commandLink value="#{msgs.lbl_view}" target="_blank" ajax="false"
actionListener="#{fileModel.view(file)}"/>
</p:column>
</p:dataTable>
Because I want to reuse this in multiple pages I tried to make this JSF template and include it via ui:include. Only thing is that I need the action to be configurable depending on the page it is used in.
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<p:dataTable value="#{fileModel.files}"
var="file" scrollable="true" scrollHeight="400">
<p:column headerText="#{msgs.lbl_file}">
#{file.name}
</p:column>
<p:column width="150">
<p:commandButton value="#{msgs.lbl_import}"
actionListener="#{fileModel.importFile(file, module)}"
**action="#{redirectTo}"**/>
</p:column>
<p:column width="150">
<p:commandLink value="#{msgs.lbl_view}" target="_blank" ajax="false"
actionListener="#{fileModel.view(file)}"/>
</p:column>
</p:dataTable>
</ui:composition>
With the inclusion
<ui:include src="moduleSettingImportDialog.xhtml">
<ui:parameter name="redirectTo" value="mypage.jsf?faces-redirect=true"/>
</ui:include>
The error I get is something like
javax.el.ELException: Not a Valid Method Expression: #{redirectTo}
at
com.sun.el.lang.ExpressionBuilder.createMethodExpression(ExpressionBuilder.java:311)
at
com.sun.el.ExpressionFactoryImpl.createMethodExpression(ExpressionFactoryImpl.java:96)
at
org.jboss.weld.util.el.ForwardingExpressionFactory.createMethodExpression(ForwardingExpressionFactory.java:43)
at
org.jboss.weld.el.WeldExpressionFactory.createMethodExpression(WeldExpressionFactory.java:53)
at
com.sun.faces.facelets.tag.TagAttributeImpl.getMethodExpression(TagAttributeImpl.java:240)
at
com.sun.faces.facelets.tag.jsf.ActionSourceRule$ActionMapper2.applyMetadata(ActionSourceRule.java:107)
at
com.sun.faces.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:81)
A similar error I get when using JSF composite components.
<c:interface>
<c:attribute name="module"/>
<c:attribute name="redirectTo" type="java.lang.String"/>
</c:interface>
<c:implementation rendered="#{systemSettingModel.LOG_REASON_FOR_CHANGES_ISAKTIV}">
<p:dataTable value="#{fileModel.files}"
var="file" scrollable="true" scrollHeight="400">
<p:column headerText="#{msgs.lbl_file}">
#{file.name}
</p:column>
<p:column width="150">
<p:commandButton value="#{msgs.lbl_import}"
actionListener="#{fileModel.importFile(file, cc.attrs.module)}"
**action="#{cc.attrs.redirectTo}"**/>
</p:column>
<p:column width="150">
<p:commandLink value="#{msgs.lbl_view}" target="_blank" ajax="false"
actionListener="#{fileModel.view(file)}"/>
</p:column>
</p:dataTable>
</c:implementation>
#{cc.attrs.redirectTo}: javax.el.ELException:
java.lang.IllegalArgumentException: Cannot convert
multimodulesettings.jsf?faces-redirect=true&includeViewParams=true of
type class java.lang.String to class javax.el.MethodExpression
javax.faces.FacesException: #{cc.attrs.redirectTo}:
javax.el.ELException: java.lang.IllegalArgumentException: Cannot
convert
multimodulesettings.jsf?faces-redirect=true&includeViewParams=true of
type class java.lang.String to class javax.el.MethodExpression at
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315) at
javax.faces.component.UIData.broadcast(UIData.java:1108) at
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) at
org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at
org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:78)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at
org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:295)
How to pass a fixed string to a JSF template or composite component that is used in the action attribute of a commandButton?
As a workaround I implemented a JSF bean method that just returns the passed in string like so.
public String echo(String s) {
return s;
}
Then instead of passing the fix string as a parameter to the component it is being passed by an EL expression.
<ui:include src="moduleSettingImportDialog.xhtml">
<ui:parameter name="redirectTo" value="#{jsfBean.echo('mypage.jsf?faces-redirect=true')}"/>
</ui:include>
I need to make a selectManyMenu with spinner or input text inside, to be able to get the following result:
Here after my code:
<p:selectManyMenu id="opt-list" value="#{myBean.selectedOptionList}"
converter="optConverter" filter="true"
filterMatchMode="contains" showCheckbox="true"
var="selectedOpt">
<f:selectItems value="#{myBean.optionList}" var="opt" itemLabel="#{opt.name}" itemValue="#{opt}" />
<p:column>
<h:outputText value="#{selectedOpt.name}" />
</p:column>
<p:column>
<p:spinner value="#{selectedOpt.nb}" size="1" />
</p:column>
</p:selectManyMenu>
The idea is that the user should be able to select an option and specify a number.
but during execution, i get the following warning/error:
WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] .....\.....\my-page.xhtml #65,84 value="#{selectedOpt.nb}": JBWEB006016: Target Unreachable, identifier ''selectedOpt'' resolved to null: javax.el.PropertyNotFoundException: ....\......\my-page.xhtml #65,84 value="#{selectedOpt.nb}": JBWEB006016: Target Unreachable, identifier ''selectedOpt'' resolved to null
You can solve your "label" problems by replacing <f:selectItem>'s itemValue by #{selectedOpt} instead of #{opt}
<p:selectManyMenu id="opt-list" value="#{myBean.selectedOptionList}"
converter="optConverter" filter="true"
filterMatchMode="contains" showCheckbox="true"
var="selectedOpt">
<f:selectItems value="#{myBean.optionList}" var="opt" itemLabel="#{opt.name}" itemValue="#{selectedOpt}" />
<p:column>
<h:outputText value="#{selectedOpt.name}" />
</p:column>
<p:column>
<p:spinner value="#{selectedOpt.nb}" size="1" />
</p:column>
Keep in mind that will not solve your spinner problem. See : http://forum.primefaces.org/viewtopic.php?f=3&t=16964
If i select a row in my Datatable i always following : Feb 24, 2014 1:01:42 AM com.sun.faces.context.PartialViewContextImpl processPartial
Information: java.lang.IllegalArgumentException: argument type mismatch . The Problem is ajax tag. If i remove it i get no exception
i use primefaces 4.0 and jsf 2.1
<p:dataTable id="inboxTable" var="task_toUser" value="#{taskboxBean.taskboxInboxList}" paginator="true"
widgetVar="inboxTable" rows="5" selection="#{taskboxBean.selectedTaskbox}"
selectionMode="single" rowKey="#{task_toUser.ID}" emptyMessage="" paginatorPosition="bottom"
>
<p:ajax event="rowSelect" update=":contentForm, :postForm:tabViewPosts:trashTable, :postForm:tabViewPosts:inboxTable, :postForm:tabViewPosts:sentTable "
listener="#{taskboxBean.onTaskboxRowSelect}" />
<p:column headerText="Post" filterBy="FROM_USER.FIRST_NAME" filterMatchMode="contains">
<h:outputText
value="#{task_toUser.TASKBOX.FROM_USER.FIRST_NAME} #{task_toUser.TASKBOX.FROM_USER.LAST_NAME} (#{task_toUser.TASKBOX.FROM_USER.EMAIL})" />
<p:commandButton disabled="true" style="float:right" icon="ui-icon-mail-closed" rendered="#{!task_toUser.IS_SEEN}"/>
<p:commandButton disabled="true" style="float:right" icon="ui-icon-mail-open" rendered="#{task_toUser.IS_SEEN}"/>
<br/>
<h:outputText value="#{task_toUser.TASKBOX.TASKTYPE.NAME} " />
<h:outputText style="font-weight: bold; " value="#{task_toUser.TASKBOX.TASKBOX_SUPPLIER.NEW_SUPPLIER.NAME}"/>
<br />
<h:outputText value="#{task_toUser.TASKBOX.CREATE_TIMESTAMP}" />
</p:column>
</p:dataTable>
i solved the problem. The problem is that the ArrayList is from another Type than the Selection and xhtml casted it automatically.
I'm using JSF 2.1, Richfaces 4.2.2 and for below mentioned code I'm getting java.io.NotSerializableException: org.richfaces.component.SavedState exception.
Bean Scope: Session
Facelet code:
<rich:dataTable id="table" value="#{mapActivityGroup.addActivityGroupModelList}"
var="model">
<rich:column>
<h:selectBooleanCheckbox id="checkBox" value="#{model.selected}" />
</rich:column>
<rich:column filterValue="#{mapActivityGroup.categoryFilter}"
filterExpression="#{fn:containsIgnoreCase(model.categoryName,
mapActivityGroup.categoryFilter)}" >
<f:facet name="header">
<h:panelGroup>
<h:outputText value="Category" />
<h:inputText value="#{mapActivityGroup.categoryFilter}">
<a4j:ajax render="table" execute="#this" event="blur" />
</h:inputText>
</h:panelGroup>
</f:facet>
<h:outputText value="#{model.categoryName==null?'':model.categoryName}"/>
</rich:column>
</rich:dataTable>
Exception:
java.io.NotSerializableException: org.richfaces.component.SavedState
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
java.util.HashMap.writeObject(HashMap.java:1100)
sun.reflect.GeneratedMethodAccessor1947.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1362)
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1170)
java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1362)
I have googled but couldn't found anything substantial. Does anyone has any idea why is it happening ?
In web.xml I changed javax.faces.STATE_SAVING_METHOD to server and it worked.
I am using p:dataList because I am developing a PrimeFaces mobile view displaying a list of items. When clicking on any item, another pm:view of the same view should be displayed. But the bean should be notified of the selected item.
Unfortunately I couldn't find a way to update the bean successfully: <p:ajax> inside dataTable throws this exception:
<p:ajax> Unable to attach <p:ajax> to non-ClientBehaviorHolder parent
Using <f:setPropertyActionListener> inside the iterative element fails too because I get:
<f:setPropertyActionListener> Parent is not of type ActionSource
This is my code:
<pm:view id="instrumentsView" >
<pm:content >
<h:form id="instrumentsList" >
<p:dataList var="instrument" value="#{instrumentBean.subscribedInstruments}" >
<h:outputLink value="#newView" >#{instrument.longName}</h:outputLink>
<f:setPropertyActionListener value="#{instrument}" target="#{instrumentBean.selectedInstrument}" />
</p:dataList>
</h:form>
</pm:content>
</pm:view>
Clearly, I am using dataList and outputLink because as far as I understand, they are the components optimized for the use in PrimeFaces mobile lists. But I am available to find other options if necessary.
I found out in the showcase (example titled News) the correct way of handling the problem:
<p:dataList var="instrument" value="#{instrumentBean.subscribedInstruments}" >
<p:column >
<p:commandLink value="#{instrument.longName}" action="pm:newView" update=":compId">
<f:setPropertyActionListener value="#{instrument}" target="#{instrumentBean.selectedInstrument}" />
</p:commandLink>
</p:column>
</p:dataList>
There is a topic explaining this in the primefaces documentation.
Selecting Data (page 124)
indexed_primefaces_users_guide_3_5.pdf
http://www.primefaces.org/documentation.html
Here is the content
<h:form id="carForm">
<p:dataGrid var="car" value="#{carBean.cars}" columns="3" rows="12">
<p:panel header="#{car.model}">
<p:commandLink update=":carForm:display" oncomplete="dlg.show()">
<f:setPropertyActionListener value="#{car}"
target="#{carBean.selectedCar}"
<h:outputText value="#{car.model}" />
</p:commandLink>
</p:panel>
</p:dataGrid>
<p:dialog modal="true" widgetVar="dlg">
<h:panelGrid id="display" columns="2">
<f:facet name="header">
<p:graphicImage value="/images/cars/#{car.manufacturer}.jpg" />
</f:facet>
<h:outputText value="Model:" />
<h:outputText value="#{carBean.selectedCar.year}" />
</h:panelGrid>
</p:dialog>
</h:form>