JSTL ForEach Loop/ Array or List - foreach

I needed to loop through items but I am also looking for a way to get the next or previous element in the items list so that as you can see below, I can check if the second item starts with the first item. Is there a way I can store the elements like in List or Array?
<c:forEach var="item" items="${entry.value.options}">
<c:set var="upper" value="${item.key }"/>
<c:choose>
<c:when test="${fn:startsWith(item, upper)}">
<c:if test="${item ne upper} }">
<ul>
<li>
<input class="parent" type="checkbox" name="criterias[${entry.key}]" value="${item.key}" />
<label>${item.value}</label>
</li>
</ul>
</c:if>
</c:when>
<c:otherwise>
<li>
<input class="child" type="checkbox" name="criterias[${entry.key}]" value="${item.key}" />
<label>${item.value}</label>
</li>
</c:otherwise>
</c:choose>
</c:forEach>
Thanks a lot!

You can pass to jsp a structure like List<Item> list where Item has own ArrayList and then use inner forEach. It could be easier than having flat structure.
<c:forEach var="item" items="${list}">
Access here item if needed <c:out value="${item.value}"/>
<c:forEach var="elem" items="${item}">
...
Access here elem <c:out value="${elem.value}"/>
...
</c:forEach>
</c:forEach>

Related

Updating primefaces dialog content from javascript

Now we put a couple of primefaces dialogs in datatable rows. This worked so far, but I want to move them out of the datatable.
Because there is always only one instance shown to the user of a particular dialog, I thought of updating it's values via Javascript before popping it up to the user. This would be the case for simple dialogs that only contain a couple of components and the information is already available on the client side.
What it used to be so far. (It's in HTML, not JSF, because I don't have the JSF code right now)
<table>
<tr>
<td>
<a onClick="show('dialog');" />
<div id='dialog'> <!-- the dialog -->
<input type="text" name="field" value="value" />
</div>
</td>
</tr>
</table>
e.g. what I want to achieve:
<table>
<tr>
<td>
<a onClick="updateDialog('dialog',{'field', 'value'}); show('dialog');" />
</td>
</tr>
</table>
<div id='dialog'> <!-- the dialog -->
<input type="text" name="field" value="value" />
</div>
Do you think it's feasible, or do you think there is already similar solutions out there in the wild? THanks.
Sounds like you want something like this... just make sure, the bean you store the instance to edit in survives the request. Make sure to read about partial processing and partial rendering in the PrimeFaces documentation which you can download for free: http://www.primefaces.org/documentation
<h:form id="tableForm">
<p:datatable value="#{carBean.cars}" var="car" ...>
<p:column>
<p:commandButton value="edit" action="#{carBean.edit(car)}" process="#this" update=":editForm" oncomplete="PF('carDialog').show();"/>
</p:column>
...
</p:datatable>
</h:form>
<h:form id="editForm">
<p:dialog widgetVar="carDialog" rendered="#{carBean.carToEdit ne null}">
<p:inputText value="#{carBean.carToEdit.brand" placeholder="brand" ... />
...
</p:dialog>
</h:form>

Displaytag in struts2 checked columns dissappear when changing pages

i have this problem with displaytag...when i check some rows in the table and after go in another page for checking others the checked elements of the previous page disappear.
If i return to the previous page all the rows are unchecked...this is my code:
<%#taglib prefix="s" uri="/struts-tags" %>
<%#taglib prefix="display" uri="http://displaytag.sf.net" %>
…
<s:form action="actionSample" theme="simple">
<display:table
id="row"
name="tableSample"
requestURI="/sample"
sort="list"
pagesize="10"
cellpadding="0"
cellspacing="0"
>
<display:column property="one" title="ONE" sortable="true" />
<display:column property="two" title="TWO" sortable="true" />
<display:column headerClass="sortheader" title="SELECTION" style="text-align:center;">
<s:checkbox theme="simple" name="check" fieldValue='%{#attr.row.idOne}' />
</display:column>
</display:table>
<div>
<br>
</div>
<div align="right">
<s:submit type="button" label="SUBMIT"/>
</div>
How can i resolve this problem?, thank you for the answer...
P.S. i omitted the code of the action class, there is an array of string named "check" that stores the ids of the element selected

PrimeFaces : Block Ui not working

Hi i am working with js2+ primefaces here is my code to block UI
<table>
<h:form id="main">
<tr>
<p:growl --->
---
<p:dashboard id="board" model="#{adminD.userProfl}" disabled="true">
<p:panel id="adminActivity" header="Admin Activities">
<table id="hor-minimalist-b" >
<tbody>
<tr>
<td>
<h:commandLink action="#{photoValidation.ooDirectory()}" name="submit" type="submit" id="convertPhotos">
<h:outputText value="Convert All Photos in Databse "/>
<f:ajax execute=":main:adminActivity" render=":main:growl"/>
</h:commandLink>
</td>
</tr>
</tbody>
</table>
</p:panel>
</p:dashboard>
<p:blockUI block=":main:board" trigger=":main:convertPhotos">
LOADING<br />
<p:graphicImage value="#{facesContext.externalContext.requestContextPath}/resources/images/ajax-loader.gif"/>
</p:blockUI>
here board is dashboard id main is form id
also implemented managed bean with thread.sleep of 5 seconds
Remove all the :main: prefixes , since all this resides inside the same h:form , there no need to add that main prefix
Use
<p:blockUI block="board" trigger="convertPhotos">
Try changing h:commandLink to p:commandLink:
<p:commandLink actionListener="#{photoValidation.ooDirectory()}" update=":main:growl" id="convertPhotos"><h:outputText value="Convert All Photos in Databse "/></p:commandLink>
Can you try this code?
<p:blockUI block="board" trigger="adminActivity:convertPhotos">
It is only tipp but you can find component element by firebug or another web tool in browser.

JSF PanelGrid vs table

Whats the advantage is JSF 2 Panel grid vs an HTML table?
e.g.
<h:panelGrid columns="1">
<h:outputText value="Hello"/>
</h:panelGrid>
vs
<table>
<tr>
<td>
<h:outputText value="Hello"/>
</td>
</tr>
</table>
"h:panelGrid" tag in JSF is used to generate HTML table tags. It places JSF components in rows and columns layout. The Advantage of using it is you do not have to type all those html tags.
For example, here you have to type all these html tags in your coding,
<table>
<tbody>
<tr>
<td>
Enter a Phone number :
</td>
<td>
<h:inputText id="input1" value="#{bean.input1}"
size="20" required="true"
label="Number" >
<f:convertNumber />
</h:inputText>
</td>
<td>
<h:message for="input1" style="color:red" />
</td>
</tr>
</tbody>
</table>
but the same thing can be done using "h:panelGrid" by typing the following,
<h:panelGrid columns="3">
Enter a Phone number :
<h:inputText id="input1" value="#{bean.input1}"
size="20" required="true"
label="Number" >
<f:convertNumber />
</h:inputText>
<h:message for="input1" style="color:red" />
</h:panelGrid>
JSF doc gives more details, and panelGrid has got some limitations too.
It would be very easy to align various panels and your can have JSF form control () within the panel, without much help from UI developer.
One of the limitations with PanelGrid is : It would not be easy to apply CSS styles. You need look for alternate solutions. But with standard html tags it would be easy to apply CSS styles. JSF2 Primefaces gives themes but I could not avoid CSS styles in a real time application development.
But with PanelGrid you can use almost any JSF control that fits in the rendered html of PanelGrid.

table not showing data when uses pagintion

I have a from like this
<h:form id="logForm" prependId="false">
<div class="leftcol">
....
<h:commandButton value="Apply Filters"
action="#{exporterReview.applyFilterAction}">
</h:commandButton><br></br><br></br>
....
</div>
<div class="rightcol1" >
<p:dataTable var="exporter"
value="#{exporterReview.exporters}"
paginator="true" rows="5"
height="400" paginatorPosition="top"
emptyMessage="#{exporterReview.noExporterFound}">
<p:column>
<div style="....">
<h:graphicImage value="#{exporter.imgPath}" />
</div>
<div style="...">
<h:commandButton value="Update"
action="#{exporterReview.updateExporter}"
rendered="#{login.updateState}"
style="... ">
<f:param name="exporterid"
value="#{exporter.exporterId}" />
</h:commandButton>
</div>
<div class="arrowbuttons">
<span class="arrow"></span>
</div>
<p:spacer height="10" width="20"/>
<h:commandButton value="#{exporter.organizationName}"
action="#{exporterReview.viewExporter}"
style="...">
<f:param name="exporterid" value="#{exporter.exporterId}" />
<f:param name="disableLink" value="#{exporter.disableLink}" />
</h:commandButton>
<div style='padding-top:10px'>
<h:outputLabel value="City: " style="color: #1c6ace;"/>
<h:panelGroup rendered="#{not exporter.disableLink}">
<h:commandLink value="#{exporter.cityName}"
style="text-decoration: underline"
disabled="#{exporter.disableLink}"
onclick="openCityPopup(#{exporter.cityId});" >
</h:commandLink>
</h:panelGroup>
<h:panelGroup rendered="#{exporter.disableLink}">
<h:outputText value="#{exporter.cityName}"></h:outputText>
</h:panelGroup>
</div>
<div style='padding-top:3px'>
<h:outputLabel value="Email Address: " style="color: #1c6ace;"/>
<a href="mailto:#{exporter.emailAddress}">
<h:outputText value="#{exporter.emailAddress}"
style="..">
</h:outputText>
</a>
</div>
<div style='padding-top:3px'>
<h:outputText value="#{exporter.categoryDesc}"
escape="false" />
</div>
<div class="horizontalline"></div>
</p:column>
</p:dataTable>
</div>
</h:form>
Here is the filter method
public void applyFilterAction() {
....
//Setting whereParam so that whenever user navigate from page And return back
// the grid is populated with the previous search criteria
session.setAttribute("settingWhereParam", whereParam);
getExporterGrid();
} //end of applyFilterAction
private void getExporterGrid() {
....
exporters.add(new Exporter(Datatable values));
} //end of getExporterGrid
The problem is when i am on first page and do the search then every thing works fine. Here is the first picture.
Then if i apply search then it becomes
But if i do pagination , say go to page 4 and then apply the search then no result shows
But then nothing show
Why it is happening? What i am doing wrong ? I am using Prime faces 2.2. Its an old program.
Thank you
I'm not sure if this will work in primefaces 2.2, but in version 3+, you can specify an update attribute.
Your commandButton would look like this:
<h:commandButton value="Apply Filters" action="#{exporterReview.applyFilterAction}" update="#form">
I did it :). Actually i did a workaround. What i did, i used onClick event on my filter Button. Like
<h:commandButton id="filterButton"
value="Apply Filters"
style=""
action="#{exporterReview.applyFilterAction}"
onclick="filterButtonClick(event)" />
Now when button is clicked, then first my client side code will run. So i get all the values and then using ajax call the servlet, and save the result in session object. After that my server side code will run, and my action method invoked, in which i simple return the url of the same page.
public String applyFilterAction() {
return "Exporter_Review?faces-redirect=true";
} //end of applyFilterAction()
Now when page invoke i simply check for the result in the session. And if session object present then simply get the values from that object and shows the result. And when i leave the page i simply put null in the session against object, now default is used. Now everything is working fine :)

Resources