I have a TreeMap with
<c:if test="${!empty viewObjects}">
<table border="0" cellpadding="0" cellspacing="0">
<c:forEach items="${viewObjects}" var="relations">
<c:forEach items="${relations.value}" var="role" varStatus="status">
<c:set var="subcount" value="${status.count + 1 }"/>
<tr class="color<c:out value="${subcount%2}"/>">
<td>${relations.key}</td>
<td>${role.name}</td>
</tr>
</c:forEach>
</c:forEach>
</table>
</c:if>
how can i have subcount increase with only +1 for every iteration within the nested foreach?
From what I experience "status" starts over when the first foreach iterates, so that also affects the subcount, and I will not get the total iterations.
You would do it the same way as you would do in Java: by using a counter variable initialized outside of the outermost loop:
int counter = 0;
for (...) {
for (...) {
count++;
}
}
So in JSTL, it would become
<c:set var="counter" value="0"/>
<c:forEach ...>
<c:forEach ...>
<c:set var="counter" value="${counter + 1}"/>
</c:forEach>
</c:forEach>
Related
When i hit on Submit button rich popup panel is not working.Should it be outside the h:form or inside . I tried both ways but it is not working. Please help me where i am going wrong .Below is my code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:body>
<ui:composition template="/pages/layout.xhtml">
<ui:define name="heading">
<h:outputText value="Paging” </h:outputText>
</ui:define>
<ui:define name="content">
<h:panelGrid id="panel2">
<h:form id="my_form">
<table>
<tr>
<td>
<h:panelGroup id="globalmessages">
<h:message id="key1" for="key" style="color:red" showDetail="true" />
<h:message id="lock1" for="lock" errorStyle ="color:red" showDetail="true" />
</h:panelGroup>
</td>
</tr>
</table>
<table width="700px" >
<tr>
<td align="right" width="30%"><label>Files: </label></td>
<td align="left" width="70%"><h:outputText value= "Hosting file" /></td>
</tr>
<tr>
<td align="right" width="30%"><label for="lastdate">
Last Date:</label></td>
<td align="left" width="70%"><h:panelGrid id="panel1">
<h:panelGroup>
<rich:calendar id=" lastdate "
value="#{myBean.ladate}"
locale="Locale.US" popup="true" datePattern="MM/dd/yyyy"
showApplyButton="false" todayControlMode = "hidden" cellWidth="24px" cellHeight="220px"
enableManualInput = "true" converterMessage = "Entered wrong date format"
style="width:200px" required="true" requiredMessage="Last date: is required."/>
(MM/DD/YYYY)
</h:panelGroup>
</h:panelGrid>
<h:commandButton value ="getHost" action="#{mybean.hosted}" id="key" />
</td>
</tr>
<tr></tr><tr></tr><tr></tr><tr></tr>
<tr>
<td align="right" width="30%"><label>Data: </label></td>
<td align="left" width="70%"><h:inputText id="datarelated" value="#{myBean.dataExist}" style="padding-bottom: 68px; width: 165px;"/></td>
</tr>
<tr></tr><tr></tr><tr></tr>
<tr>
<td align="right">
<a4j:commandButton value ="SubmitVal" action="#{myBean.onVal}" id="lock" style="height: 25px; width: 90px;"
render="globalmessages" status="ajaxStatus"/>
</td>
</tr>
</table>
</h:form>
<a4j:status name="ajaxStatus"
onstart="#{rich:component('waitPanel')}.show('',{top:'340px', left:'450px',height:'50px', width:'350px'})"
onstop="#{rich:component('waitPanel')}.hide()" >
</a4j:status>
<rich:popupPanel id="waitPanel" style="text-align:center">
<h:form id="test">
<h:outputText value="Please wait...Calculating" style="font-weight:bold;font-size:large" />
</h:form>
</rich:popupPanel>
</h:panelGrid>
</ui:define>
</ui:composition>
</h:body>
</html>
I am adding row dynamicall on click of commandButton.
in which I have two textfield and one dropdown and last column is save.
I am able to save old data which are already in DB,
But unable to save the newly added row. actually control is not reaching to bean when I click on save commandLink.
<div>
<div class="float_right">
<p:commandButton styleClass="add_uom"
value="#{msg['uom.add.new.uom']}" process="#this"
actionListener="#{uomBean.addRow}" immediate="true"
update=":uomFormId:languageDetail">
</p:commandButton>
</div>
<div class="clear"> </div>
<div>
<h:panelGroup id="languageDetail">
<table width="100%" cellspacing="1" cellpadding="1"
border="0" class="role_detail_section">
<thead>
<tr>
<ui:repeat var="language" value="#{uomBean.languageList}">
<th>#{language.languageCode}</th>
</ui:repeat>
<th>#{msg['uom.measuremnet.type.heading']}</th>
<th>#{msg['uom.save']}</th>
<th>#{msg['uom.activate.deactivate.heading']}</th>
</tr>
</thead>
<tbody>
<ui:repeat var="uom" value="#{uomBean.uomDTOList}">
<tr>
<ui:repeat var="uomCountry" value="#{uom.uomList}">
<td><h:inputText styleClass="values"
value="#{uomCountry.languageValue}" /></td>
</ui:repeat>
<td><h:selectOneMenu
value="#{uom.measureTypeId}"
required="true"
requiredMessage="#{msg['uom.measurement.error.msg']}">
<f:selectItem itemLabel="Select" itemValue="0" />
<f:selectItems value="#{uomBean.measureList}"
var="uomtDTO"
itemLabel="#{uomtDTO.measurmentTypeValue}"
itemValue="#{uomtDTO.measurmentTypeId}" />
</h:selectOneMenu></td>
<td>
<p:commandLink value="Saving.." action="#{uomBean.testUOM()}" ></p:commandLink>
</td>
</td>
</tr>
</ui:repeat>
</tbody>
</table>
</h:panelGroup>
<h:messages globalOnly="true" />
</div>
</div>
UOMDTO is
private Country country;
private Language language;
private String uomDisplayName;
private String uomDescription;
private List<UOMDetailDTO> uomList;
private Integer measureTypeId;
and UOMDetailDTO is
private String languageName;
private String languageCode;
private String languageValue;
Would be nice to see the source of uomBean.
I can only guess, but if uomBean is request scoped, the new row has been "lost" by the time you click save and thus cannot be saved. If uomBean is view or session scoped, then I would guess that you somehow reset/reload your uomDTOList, loose the new row and get the same problem as if it was request scoped.
I am accepting data in Array and displaying it in the same screen using <h:dataTable>.
How can display contents in reverse order, i.e. show the latest entry in the first row?
Below is code can i display nonDox.non_List in reverse order
<h:body>
<h:panelGroup rendered="#{not empty dataBase}">
<h:form id="nonDoxScanForm">
<f:event listener="#{nonDox.validate_AccNo}" type="postValidate" />
<table border="0" class="InnerBox" width="55%">
<tr><th colspan="7" align="Center" class="clsTitle">Non Dox Add</th></tr>
<tr>
<td>Delivery Date</td>
<td >Consginee (F2) </td>
<td>Weight (F3)</td>
<td>SubBranch Code(F4)</td>
<td >Consignment No (F10)</td>
<td align="Center">(F12)</td>
</tr>
<tr>
<td> <p:calendar value="#{nonDox.delDate}" id="fDat" /> </td>
<td><h:inputText size="20" id="fcon" value="#{nonDox.consignee}" /> </td>
<td><h:inputText size="20" id="fweig" value="#{nonDox.weight}" >
</h:inputText> </td>
<td><h:inputText size="20" id="fsub" value="#{nonDox.subBranchCode}" >
<f:validateLength maximum="3"></f:validateLength>
</h:inputText> </td>`enter code here`
<td><h:inputText size="10" id="acno" value="#{nonDox.accNo}" onfocus="this.select()" >
</h:inputText>
</td>
<td> <h:commandButton value="Add" id="fAdd" action="#{nonDox.addAction}" onclick="return validate();" />
</td>
<td> <h:commandButton value="Save" action="#{nonDox.saveAction}" >
</h:commandButton>
</td>
</tr>
<tr>
<td colspan="7">
<h:message for="acno"/>
</td>
</tr>
</table>
<h:dataTable value="#{ nonDox.non_List}" var="o"
styleClass="order-table"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row" width="55%"
>
<h:column>
<f:facet name="header">Del Date</f:facet>
#{o.cor_Date.substring(0, 10)}
</h:column>
<h:column>
<f:facet name="header">consignee</f:facet>
#{o.consignee}
</h:column>
<h:column>
<f:facet name="header">Weight</f:facet>
#{o.weight}
</h:column>
<h:column>
<f:facet name="header">Rate</f:facet>
#{o.rate}
</h:column>
<h:column>
<f:facet name="header">subBranchCode</f:facet>
#{o.subBranchCode}
</h:column>
<h:column>
<f:facet name="header" >POD No</f:facet>
#{o.accNo}
</h:column>
<h:column>
<f:facet name="header">Action</f:facet>
<h:commandLink value="Delete" action="#{nonDox.deleteAction(o)}" />
</h:column>
</h:dataTable>
</h:form>
<h:panelGroup >
<h:panelGroup rendered="#{empty dataBase}">
<h1>Session Expired</h1>
<h:link outcome="Login" target="CommonContent" >Login</h:link>
</h:panelGroup>
</h:body>
If you're using an List as in new ArrayList<Item>(), it's easy: use Collections#reverse():
private List<Item> data;
#PostConstruct
public void init() {
data = service.list();
Collections.reverse(data);
}
// ...
Just reference it in <h:dataTable value="#{bean.data}"> the usual way.
If you're using an array as in Item[], then you'd need to convert it to List first with help of Arrays#asList(), so that you can feed it to Collections#reverse():
private List<Item> data;
#PostConstruct
public void init() {
Item[] items = service.array();
data = Arrays.asList(items);
Collections.reverse(data);
}
// ...
Or just rewrite the service method in such way that you don't need to perform this conversion step in the backing bean.
Key is, you shouldn't expect to perform this job in the view. You should just prepare the model in such way that it's exactly as what the view expects. The <h:dataTable> itself doesn't provide any facilities like that.
I have to Tab in selectoneButton as "request" and "archive". In that tab I have information that is called with ajax. In that information I need to have a button As "acceptCommonButton" and "noNowCommonButton" so when a User clicks on the "acceptCommonButton" button it calls the "acceptRequest" method. When a user Clicks on "noNowCommonButton" button it calls to "notNowRequest" method.
My problem is that the Button Works until the last request is in "archive" Tab. It means that when the last request is in "request" tab my Button does not work. it's too Weird!!!!
I think the problem here is caused by DataGrid.
could you please see my Code?!!
<table style="width: 100%">
<tr>
<td>
<p:selectOneButton value="#{inviteRequestManagedBean.filterType}">
<f:selectItem itemLabel="#{inviteRequest_msg.request}" itemValue="request"/>
<f:selectItem itemLabel="#{inviteRequest_msg.archive}" itemValue="archive" />
<f:ajax event="change" render="requestDataGrid" />
</p:selectOneButton>
</td>
</tr>
<tr>
<td>
<p:dataGrid id="requestDataGrid" var="tBusinessPartnerRequestInfo"
value="#{inviteRequestManagedBean.filterBusinessRequest()}" columns="1" rows="22" >
<p:column>
<div>
<table border="0" width="100%">
<tr>
<td>
<p:graphicImage value="#{tBusinessPartnerRequestInfo.partySender_imageUrl}"/>
</td>
<td>
<div>
<table border="0" width="100%">
<tr>
<td>
<h:outputLabel value="#{tBusinessPartnerRequestInfo.requestDate}"/>
</td>
</tr>
<tr>
<td>
<h:outputLabel value="#{tBusinessPartnerRequestInfo.partySender_fullName}"/>
</td>
</tr>
</table>
</div>
</td>
<td>
<p:commandButton id="acceptCommonButton" value="#{inviteRequest_msg.accept}"
actionListener="#{inviteRequestManagedBean.acceptRequest(tBusinessPartnerRequestInfo.id)}"
update="#form" process="#form">
</p:commandButton>
</td>
<td>
<p:commandButton id="noNowCommonButton" value="#{inviteRequest_msg.notnow}"
actionListener="#{inviteRequestManagedBean.notNowRequest(tBusinessPartnerRequestInfo.id)}"
update="#form" process="#form">
</p:commandButton>
</td>
<td>
<p:panel>
<p:ajaxStatus>
<f:facet name="start">
<p:graphicImage value="../resources/img/loading.gif"/>
</f:facet>
<f:facet name="complete">
<h:outputLabel value=""/>
</f:facet>
</p:ajaxStatus>
</p:panel>
</td>
</tr>
</table>
</div>
<hr/>
</p:column>
</p:dataGrid>
<p:panel>
</p:panel>
</td>
</tr>
</table>
How can i make the success message display out? I have the following code, but only the warning message appear. What do i have to change so that the success message will be display out in my success page ?
userbean.java :
public String Login() throws Exception {
String status = "failure";
current=userBo.validateUser(getLogin(),getPass());
if(current!=null){ exist=false; status = "success";
String message = "submitted successfully !!";
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(message)); }
exist=true; return status; }
login.xhtml :
<f:view>
<h:form>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th>Username</th>
<td><h:inputText value="#{user.login}"
styleClass="login-inp" /></td>
</tr>
<tr>
<th>Password</th>
<td><h:inputSecret value="#{user.pass}"
onfocus="this.value=''" styleClass="login-inp" /></td>
</tr>
<tr>
<th></th>
<!-- <td><input type="button" class="submit-login" /> -->
<td><h:commandButton action="#{user.checkUser}" styleClass="submit-login" />
<h:messages globalOnly="true" />
</td>
</tr>
</table>
</h:form>
</f:view>
success.xhtml :
<h:form>
<h:body>
<h1>heyyyy ,y sucseded !!!</h1> <br/><br/>
<h:commandLink action ="#{user.logout}" > disconnect </h:commandLink>
</h:body>
</h:form>
warning message :
Infos: WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=null[severity=(INFO 0), summary=(submitted successfully !!), detail=(submitted successfully !!)]
Your <h:messages globalOnly="true" /> is been placed in the wrong view. You placed it in login.xhtml, but you're navigating to success.xhtml on success instead of returning to login.xhtml. If you put the <h:messages globalOnly="true" /> in success.xhtml, then it will be displayed the way you expected.
on your action method i.e. action="#{user.checkUser}" return a string that string will decide which page to show using your faces-config.xml file.
eg.
< navigation-rule>
< from-view-id>*< /from-view-id>
< navigation-case>
<from-outcome>ReturnedString</from-outcome>
<to-view-id>success.xhtml(path of your file)</to-view-id>
<redirect/>
</navigation-case>
< /navigation-rule>
this will definately work.