JSF & Primefaces: Component ID just won't get found - jsf-2

I keep receiving the same exception again and again. Comparing exception and hmtl-output without for="#{choiceRadio.clientId}" seems to tell me that binding works. But it just doesn't and I feel like I am missing something huge.
The Code:
<p:selectOneRadio binding="#{choiceRadio}" value="#" layout="custom">
<f:selectItems value="#" />
</p:selectOneRadio>
<h:panelGrid columns="1">
<ui:repeat var='choice' value='#{item.items3}'>
<p:radioButton for="#{choiceRadio.clientId}" />#{choice.name}
</ui:repeat>
</h:panelGrid>
</h:form>
The Exception:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Cannot find component 'j_idt34:0:j_idt36:2:j_idt46:j_idt82' in view.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
root cause
javax.faces.FacesException: Cannot find component 'j_idt34:0:j_idt36:2:j_idt46:j_idt82' in view.
org.primefaces.component.radiobutton.RadioButtonRenderer.findSelectOneRadio(RadioButtonRenderer.java:126)
org.primefaces.component.radiobutton.RadioButtonRenderer.encodeEnd(RadioButtonRenderer.java:35)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
com.sun.faces.facelets.component.RepeatRenderer.encodeChildren(RepeatRenderer.java:104)
com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:523)
com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:984)
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
org.primefaces.component.lightbox.LightBoxRenderer.encodeMarkup(LightBoxRenderer.java:52)
org.primefaces.component.lightbox.LightBoxRenderer.encodeEnd(LightBoxRenderer.java:32)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:59)
org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:43)
org.primefaces.component.outputpanel.OutputPanelRenderer.encodeEnd(OutputPanelRenderer.java:46)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
com.sun.faces.facelets.component.RepeatRenderer.encodeChildren(RepeatRenderer.java:104)
com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:523)
com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:984)
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:55)
org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:43)
org.primefaces.component.outputpanel.OutputPanelRenderer.encodeEnd(OutputPanelRenderer.java:46)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
com.sun.faces.facelets.component.RepeatRenderer.encodeChildren(RepeatRenderer.java:104)
com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:523)
com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:984)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
note The full stack trace of the root cause is available in the JBoss Web/7.0.13.Final logs.
JBoss Web/7.0.13.Final
Without ui:repeat I don't get any exception but without ui:repeat I do not have any content either:
<p:selectOneRadio id="myRadio" value="#{cartBean.selectedChoice}" layout="custom">
<f:selectItems value="#{item.items3}" />
</p:selectOneRadio>
<h:panelGrid columns="1">
<p:radioButton for="myRadio" value="hh" itemIndex="0"/>
</h:panelGrid>
</h:form>

The for attribute of the radioButton must be the id of the selectOneRadio it refers to.
Add an id to your selectOneRadio and refer to it in the button:
<p:selectOneRadio id="myRadio" binding="#{choiceRadio}" value="#" layout="custom">
<f:selectItems value="#" />
</p:selectOneRadio>
<h:panelGrid columns="1">
<ui:repeat var='choice' value='#{item.items3}'>
<p:radioButton for="myRadio" />#{choice.name}
</ui:repeat>
</h:panelGrid>
EDIT
You might need to prepend the ids of all NamingContainers right from ViewRoot before the element id, like: for="form_id:myRadio".
When in doubt what the exact absolute id of an element might be, look at it in FireBug (Firefox) or developer tools (Chrome) or search for its given id (in this case "myRadio") in the html output source and skip possible numbers in-between.
So this
id="iterateCategories:0:iterateItems:2:lightForm:radioForm"
would become
iterateCategories:iterateItems:lightForm:radioForm
as your absolute id.

Related

Caused by: javax.el.PropertyNotFoundException: Property 'addUtilisateur' not found on type com.faycal.bean.UtilisateurBean [duplicate]

I've the following code snippet in my Facelet:
<h:commandLink id="cmdbtn">
<f:ajax event="click" execute="#form"
listener="#{screenShotBean.takeScreenshot}" />
</h:commandLink>
It works fine, but when I outcomment it like this,
<!-- <h:commandLink id="cmdbtn"> -->
<!-- <f:ajax event="click" execute="#form" -->
<!-- listener="#{screenShotBean.takeScreenshot}" /> -->
<!-- </h:commandLink> -->
then it throws the following exception:
javax.el.PropertyNotFoundException: Property 'takeScreenshot' not found on type monstage.test.com.ScreenShotBean
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)
at javax.el.BeanELResolver.property(BeanELResolver.java:325)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at com.sun.faces.facelets.el.ELText$ELTextVariable.toString(ELText.java:217)
at com.sun.faces.facelets.el.ELText$ELTextComposite.toString(ELText.java:157)
at com.sun.faces.facelets.compiler.CommentInstruction.write(CommentInstruction.java:77)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:424)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
When I change the method expression with parentheses as below,
<!-- <h:commandLink id="cmdbtn"> -->
<!-- <f:ajax event="click" execute="#form" -->
<!-- listener="#{screenShotBean.takeScreenshot()}" /> -->
<!-- </h:commandLink> -->
Then doesn't throw the exception, but it's still invoked.
How is this caused and how can I solve it?
Look closer at the stack trace. Here's the relevant part:
...
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
com.sun.faces.facelets.el.ELText$ELTextVariable.toString(ELText.java:217)
com.sun.faces.facelets.el.ELText$ELTextComposite.toString(ELText.java:157)
com.sun.faces.facelets.compiler.CommentInstruction.write(CommentInstruction.java:77)
...
It's thus evaluating EL in a comment block (recognizable by CommentInstruction). A comment block is considered as template text. Facelets evaluates by default also EL #{} in template text. It's like as if you're writing <p>#{screenShotBean.takeScreenshot}</p> without any JSF tag.
You've several options:
Remove the comment block altogether.
Escape EL expressions in the comment by prefixing it with \ as in
\#{screenShotBean.takeScreenshot}
so that they won't be evaluated.
Wrap the entire comment block in <ui:remove> so that it doesn't appear in the component tree (nor in the generated HTML output).
Disable parsing of all comments by Facelets by adding the following context parameter to web.xml:
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
Note that no one comment will end up in generated HTML output this way.
In addition to the options BalusC already provided you could also add the attribute rendered="false" to your commandLink.
If you have several components you want to be able to toggle quickly, you might want to consider creating a debug property in a bean or use the project stage:
rendered="#{facesContext.application.projectStage == 'Development'}"
You could also use the context parameter that skips comments in your web.xml.
This is the parâmeter:
javax.faces.FACELETS_SKIP_COMMENTS

binding on p:dataTable which is included multiple times causes ID unqiueness exceptions

I'm attempting to use a special PrimeFaces data exporter implementation as being used in this answer:
https://stackoverflow.com/a/14413932/396732
Our use case however is a little more complex, e.g. using Facelets to show the respective datatable for export, which has row expansions with sub tables in them.
insiderListManagerDialogs.xhtml:
<ui:include src="insiderListManagerListDialog.xhtml">
<ui:param name="idPrefix" value="il-emp" />
<ui:param name="widgetVarPrefix" value="ilEmp" />
<ui:param name="dialogTitle" value="#{msg['entity.employee.internal.plural.label']}" />
<ui:param name="mapPropertyName" value="insiderListEmployeesMap" />
<ui:param name="sortColumn" value="#{ent.lastTime}" />
<ui:param name="keyColumnsXhtml" value="listDialogInsiderListKeyColumns.xhtml" />
<ui:param name="valueColumnsXhtml" value="listDialogEmployeeValueColumns.xhtml" />
</ui:include>
insiderListManagerListDialog.xhtml:
<p:dialog id="#{idPrefix}-il-view-dialog"
widgetVar="#{widgetVarPrefix}Dialog"
header="#{dialogTitle}"
modal="true"
resizable="false"
appendToBody="true"
onShow="resetFilterInput( '#{idPrefix}' );"
width="1000"
height="750">
<h:form id="#{idPrefix}-il-view-form">
<p:dataTable id="list-entities"
widgetVar="listEntitiesTable"
binding="#{table}"
value="#{insiderListManager.listInstances}"
var="key"
scrollable="true"
scrollHeight="625"
scrollWidth="985"
resizableColumns="true"
expandedRow="#{insiderListManager.listEntitiesRowTogglerOpen}"
filteredValue="#{insiderListManager.filteredEntities}"
sortBy="#{sortColumn}"
styleClass="bx-datatable-header-hidden-m"
tyle="width: 970px;">
<f:facet name="header">
<p:inputText id="globalFilter"
onkeypress="if (event.keyCode == 13) { listEntitiesTable.filter(); return false;}"
size="70"
styleClass="bx-dt-header-element" />
<p:commandButton id="search-btn"
icon="ui-icon bx-icon-search"
value="#{msg['common.action.search.label']}"
process="#this"
onclick="listEntitiesTable.filter(); return false;"
styleClass="bx-dt-header-element" />
<p:commandButton title="#{msg['common.action.excelExport.all.hint']}"
icon="ui-icon bx-icon-excel"
action="#{insiderListManager.exportXls( table )}"
ajax="false"
styleClass="bx-button-border bx-dt-header-element" />
<div class="bx-clear-float" />
</f:facet>
<p:column width="15"
resizable="false">
...
<p:rowExpansion>
<p:dataTable value="#{insiderListManager[mapPropertyName].get(key)}"
var="value">
<ui:include src="#{valueColumnsXhtml}" />
</p:dataTable>
</p:rowExpansion>
</p:dataTable>
<h:panelGroup id="button-panel" layout="block" styleClass="left-button-panel mt-5px">
<p:commandButton id="toggle-button"
icon="#{insiderListManager.listEntitiesRowTogglerOpen ? 'ui-icon ui-icon-circle-triangle-e' : 'ui-icon ui-icon-circle-triangle-s'}"
value="#{insiderListManager.listEntitiesRowTogglerOpen ? msg['common.action.collapseAll.label'] : msg['common.action.expandAll.label']}"
process="#this"
update="#form">
<f:setPropertyActionListener target="#{insiderListManager.listEntitiesRowTogglerOpen}"
value="#{not insiderListManager.listEntitiesRowTogglerOpen}" />
</p:commandButton>
</h:panelGroup>
</h:form>
</p:dialog>
Note the
<p:commandButton title="..."
icon="ui-icon bx-icon-excel"
action="#{insiderListManager.exportXls( table )}"
... />
which is using the bound data table as described in the link posted at the top.
We are using JSF 2.1 (Mojarra 2.1.22 - and we cannot switch to MyFaces) which allows expressions to construct IDs like #{idPrefix}-il-view-dialog from a <ui:param name="idPrefix" value="il-emp" />.
However, we are getting ID uniqueness exception:
Caused by: java.lang.IllegalStateException: Component ID il-emp-il-view-form:list-entities:globalFilter has already been found in the view.
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:846)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:830)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:830)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:830)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:830)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:830)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:830)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:830)
at com.sun.faces.application.view.StateManagementStrategyImpl.saveView(StateManagementStrategyImpl.java:144)
at com.sun.faces.application.StateManagerImpl.saveView(StateManagerImpl.java:133)
at com.sun.faces.application.view.WriteBehindStateWriter.flushToWriter(WriteBehindStateWriter.java:225)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:419)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.ocpsoft.pretty.faces.application.PrettyViewHandler.renderView(PrettyViewHandler.java:163)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
... 49 more
Same happens to other buttons with explicit IDs if omitted, e.g. the search button (<p:commandButton id="search-btn" ...).
QUESTION:
Why is this happening and how can we avoid this problem when we are bound to using PrimeFaces dialogs for each use case displayed? (we have more than one dialog)
Note that when removing the <p:dataTable ... binding="..." the page works correctly.
You're basically binding physically different <p:dataTable> components to one and same EL variable. If this EL variable is not null (i.e. already set by a previous component in the same view), then JSF will reuse it instead of creating a new one, and override all of its attributes during view build time, resulting in "weird" behavior during view render time and potential duplicate component ID errors during state saving.
In your specific case, you can use UIComponent#getNamingContainer() to directly reference the parent <p:dataTable> component from inside a child component.
<p:dataTable ... (NO binding!)>
...
<p:comandButton ... action="#{bean.exportXls(component.namingContainer)}" />
Might it happen that it's nested in another NamingContainer component, then you need to use #{component.namingContainer.parent.namingContainer} instead. And so forth for multiple ones.

Passing parameters between two jsf pages with parameter conversion

I am a newbie on jsf i want to display the details of a question when i click on a h:link and to do so i need to pass the question id between two jsf pages (i have a detail page and another page that display a list of questions to display their details) but this id is of type Long so i need to convert it in order to be able to look for it in the database but i don't know how to do so.
I google it but the code i wrote after the search don't work. Here's the code
<p:dataList value="#{questionBean.questionsForums}" var="quests"
itemType="none">
<p:panel >
<f:facet name="header">
<h:outputText value="#{quests.nbupvote}"
style="margin-right:30px;color:#cdcdcd" class="voteBox" />
<h:outputText class="font-custom" value="#{quests.titre}" />
</f:facet>
<h:link value="Consulter Détails" outcome="question">
<f:param name="quesId" value="#{quests.quesPk}" >
</f:param>
</h:link>
</p:panel>
</p:dataList>
and this the code of the managedBean
private String quesPk;
private Question detailQuestion;
public Question getDetailQuestion() {
return detailQuestion=qDao.selectDetail(Long.valueOf(quesPk));
}
public void setDetailQuestion(Question detailQuestion) {
this.detailQuestion = detailQuestion;
}
And this in the log with the exception
2014-01-16T21:11:22.145+0100|Grave: Error Rendering View[/question.xhtml]
javax.el.ELException: /question.xhtml #52,24 value="#{questionBean.detailQuestion}": java.lang.NumberFormatException: null
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIData.getValue(UIData.java:732)
Caused by: javax.el.ELException: java.lang.NumberFormatException: null
at javax.el.BeanELResolver.getValue(BeanELResolver.java:368)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstValue.getValue(AstValue.java:140)
at com.sun.el.parser.AstValue.getValue(AstValue.java:204)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 53 more
Caused by: java.lang.NumberFormatException: null
at java.lang.Long.parseLong(Long.java:404)
at java.lang.Long.valueOf(Long.java:540)
at com.portail.managedBeans.QuestionBean.getDetailQuestion(QuestionBean.java:33)
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)
2014-01-16T21:11:22.220+0100|Avertissement: StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NumberFormatException: null
at java.lang.Long.parseLong(Long.java:404)
at java.lang.Long.valueOf(Long.java:540)
at com.portail.managedBeans.QuestionBean.getDetailQuestion(QuestionBean.java:33)
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 javax.el.BeanELResolver.getValue(BeanELResolver.java:363)
And this is the code of the details of the question
<h:head>
<f:metadata>
<f:viewParam name="quesId" value="#{questionBean.quesPk}" converter="javax.faces.Long" />
</f:metadata>
</h:head>
<h:form>
<p:dataList value="#{questionBean.detailQuestion}" var="quests"
itemType="none">
<h:outputText value="1" style="margin-right:30px;color:#cdcdcd"
class="voteBox" />
<h3><h:outputText class="font-custom"
value="#{quests.titre}" /></h3><br/><p:separator></p:separator>
<h:outputText class="font-custom"
value="#{quests.contenu}" />
<div class="navfooter" style="margin-left: 20%">
<ul>
<li>Modifier</li>
<li style="margin-left: 40%">Auteur</li>
</ul>
</div>
</p:dataList>
I am using eclipse kepler and jsf2 and primefaces. If you know how it can be done please tell me
#ManagedProperty is not the right tool for the job of converting a submitted value and setting it as a bean property. HTTP request parameters are inherently strings. Better use <f:viewParam>, you can attach a converter to it like as you would do to <h:inputText>.
Source page:
<h:link value="Consulter Détails" outcome="question">
<f:param name="quesId" value="#{quests.quesPk}" />
</h:link>
Target page (question.xhtml):
<f:metadata>
<f:viewParam name="quesId" value="#{questionBean.quesPk}" converter="javax.faces.Long" />
</f:metadata>
With
private Long quesPk; // +setter
See also:
ViewParam vs #ManagedProperty(value = "#{param.id}")
What can <f:metadata>, <f:viewParam> and <f:viewAction> be used for?
Unrelated to the concrete problem, doing business logic in getter methods is a bad idea. Don't do that. Use <f:event type="preRenderView"> or <f:viewAction> listener method.
See also:
Why JSF calls getters multiple times

Constructor of a viewScoped class invoked twice

I've been struggling with this for two days with no success and I think it's already time to ask for your help. But first of all, this is what I'm using:
JSF 2 Mojara 2.1.1
Primefaces 3.4.2
Netbeans 7.1.1
Tomcat 7.0.37
And now, the problem: I have a main page which is composed by several other pages using several <ui:include .. /> tags, like this:
<ui:composition template="/resources/templates/template1.xhtml">
<ui:define name="appData">
<p:panelGrid columns="1" id="contenidoAplicacion" styleClass="noborder">
<h:form id="fNewPerson">
<p:panel header="New employee" style="min-height:40em">
<ui:include src="./forms/personal.xhtml" />
<p:accordionPanel styleClass="noborder" activeIndex="3">
<p:tab id="tabSomeData" title="Identidad profesional" >
<ui:include src="./forms/formSomeData.xhtml" />
</p:tab>
....
....
</ui:define>
</ui:composition>
The personal.xhtm file looks like this:
<p:panelGrid>
<p:row>
<p:column >
<h:outputLabel value="Field1"/>
<p:inputText label="Field1" id="field1" value="#{dataBacking.selectedPerson.field1}" tabindex="1"
required="true" size="10" >
<f:convertNumber for="field1" integerOnly="true" groupingUsed="false"/>
</p:inputText>
<p:inputText id="field2" value="#{dataBacking.selectedPerson.field2}" tabindex="2" required="true" size="1" maxlength="1" >
<p:ajax event="keyup" listener="#{dataBacking.check}"
process="field1 field2" partialSubmit="true"
update="field1 field2 photo"/>
</p:inputText>
</p:column>
<p:column rowspan="5" >
<p:graphicImage id="photo" value="#{dataBacking.selectedPerson.photo}" width="90" />
</p:column>
</p:row>
...
</p:panelGrid>
The check() method in the dataBacking class is irrelevant because it only checks if the field1 and the field2 meet some rules and it works properly. The problem comes when the main page is loaded for the first time. In that case, the <p:ajax /> component in personal.xhtml doesn't work. I have to reload the page (simply by pressing the F5 key) and this time it works as it would be expected.
I've been changing some attributes of the component, but nothing seems to work. I really don't know what else to do. Any kind of help will be apreciated.
EDITED. After one more day, I think the problem has nothing to do with Primefaces ajax component, as the title of the question suggested. I've come to this conclusion through these two facts:
The behaviour with the <f:ajax .../> component remains the same.
I've figured out that the view relative to the first time I load the page is not persisted. I'll try to explain myself.
The DataBacking class has defined its scope as view so that the page can "see" all the attributes and methods during the time it's been shown to the user. However, I've noticed that the constructor is called twice: the first time the page is loaded (and then, none of the methods of the class are successfully invoked) and when I refresh the page. In this last case, the behaviour of both the page and the class is the expected one.

p:dataTable and MalformedByteSequenceException

I receive this error when I try to add the tag p:dataTable on my project:
An Error Occurred:
Byte non valido 1 della sequenza UTF-8 a 1 byte.
- Stack Trace
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Byte non valido 1 della sequenza UTF-8 a 1 byte.
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:687)
at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:557)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1750)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.peekChar(XMLEntityScanner.java:494)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2647)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:302)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
at com.sun.faces.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:423)
at com.sun.faces.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:399)
at com.sun.faces.facelets.compiler.Compiler.compile(Compiler.java:124)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.createFacelet(DefaultFaceletFactory.java:305)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.access$100(DefaultFaceletFactory.java:93)
at com.sun.faces.facelets.impl.DefaultFaceletFactory$1.newInstance(DefaultFaceletFactory.java:160)
at com.sun.faces.facelets.impl.DefaultFaceletFactory$1.newInstance(DefaultFaceletFactory.java:158)
at com.sun.faces.facelets.impl.DefaultFaceletCache$1.newInstance(DefaultFaceletCache.java:83)
at com.sun.faces.facelets.impl.DefaultFaceletCache$1.newInstance(DefaultFaceletCache.java:78)
at com.sun.faces.util.ExpiringConcurrentCache$1.call(ExpiringConcurrentCache.java:99)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at com.sun.faces.util.ExpiringConcurrentCache.get(ExpiringConcurrentCache.java:114)
at com.sun.faces.facelets.impl.DefaultFaceletCache.getFacelet(DefaultFaceletCache.java:121)
at com.sun.faces.facelets.impl.DefaultFaceletCache.getFacelet(DefaultFaceletCache.java:62)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.getFacelet(DefaultFaceletFactory.java:256)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.getFacelet(DefaultFaceletFactory.java:201)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:764)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at it.cyborg.cdg.jsfClasses.util.MultipartFilter.doFilter(MultipartFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
- Component Tree
<UIViewRoot id="j_id1" inView="true" locale="it_IT" renderKitId="HTML_BASIC" rendered="true" transient="false" viewId="/progetti/List.xhtml"/>
- Scoped Variables
Request Parameters
Request Parameters
Name
Value
j_idt24
j_idt24
j_idt24:j_idt25
j_idt24:j_idt25
View Attributes
View Attributes
Name
Value
None
Request Attributes
Request Attributes
Name
Value
None
Flash Attributes
Flash Attributes
Name
Value
None
Session Attributes
Session Attributes
Name
Value
logicBean
it.cyborg.cdg.logic.LogicBean#9ba2b1
stiliPortaleController
it.cyborg.cdg.jsfClasses.StiliPortaleController#1d62330
userBean
it.cyborg.cdg.UserBean#1a04a2f
Application Attributes
Application Attributes
Name
Value
csfcff
com.sun.faces.context.flash.ELFlash#665898
5-mar-2012 12.34.10 - Generated by Mojarra/Facelets
<br/>
Where could be the problem?
The xhtml page (that contained a h:dataTable) was modify replacing the dataTable and the column tag with those of PrimeFaces, the class was modify to return a List object and not a DataModel...
I saw this example:
http://www.primefaces.org/showcase-labs/ui/datatableSorting.jsf
and it seems simple to add the sorting option because I must not add any specific code into java's class...
However here it is my code:
List.xhtml:
...
<p:dataTable value="#{progettiController.itemsList}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px" id="dataTable">
<p:column sortBy="#{item.id}">
<f:facet name="header">
<h:outputText value="#{bundle.ProgettiTitle_id}"/>
</f:facet>
<h:commandLink action="#{progettiController.prepareView}" value="#{item.id}"/>
</p:column>
<p:column sortBy="#{item.oggetto}">
<f:facet name="header">
<h:outputText value="#{bundle.ProgettiTitle_oggetto}"/>
</f:facet>
<h:outputText value="#{item.oggetto}"/>
</p:column>
...
ProgettiController.java:
...
private List itemsList;
...
public void setItemsList()
{
itemsList=logic.method.findProgettiByQuery(); //--- a method that returns a sublist of Progetti and that worked correctly
}
...
public List getProgetti()
{
return itemsList;
}
...
Thank you for your help!
Update: Ok, I think I understand where the problem was... It's not in p:datatable and not in p:column but in my ability to copy and paste from the web... Sometimes the space character isn't recognized correctly so I must replace all spaces with new spaces...
I don't know which PF version you are using, but the one that I use (2.2) has no attribute rowClasses.
However, h:dataTable has this attribute. But I don't know how Primefaces handles this situation. From my experience, sometimes it works to use attributes of underlying jsf components, sometimes not.
The error is of course a little generic and misleading. Seems like an unhandled exception from the lower xml parsing layers.

Resources