Can't rerender component which is bulilt through foreach - jsf

i have a div which consists of set of checkboxes built through foreach as follows:
<ice:panelGroup id="myDiv">
<c:forEach items="#{myBean.myCheckBoxes}" var="entry" varStatus="loop">
<input type="checkbox" name="myCheckBoxes" value="#{entry.value}" />
<span class="#{fn:contains(entry.value,'g') ? 'bold-style' : ''}">#{entry.key}</span>
</c:forEach>
</ice:panelGroup>
and i have an icefaces button in the same form of that div, and the button makes partial submit, i don't want to make full form submit.
<ice:commandButton value="Find" action="#{myBean.find}" partialSubmit="true">
<f:ajax execute="#this" render="myDiv" />
</ice:commandButton>
the search method:
public void find() {
// changes the map of the iteration
}
what happens, is that after executing search some components doesn't get removed from the div, although that they are not in the map, guess that the div is not getting refreshed/populated with data correctly, please advise, thanks.

solved by using ui:repeat instead of foreach.

Related

h:commandlink call to action only second click

My commandlink is calling to action only in the second click. I added a debug point and tried. first click it doesn't come to method. Only second click it hit the action.
I tried by adding the script as mentioned in here but it didn't help. Any other solution to resolve this? instead h:commandlink ?
<h:form>
<h:panelGroup id="new-line-panel">
some code goes here....
<h:panelGroup id="numberSelectionPanel">
<ui:repeat var="newLineItem" value="#{SelectionBean.Cards}" >
<span class="new-line-item">
<h:commandLink id="no-#{newLineItem.serNo}"
styleClass="#{SelectionBean.serNo == newLineItem.serNo ? 'selected' : ''} btn"
action="#{SelectionBean.populateSelectedNum(newLineItem.serNo)}">
<f:ajax render=":form:numberSelectionPanel" execute="#form"/>
#{newLineItem.serNo}
</h:commandLink>
</span>
</ui:repeat>
</h:panelGroup>
some more code
</h:panelgroup>
</h:form>
in the SelectionBean method
public void populateSelectedNumber(String number) {
this.serNo = number; // I added debug point here
selectedMnpMessage = null;
}

Dynamically created Div did not get updated after calling rerender event

I am using RichFaces 3.3.x and Tomahawk. I have an input field which has a4j:support on onkeyup and I am using 'process' to update the backing bean. Afterwards I use 'reRender' to get my backing bean (freshly) created div. Unfortunately the getter of the session scoped bean created Div is not called! What should I do?
<t:inputText id="searchString"
value="#{beans.searchString}"
onkeydown="if (event.keyCode == 13) { return false; }">
<a4j:support event="onkeyup" requestDelay="200" ajaxSingle="true"
reRender="resultsDiv" eventsQueue="quicksearchqueue"
ignoreDupResponses="true"
process="searchString"
/>
</t:inputText>
<t:div id="results" binding="#{bean.resultsDiv}" />
Firstly, the id you put in a4j:support to reRender is "resultsDiv" which is different from "results" id of .
If this is not the origin of your problem, try to put the region you want to update within ajax inside an ajax rendered outputPanel, example:
<a4j:outputPanel id="resultsDiv" ajaxRendered="true" >
<t:div id="results" binding="#{bean.resultsDiv}" />
</a4j:outputPanel>
And of course use the outputPanel's id in the reRender value of a4j:support
Except for the wrong ids in the code above, I had the same problem. I used a rich:tree and the reRender attribute to rerender a dynamic generated div component. It simply did not work. If you use a rich:panel instead of the div component, it will work just fine:
<t:inputText id="searchString"
value="#{beans.searchString}"
onkeydown="if (event.keyCode == 13) { return false; }">
<a4j:support event="onkeyup" requestDelay="200" ajaxSingle="true"
reRender="results" eventsQueue="quicksearchqueue"
ignoreDupResponses="true"
process="searchString"
/>
</t:inputText>
<rich:panel id="results" binding="#{bean.yourPanel}" />
In the backing bean you put your generated div as a child to the rich panel component like this:
yourPanel.getChildren().add(yourGeneratedDiv);
I have no idea why it does not work with the t:div component though. Any answer on this would be appreciated.

richfaces tooltip for inputtext

I want to have a tooltip for an inputtext and I need the tooltip to be updated when I complete the inputtext. I place this elements inside a form.
The inputtext takes the value from a backing bean, and the value is set in the bean only when I submit the form. Yhe tooltip also takes the value from the bean.\
Here is some code I use (of course, it is not working):
<h:inputText id="inp" value="#{individual.givenName}">
<a4j:support event="onchange" reRender="inp" />
</h:inputText>
<rich:toolTip id="inp_tip">#{individual.givenName}</rich:toolTip>
I want the tooltip to be updated when I type some text. Any idea how I can do this?
Thanks!
You can get the tooltip updated by implementing something like this:
<a4j:region id="a4jRegion">
<h:panelGroup layout="block" id="divTooltipInputText">
<h:inputText id="inp" value="#{individual.givenName}">
<a4j:support event="onchange" reRender="divTooltipInputText" />
</h:inputText>
<rich:toolTip for="inp" id="inp_tip">#{individual.givenName}</rich:toolTip>
</h:panelGroup>
</a4j:region>
The a4j:region will limit the processing on the onchange event to just the inputText and toolTip.

f:ajax inside ui:repeat

I need to show a list of auction items. When a user clicks on a Bid button next to each item, I'd like to have ajax open a bid form right under this auction item. So I'm going with a ui:repeat and a f:ajax as shown below, but when I go to the page all the auction items have the bid component open next to them. And clicking any of the buttons doesn't do anything. This is the code (with the bid form simplified to just an outputText:)
<h:form>
<table border="1">
<ui:repeat var="parcel" varStatus="status" value="#{auctionsViewBean.parcels}">
<tr>
<td><h:commandButton value="Bid" action="nothing">
<f:ajax render="bidView"/>
</h:commandButton></td>
<td>#{status.index + 1}</td>
<td>#{parcel.a}</td>
<td>#{parcel.b}</td>
<td>#{parcel.c}</td>
</tr>
<tr><td><h:outputText id="bidView" value="#{auctionsViewBean.showBidViewForParcel(parcel)}">Some text</h:outputText></td></tr>
</ui:repeat>
</table>
</h:form>
What am I doing wrong? And how can I specify only the bid component related to the clicked auction item?
If I understand you correctly, you want to initially hide the bidView until the button is pressed? You can do it by giving it a rendered attribute and put it in another component which can be referenced by <f:ajax>. You only need to rearrange the action method and checking logic.
<h:commandButton value="Bid" action="#{auctionsViewBean.addBidView(parcel)}">
<f:ajax render="bidView" />
...
<h:panelGroup id="bidView">
<h:panelGroup rendered="#{auctionsViewBean.showBidView(parcel)}">
...
</h:panelGroup>
</h:panelGroup>
with something like this:
public void addBidView(Parcel parcel) {
bidViews.put(parcel, new BidView());
}
public boolean isShowBidView(Parcel parcel) {
return bidViews.containsKey(parcel);
}

JSF valueChangeListener not fired on form submission

On selecting a DIV element, i take the value of the selected DIV's hidden element and pass it on to a form with hidden element in it. This form is then submitted.
Below are pieces of my code.
The value of the hidden input inside the form is correctly set
on selecting the DIV and the form is also submitted but the valueChangeListener is not fired.
Every hint is welcome!
-choesang
Form with hidden element:
<a4j:form id="currentForumPost" ajaxSubmit="true"
onsubmit="console.log('currentForumPost is submitted');
console.log(jQuery('#currentForumPost:currentPostId').val())" >
<h:inputHidden id="currentPostId"
valueChangeListener="#{forumController.changeListenerSelectedForumPost}"
immediate="true"/>
</a4j:form>
DIV element:
<div class="block ui-accordion ui-widget ui-helper-reset"
onclick="var x = jQuery(this).find('.hiddenInputText').val();
jQuery(this).closest('#RightPane').find('#currentForumPost:currentPostId').val(x);
jQuery(this).closest('#RightPane').find('#currentForumPost').submit();">
<h:inputText value="#{post.uuid}" styleClass="hiddenInputText"/>
......
</div>
Java
public void changeListenerSelectedForumPost(final ValueChangeEvent event) {
setSelectedForumPost(event.getComponent().getAttributes().get("value").toString());
}
It appears that you do not have a valueChangeListener attribute on the inputText. You need this attribute so JSF knows which listener to call. Assuming your bean is named 'bean', here is an example:
<h:inputText value="#{post.uuid}" valueChangeListener="#{bean.changeListenerSelectedForumPost}" styleClass="hiddenInputText" />

Resources