JSF a4j:commandLink component doesn't work inside a4j:repeat - jsf

I have such code in my JSF template:
<h:form>
<table id="users" cellspacing="0">
<a4j:repeat var="person" value="#{personList}">
<tr>
<td class="col1">
<a4j:commandLink
disabled="#{!canCreatePerson}"
styleClass="#{canCreatePerson ? '' : 'inactive_link'}"
action="#{adminPageController.create}"
reRender="user-dialog-region"
timeout="5000"
limitToList="true"
ignoreDupResponses="true"
title="#{canCreatePerson ? messages['edit_user'] : ''}"
onclick="if (!ajaxSubmissionAllowed) {return false;}
ajaxSubmissionAllowed=false;"
oncomplete="ajaxSubmissionAllowed=true;">
<h:outputText id="userName" value="#{person.name}"/>
</a4j:commandLink>
</td>
</tr>
</table>
</h:form>
This perfectly works outside the a4j:repeat tag, but no action performs inside a4j:repeat like it's implemented in my template.

The problem was in SCOPE type of the variable personList, it was CONVERSATION, after I've changed it to PAGE everything works fine.
It's strange that I didn't see any error from SEAM.

Related

How to refresh inputboxes in JSF after ajax submit command?

I have an inputText and an inputTextArea in JSF (shown below) that I carry out an ajax action on. However, after my ajax event, the values remain in the input boxes. Is there a simple way to refresh these text boxes after the commandButton is involked? Thanks.
<table>
<tr>
<td><div class="white"><H2>Comments</H2></div>
<h:inputText class="inputboxes" id="username"
value="#{commentBean.comment.commentname}" size="20">
</h:inputText><br/><br/>
<h:inputTextarea rows="5" cols="55" id="comment" class="inputbox" value="#{commentBean.comment.commentText}"
size="20" /></td>
</tr>
<tr>
<td></td>
<td><h:commandButton id="update"
action="#{commentBean.addComment(searchBean.companyId)}" class="myButton2" value="Add Comment" >
<f:ajax execute="#form" render=":results"/>
</h:commandButton></td>
</tr>
</table>
</h:form>
<h:form id="results">
<table>
<tr>
<td>
<h:dataTable value="#{commentBean.viewComments(searchBean.companyId)}" var="c">
<h:column>
<div class="commentsbox">#{c.commentText}</div>
</h:column>
<h:column>
<div class="boldfont">#{c.commentdate}</div>
</h:column>
<td><h:column>
<div class="commentname">#{c.commentname}</div>
</h:column>
</td>
</h:dataTable>
</td>
</tr>
</table>
In your view :
<f:ajax execute="#this" render=":results, username, comment"/>
In your backing bean, in the addComment() method :
comment.setCommentname(null);
comment.setCommentText(null);
or simply (I guess only)
comment = null;

Horizontal display of a list of p:graphicImage and their titles in ui:repeat

I 'm using the tag ui:repeat to display a list of pictures and their titles.
My code is:
<p:dialog id="idSchemaDlg5" widgetVar="schemaDlg" position="10" resizable="true" modal="true" header="Schéma des composants">
<h:panelGrid columns="1">
<ui:repeat value="#{imageStreamer.pictureNamesList}" var="imageName" >
<h:panelGrid columns="#{imageStreamer.pictureNamesList.size()}">
<p:graphicImage value="#{imageStreamer.image}" >
<f:param name="pictureName" value="#{imageName}" />
</p:graphicImage>
<h:outputText value="#{imageName}"/>
</ui:repeat>
</h:panelGrid>
</p:dialog>
I would to display the list of pictures horizontally but the list of pictures with this code was vertically displayed.
Any help is welcome.
I would to have this structure in output <table><tbody><tr><td><img1/><title1/></td><td><img2/><title2/></td><img3/><titl‌​e3/><td></td></tr></table>
The <ui:repeat> inside <h:panelGrid> won't generate physically multiple table cells. It will generate only one table cell. In fact, each immediate child UI component of <h:panelGrid> counts as a single table cell. The <ui:repeat> is an UI component.
You need <c:forEach> instead. It's a taghandler and runs during building JSF component tree instead of during generating HTML output. It generates physically multiple JSF components, in contrary to <ui:repeat> which represents physically one JSF component which is reused everytime during generating HTML output.
<h:panelGrid columns="#{imageStreamer.pictureNamesList.size()}">
<c:forEach items="#{imageStreamer.pictureNamesList}" var="imageName">
<h:panelGroup>
<p:graphicImage value="#{imageStreamer.image}">
<f:param name="pictureName" value="#{imageName}" />
</p:graphicImage>
<h:outputText value="#{imageName}"/>
</h:panelGroup>
</c:forEach>
</h:panelGrid>
(note that you need to wrap the image and the text in a <h:panelGroup> to represent a single table cell)
Or, if you insist in using <ui:repeat>, then you have to write down the desired HTML output yourself.
<table>
<tbody>
<tr>
<ui:repeat value="#{imageStreamer.pictureNamesList}" var="imageName">
<td>
<p:graphicImage value="#{imageStreamer.image}">
<f:param name="pictureName" value="#{imageName}" />
</p:graphicImage>
<h:outputText value="#{imageName}"/>
</td>
</ui:repeat>
</tr>
</tbody>
</table>
See also:
JSTL in JSF2 Facelets... makes sense?
create table columns dynamically in JSF
you must change the order of the h:panelGrid and p:graphicImage. because you repeat the creation of the h:panelGrid with size() as number of columns. your code becomes:
<p:dialog id="idSchemaDlg5" widgetVar="schemaDlg" position="10" resizable="true" modal="true" header="Schéma des composants">
<h:panelGrid columns="#{imageStreamer.pictureNamesList.size()}">
<ui:repeat value="#{imageStreamer.pictureNamesList}" var="imageName" >
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td> <p:graphicImage value="#{imageStreamer.image}" >
<f:param name="pictureName" value="#{imageName}" />
</p:graphicImage>
</td>
</tr>
<tr>
<td ><h:outputText value="#{imageName}"/></td>
</tr>
</table>
</ui:repeat>
</h:panelGrid>
</p:dialog>

How to rewrite JSF h:table into h:panelGrid

I need a way to create editable table like this. I interested is it possible to use h:panelGrid to display and edit the data. From my previews post I saw that it's possible to simple JSF table, but is this possible with h:panelGrid?
<table>
<ui:repeat var="elem" value="#{yourMB.yourDataList}">
<tr>
<td>#{elem.userid}</td>
<td>
<h:outputText value="#{elem.name}"
rendered="#{not elem.editable}" />
<h:inputText value="#{elem.name}" rendered="#{elem.editable}" />
</td>
<td>
<h:outputText value="#{elem.telephone}"
rendered="#{not elem.editable}" />
<h:inputText value="#{elem.telephone}"
rendered="#{elem.editable}" />
</td>
<td>
<h:commandLink value="Edit" rendered="#{not elem.editable}"
action="#{yourMB.editAction(elem)}" />
</td>
</tr>
</ui:repeat>
</table>
<h:commandButton value="Save Changes" action="#{yourMB.saveAction}" />
The answer is "NO". Try to use h:dataTable instead of h:panelGrid.

Primefaces galleria not displaying after adding captcha to the xhtml

On my page galleria was working fine before adding captcha to the code.
After adding captcha to the code galleria is not displaying on page.
I tried to keep both captcha on different form but still it is not working.
Captcha is working fine.
I've no idea what is problem with this.
<h:form id="frmTest">
<center >
<br/><br/>
<table width="70%" border="0">
<tr>
<td width="70%" align="center">
<p:panel >
<p:galleria value="#{LoginBean.imgList}"
var="image" effect="slide"
effectSpeed="1000"
panelWidth="500" panelHeight="300"
frameWidth="100" frameHeight="70"
rendered="true">
<p:graphicImage value="../resources/images/{image}"/>
</p:galleria>
</p:panel>
</td>
<td width="30%">
<p:panel>
<p:commandButton id="btnShowCaptcha"
process="#form"
onclick="captchaDlgWar.show()"
value="Show Captcha"/>
</p:panel>
</td>
</tr>
</table>
</center>
<p:dialog widgetVar="captchaDlgWar" id="capchaDlgId"
hideEffect="explode" showEffect="clip"
modal="true" closable="true" resizable="false"
header="Prove you are human..." width="360" height="190">
<h:panelGrid columns="1">
<p:captcha label="Captcha"
id="captchaId"
language="tr"
required="true"/>
<p:commandButton id="btnContinue"
ajax="false"
value="Continue"
action="#{MyBean.onContinueAction}"/>
</h:panelGrid>
</p:dialog>
</h:form>
MyBean
public String onContinueAction() {
RequestContext.getCurrentInstance().execute("captchaDlgWar.hide()");
return "somePage.xhtml";
}
Thnx.
try taking your dialog outside of your form and add another form inside your dialog
so you'll have one dialog with galeria inside and another dialog inside your dialog make sure you don't nest forms
<h:form.... <p:galleria...</h:form>
and
<p:dialog><h:form.... <p:captcha ...</h:form></p:dialog>
Also
I'd try to use p:panelGrid Primefaces PanelGrid instead of the table

What is label's 'for' id for selectBooleanCheckbox

How to reference each individual checkbox in the outputLabel so that when I click on item's label, it would effectively be the same as if I clicked on the checkbox?
<rich:dataGrid value="#{all}" var="item" columns="3">
<h:outputLabel value="#{item.name}" for="what_here?" />
<h:selectBooleanCheckbox value="#{item.selectedForLaterUse}" id="item#{item.id}" />
</rich:dataGrid>
A possibility that comes first to mind is of course
for="item#{item.id}"
but since jsf id's are relative, it would not work, right?
There is also one option to use selectManyCheckbox but that doesn't seem to give an option to use columns.
You do not need to do it. JSF does it for you. Just specify a fixed ID as long as it's in the same scope.
<rich:dataGrid value="#{all}" var="item" columns="3">
<h:outputLabel value="#{item.name}" for="item" />
<h:selectBooleanCheckbox value="#{item.selectedForLaterUse}" id="item" />
</rich:dataGrid>
JSF will generate the proper HTML accordingly. Open page in browser, rightclick and do View Source to see it yourself. The generated HTML element IDs are in this particular case composed of all parent NamingContainer components and the current item index.
Here's an example of the generated output, assuming that you're giving all NamingContainer components a fixed ID like <h:form id="form"> and <rich:dataGrid id="grid"> (otherwise JSF will autogenerate IDs like j_idt1 and so on, which would work perfectly fine as well but is not immediately readable):
<table id="form:grid" class="rf-dg">
<tbody id="form:grid:dgb" class="rf-dg-body">
<tr class="rf-dg-r">
<td class="rf-dg-c">
<label for="form:grid:0:item">one</label>
<input id="form:grid:0:item" type="checkbox" name="form:grid:0:item" />
</td>
<td class="rf-dg-c">
<label for="form:grid:1:item">two</label>
<input id="form:grid:1:item" type="checkbox" name="form:grid:1:item" />
</td>
<td class="rf-dg-c">
<label for="form:grid:2:item">three</label>
<input id="form:grid:2:item" type="checkbox" name="form:grid:2:item" />
</td>
</tr>
</tbody>
</table>

Resources