JSF2 and Spring Webflow (<h:commandLink> doesn't respond inside <ui:repeat> facelet tag) - jsf

i am trying to have a List of commandLink in every cell of dataTable.
this is small example explaining what i am trying to do
<h:form id="form1">
<p:dataTable id="doctorTable" var="doctor"
value="#{search.medecinsResult}" rowIndexVar="rowIndex">
<p:column headerText="#{search.headerDate[1]}">
<ui:repeat var="seance" value="#{search.column2[rowIndex]}">
<h:commandLink value="#{seance}" action="Reserver"
title="Réservez cette séance">
</h:commandLink>
<br />
</ui:repeat>
</p:column>
</p:datable>
</h:form>
And i define transition on the page viewState in my XML flow:
<view-state id="result">
<transition on="Reserver" to="next">
</transition>
</view-state>
the commandLink work fine outside repeat tag, but when its inside it just reload the webpage
i found JIRA issues for that, but it not resolved.
link to JIRA issue
if there is any workaround it will be great, thank's for your responses.

It's the <ui:repeat> which is the culprit. It doesn't work very well when nested in another repeating component. There are many related issues for that already, the JSF guys are working on that. The usual solution is to pick a "fullworthy" JSF UIData component instead, such as <h:dataTable>. Since you're already using PrimeFaces, I'd suggest to try <p:dataList> instead.

Related

primefaces panelgrid update from datatable

I am getting "Cannot find component with identifier "contentForm:tabView:form:addressDialogPanel" referenced from "contentForm:tabView:form:addressBookTable" " error. How can I update my panelGrid inside the widget?
<h:form id="form">
<p:dataTable id="addressBookTable">
<p:ajax event="rowSelect" listener="#{addressBookController.onRowSelect}"
update="contentForm:tabView:form:addressDialogPanel" oncomplete="addressDialog.show()" />
</p:dataTable>
<p:dialog id="addressDialogId" widgetVar="addressDialog">
<h:panelGrid id="addressDialogPanel" columns="2" cellpadding="4">
</h:panelGrid>
</p:dialog>
</h:form>
The main problem is that you are giving the wrong client ID of component's. Also p:tabView is a component it is not a form. When you define a h:form, it generates a standart HTML form element. And when you submit the page JSF uses POST to submit your data into backing bean. So nesting them is going to occur lot's of issues that you don't expect. You should seperate forms into sections like sideForm or searchForm or etc.
You should detect the correct client ID of your component when you try to update it. You can do this with your browser's developer settings(press f12 for chrome). Then select component with the magnifier button and give that ID into update property. Just like here:
You should read to learn basics of JSF for example from here

is it possible to send value from <a4j:support> to bean

<rich:tree switchType="client" value="#{Bean.tree}" var="one">
<rich:treeNode>
<h:commandLink value="#{one.item1}"
action="#{Bean.getItem()}"
style="color:blue;text-decoration:none;"
title="Click here to view details">
<f:param name="ids" value="#{one.id}">
</f:param>
</h:commandLink>
<a4j:support event="onclick" reRender="productInformation"
action="#{Bean.getItem()}"/>
</rich:treeNode>
</rich:tree>
<rich:panel id="productInformation">
</rich:panel>
hi I have a page in that tree structure will be present if i click on the link the corresponding action should be performed but by using h:commandlink the whole page will be refreshed.So Iam going for I have a problem here in h:commandlink i was able to transfer the parameter to bean by using f:param but by using how can I acess the value to bean please help me out iam new to jsf.
Solved the solution by using a4j:commandlink tag and passing the parameter from a function.
<
a4j:commandLink ajaxSingle="true" value="#{item.Description}(#{item.name})"
action="#{Bean.getProductLink(item.paramID)}" style="color:blue;text-decoration:none;" title="#{item.productDescription}" reRender="addproductGuidForms"/>
is working fine.
Since you are using JSF2 there is no need to pass with f:param just pass it in method args
action="#{Bean.getItem(one.id)}"
b.t.w you better rename the method name into action="#{Bean.retrieveItem(one.id)}"

<c:foreach> tag not evaluating an object

I have the following piece of code:
<h:outputText value="#{lecture.lectureName}" />
<c:forEach items="#{criterionController.getCriteriaForLecture(lecture)}" var="criterion">
<h:outputText value="#{criterion.criterionName}" />
<h:commandLink value="Edit"/>
<h:commandLink value="Delete"/>
</c:forEach>
The output text part is working perfectly and displays what it should display so this proves that the lecture object is set. However the for each tag gives a null pointer exception. When I debugged the code, I saw that the lecture object was taken as null when the method getCriteriaForLecture() was called.
How can this behaviour explained?
This can happen if the lecturer variable is in turn been set by a JSF iterating component such as <h:dataTable>, <ui:repeat>, etc or probably a <p:tabView>, based on your previous question.
A more detailed explanation of this behaviour can be found here: JSTL in JSF2 Facelets... makes sense? To the point, JSTL tags runs during building the view, not during rendering the view. The lecturer variable is in your particular case only available during rendering the view and is thus always null during building the view, when JSTL runs.
To solve it, use a normal JSF component like <ui:repeat> instead.
<ui:repeat value="#{criterionController.getCriteriaForLecture(lecture)}" var="criterion">
<h:outputText value="#{criterion.criterionName}" />
<h:commandLink value="Edit"/>
<h:commandLink value="Delete"/>
</ui:repeat>
Much better would be not doing business actions in getters at all. Just make the List<Criterion> a property of Lecture instead.
<ui:repeat value="#{lecture.criterions}" var="criterion">
<h:outputText value="#{criterion.criterionName}" />
<h:commandLink value="Edit"/>
<h:commandLink value="Delete"/>
</ui:repeat>
See also Why JSF calls getters multiple times

JSF Primefaces TabView problems

I asked this in the PF Forum but no one seems to want to answer so I though I'd try my luck here.
I have a ui:repeat that is not being updated correctly after an Ajax call when it is within a TabView.
Simple scenario is I have a ui:repeat pointing at an ArrayList (ArrayList contains simple pojos with a String). Within this I have an h:inputText whose value is the pojo's String getter/setter. The ui:repeat is contained within a h:panelGroup. I use a p:commandButton to run an action to update the ArrayList (just add a couple of objects to it a Math.random value for the String) and then update the h:panelGroup. The updated values in the ArrayList are not reflecting in the ui:repeat input fields. This only appears to be affecting input fields as outputText fields do update correctly. Also if I do the same for a p:dataTable the input field are updated correctly. If I remove the Tabview and Tab tags it works fine.
As it works when removing the Tabs I can only assume this is a bug and not designed to work like this. If someone could please confirm if this is so or if there is a viable work around. I need to use a ui:repeat as my fields are not in a tabular format. This has only occurred since migrating from PF 2.2. I'm currently on PF 3.1, Weblogic 10.3.4 and Mojarra 2.0.4
<p:tabView>
<p:tab title="Test">
<h:form prependId="false">
<p:commandButton id="testStringCheck"
value="Test String Check"
process="#form"
update="testPanel"
action="#{testBean.generateVOwithRandomStrings}">
</p:commandButton>
<h:panelGroup id="testPanel" layout="block">
<ui:repeat value="#{testBean.voList}" var="entry">
<h:outputText value="#{entry.randomString}"/>
<p:inputText style="display:block;"
value="#{entry.randomString}"
size="15">
</p:inputText>
</ui:repeat>
</h:panelGroup>
</h:form>
</p:tab>
</p:tabView>
As a workaround I've used a p:datagrid instead of a ui:repeat. This achieves the look I had in the the ui:repeat so I'm happy. Hopefully this bug will be fixed on future releases.
This is something of a bug in Primefaces commandButton. See the following thread:
http://forum.primefaces.org/viewtopic.php?f=3&t=17454
You can try replacing
<p:commandLink id="testStringCheck" ... update="#form" />
With an <h:commandLink>
<h:commandLink id="testStringCheck" render="#form"/>
Also from the above link here is an interesting method that somebody posted that enables you to correctly find the correct clientId to update.
http://paste.kde.org/177698/
temp solution: insert outside h:panelGroup:
<p:outputPanel defered="true" delay="1" ..>
and update outputPanel instead of panelGroup
Or use a datalist component instead of ui:repeat.
One more, i'm not sure but you can try, so update class instead id:
<h:panelGroup id="testPanel" layout="block" styleClass="testPanelCl" ../>
and update : #(.testPanelCl), don't forget id of panelGroup, without id JSF can not update by class

javax.faces.ViewState is missing after ajax render

This is not a duplicate post, i just done research but not helping.
First, this is my page... simplified for easy reading.
<h:form id="treeForm">
<f:event type="preRenderView" listener="#{taskTreeBean.update}" />
<rich:tree id="tree" nodeType="#{node.type}" var="node"
value="#{taskTreeBean.rootNodes}" toggleType="client"
selectionType="ajax"
render="#all"
selectionChangeListener="#{taskTreeBean.selectionChanged}">
<rich:treeNode>
...
</rich:treeNode>
</rich:tree>
</h:form>
<h:form id="taskListTableForm">
<rich:dataTable id="taskListTable" styleClass="tasklist" keepSaved="true" value="#{taskListModel}" var="task"
rowClasses="odd-row, even-row" rows="3">
<rich:column>
...
</rich:column>
<f:facet name="footer">
<rich:dataScroller id="scroller" for="taskListTable" />
</f:facet>
</rich:dataTable>
</h:form>
When i click some tree node, task list form will render, but the viewstate will disappear, which makes dataScroller requires two clicks to next/prev page since the first click is getting back the ViewState value.
I checked the JIRA here - http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-790.
Tried render="#all" or render="treeForm, taskListTableForm", both failed. I cannot wait mojarra to release 2.2. So is there any workaround here?
Thanks so much. The JIRA is just too difficult to understand.
Edited: There is another problem, the page go from 1 to 2 in the dataTable if i click the tree node. Why?
I am aware that you probably solved this problem, but for future reference, this should provide others with the solution.
I had the same problem and worked around it by replacing <f:ajax/> with <p:ajax/> from PrimeFaces 3.0. The page in question has no other PrimeFaces components. I don't know why it works, but hopefully it will in your case.

Resources