Want to want to do is:
On my datatable, the last column has a view, edit and delete. the View has the following method to get the row data:
public String prepareView() {
current = (TimeLoggingDetail) getItems().getRowData();
selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
return "View";
}
When view is clicked it redirects me to a page where I can view the selected values.
I want to change that into showing the values in a popup and not get redirected to a page where its displayed.
So I have tried the following:
<a4j:commandLink id="myLink" value="Action" actionListener="#{timeLoggingDetailController.prepareView}" rendered="#{item.timeLoggingId eq AdminTimeLogging.filteredId}" styleClass="auto-style5">
<rich:componentControl event="complete" target="popup" operation="show"/>
</a4j:commandLink>
If I click the button the popup does not show, when I remove the event="complete" the popup does show but with no values. If I remove the popup code completely, click on view and then add the popup code again it displays but only the old value I selected without popup code, The values that's in memory.
I have also tried:
<a4j:commandLink id="myBut" action="#{timeLoggingDetailController.prepareView}" execute="#this" value="Test" styleClass="auto-style5" render="popup" oncomplete="#{rich:component('popup')}.show()">
</a4j:commandLink>
It also does not open the popup, I have tried using #{rich:component('popup')}.show() in numerous ways but it does not open, Should I change the method prepareView to return something specific? should I do a condition to display the popup with those values? it seems like the popup opens before the method finishes. the <a4j:commandLink/> is within the code:
<h:column>
<f:facet name="header">
<h:outputText value=" "/>
</f:facet>
<a4j:commandLink id="myBut" action="#{timeLoggingDetailController.prepareView}" execute="#this" value="Test" styleClass="auto-style5" render="popup" oncomplete="#{rich:component('popup')}.show()">
</a4j:commandLink>
<h:column/>
My popup Panel:
<h:column>
<f:facet name="header">
<h:outputText value=" "/>
</f:facet>
<a4j:commandLink id="myBut" action="#{timeLoggingDetailController.prepareView}" execute="#this" value="Test" styleClass="auto-style5" render="popup" oncomplete="#{rich:component('popup')}.show()">
</a4j:commandLink>
<rich:popupPanel id="popup" modal="true" autosized="true" resizeable="false" domElementAttachment="form">
<f:facet name="header">
<h:outputText value="TEST" />
</f:facet>
<f:facet name="controls">
<h:outputLink value="#" onclick="#{rich:component('popup')}.hide();
return false;">
Close
</h:outputLink>
</f:facet>
<h:panelGrid columns="2">
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_date}"/>
<h:outputText value="#{timeLoggingDetailController.selected.date}" title="#{bundle.ViewTimeLoggingDetailTitle_date}">
<f:convertDateTime pattern="MM/dd/yyyy" />
</h:outputText>
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_description}"/>
<h:outputText value="#{timeLoggingDetailController.selected.description}" title="#{bundle.ViewTimeLoggingDetailTitle_description}"/>
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_normalHours}"/>
<h:outputText value="#{timeLoggingDetailController.selected.normalHours}" title="#{bundle.ViewTimeLoggingDetailTitle_normalHours}"/>
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_overtimeHours}"/>
<h:outputText value="#{timeLoggingDetailController.selected.overtimeHours}" title="#{bundle.ViewTimeLoggingDetailTitle_overtimeHours}"/>
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_doubleTimeHours}"/>
<h:outputText value="#{timeLoggingDetailController.selected.doubleTimeHours}" title="#{bundle.ViewTimeLoggingDetailTitle_doubleTimeHours}"/>
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_approvalLevelsId}"/>
<h:outputText value="#{timeLoggingDetailController.selected.approvalLevelsId}" title="#{bundle.ViewTimeLoggingDetailTitle_approvalLevelsId}"/>
</h:panelGrid>value="#{approvalLevelsController.selected.description}" title="#{bundle.ViewApprovalLevelsTitle_description}"/>
<br />
<h:panelGrid class="auto-style4">
<h:commandLink action="#{timeLoggingDetailController.update}" value="#{bundle.EditTimeLoggingDetailSaveLink}" onclick="#{rich:component('popup')}.hide();" styleClass="linkbutton"/>
</h:panelGrid>
</rich:popupPanel>
</h:column>
Related
In my crud application I want to select a row and then display that row data in a popup. navigating to another page works and it displays the data. when I try to display it in my popup no values are displayed. I could be wrong but I think the popup opens before the method prepareView is done.
code block:
<h:column>
<f:facet name="header">
<h:outputText value=" "/>
</f:facet>
<h:commandLink id="myLink" value="Action" action="#{timeLoggingDetailController.prepareView}" rendered="#{item.timeLoggingId eq AdminTimeLogging.filteredId}" styleClass="auto-style5">
<rich:componentControl target="popup" operation="show"/>
</h:commandLink>
</h:column>
</h:dataTable>
</h:panelGroup>
</h:form>
<rich:popupPanel id="popup" modal="false" autosized="true" resizeable="false" domElementAttachment="form">
<f:facet name="header">
<h:outputText value="Approval level" />
</f:facet>
<f:facet name="controls">
<h:outputLink value="#" onclick="#{rich:component('popup')}.hide();
return false;">
Close
</h:outputLink>
</f:facet>
<h:form id="submitForm">
<h:panelGrid columns="2">
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_date}"/>
<h:outputText value="#{timeLoggingDetailController.selected.date}" title="#{bundle.ViewTimeLoggingDetailTitle_date}">
<f:convertDateTime pattern="MM/dd/yyyy" />
</h:outputText>
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_description}"/>
<h:outputText value="#{timeLoggingDetailController.selected.description}" title="#{bundle.ViewTimeLoggingDetailTitle_description}"/>
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_normalHours}"/>
<h:outputText value="#{timeLoggingDetailController.selected.normalHours}" title="#{bundle.ViewTimeLoggingDetailTitle_normalHours}"/>
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_overtimeHours}"/>
<h:outputText value="#{timeLoggingDetailController.selected.overtimeHours}" title="#{bundle.ViewTimeLoggingDetailTitle_overtimeHours}"/>
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_doubleTimeHours}"/>
<h:outputText value="#{timeLoggingDetailController.selected.doubleTimeHours}" title="#{bundle.ViewTimeLoggingDetailTitle_doubleTimeHours}"/>
<h:outputText value="#{bundle.ViewTimeLoggingDetailLabel_approvalLevelsId}"/>
<h:outputText value="#{timeLoggingDetailController.selected.approvalLevelsId}" title="#{bundle.ViewTimeLoggingDetailTitle_approvalLevelsId}"/>
</h:panelGrid>
<br />
<h:panelGrid class="auto-style4">
<h:commandLink action="#{timeLoggingDetailController.update}" value="#{bundle.EditTimeLoggingDetailSaveLink}" onclick="#{rich:component('popup')}.hide();" styleClass="linkbutton"/>
</h:panelGrid>
</h:form>
</rich:popupPanel>
</ui:define>
</ui:composition>
</html>
You may want to use <a4j:commandLink>, it provides oncomplete event which is fired when the action completes.
This should work for you:
<a4j:commandLink id="myLink" value="Action" actionListener="#{timeLoggingDetailController.prepareView}" rendered="#{item.timeLoggingId eq AdminTimeLogging.filteredId}" styleClass="auto-style5">
<rich:componentControl event="complete" target="popup" operation="show"/>
</a4j:commandLink>
In my application, I have a h:datatable which contains vehicles data and h:selectBooleanCheckBox in each of its row. I want know the selected checkbox in the datatable datatable's row in the backing bean without applying any submit button. The idea of doing this is; when any user clicks the check boxes in one application page, s/he could easily see the selected rows in other pages aswell beacause the datatable in every page contains many vehicles. Therefore, users could be able to see the selected vehicles in any page and do the related operation.
The following shows part of my JSF page.
<rich:dataTable id="vehicleTable" var="vhcl" value="#{mainPage.vehicleList}"
binding="#{mainPage.vehicleTable}" >
<rich:column id="col_sel" width="10px"
<h:selectBooleanCheckbox title="#{general.showOnMap}" onclick="showOnMap(this)" id="selectedCheckBox" />
</rich:column>
<rich:column id="trackId" label="#{general.vehicleName}" >
<f:facet name="header">
<h:outputText value="#{general.vehicleName}" id="state_name" />
</f:facet>
<h:outputText value="#{vhcl.vehicle.mtsTrackId}" id="vehicleId" title="#{general.vehicleId}" style="font-size:10px; color:blue;" />
<br/>
<h:outputText value="#{vhcl.vehicle.vehiclePlate}" id="vehiclePlate" title="#{general.licencePlate}" style="font-size:10px; color:blue"/>
</rich:column>
<rich:column id="type_col" label="#{general.vehicleType}" >
<f:facet name="header">
<h:outputText value="#{general.vehichleType}" id="vehichleTypeLabel" />
</f:facet>
<h:graphicImage value="#{vhcl.typeImage}" height="40" width="40" align="left"/>
<h:panelGrid columns="1" align="right">
<h:graphicImage id="statusImage" value="#{vhcl.statusImage}" title="#{vhcl.status}" height="15" width="15" />
<h:graphicImage id="motorStatusImage" value="#{vhcl.motorStatusImage}" title="#{vhcl.motorStatus}" height="15" width="15" />
</h:panelGrid>
</rich:column>
<rich:column id="msg_col" label="#{general.lastMessageDate}" >
<f:facet name="header">
<h:outputText value="#{general.lastMessageDate}" id="lastMsgDateLabel" />
</f:facet>
<h:outputText value="#{vhcl.messageDate}" id="lastMsgDate" />
<br />
<h:outputText value="Hız: " />
<h:outputText value="#{vhcl.instantSpeed}" id="lastSpeed" style="color:blue; font-weight:bold" />
<h:outputText value="km/s" />
</rich:column>
<rich:column id="addr_col" label="#{general.address}" >
<f:facet name="header">
<h:outputText value="#{general.address}" id="addressLabel"/>
</f:facet>
<h:outputText value="#{vhcl.address}" id="addr" />
<br />
<h:outputText value="#{vhcl.location}" id="location" style="color:blue;" />
</rich:column>
In your Vehicle class create a Boolean field and add getter and setter methods for it like this.
private Boolean selected;
public Boolean getSelected() {
return selected;
}
public void setSelected(Boolean selected) {
this.selected = selected;
}
Then bind your checkBox to that property and add a <a4j:support> tag to the checkBox as below.
<h:selectBooleanCheckbox onclick="showOnMap(this)" value="#{vhcl.selected}">
<a4j:support event="onchange" ajaxSingle="true"/>
</h:selectBooleanCheckbox
Now when you check or uncheck the checkBox the value is submitted to the bean. Then any time you can find whether the vehicle is selected like this.
if(vehicle.selected != null && vehicle.selected) {
//vehicle is selected
}
Note: Your table should be inside a form.
<h:form>
<rich:dataTable value="#{classBean.classList}" var="class"
id="classTable" style="width: 90%" rows="10">
<f:facet name="header">
<h:outputText value="class list" style="float: left"></h:outputText>
</f:facet>
<rich:column style="width: 35px">
<h:selectBooleanCheckbox
value="#{classBean.selected[class.name]}" />
</rich:column>
<rich:column>
<f:facet name="header">
class name
</f:facet>
<h:outputText value="#{class.name}" />
</rich:column>
<f:facet name="footer">
<a4j:commandButton value="add" action="#{classBean.add}" />
<a4j:commandButton value="delete" action="#{classBean.delete}" />
</f:facet>
<rich:dataTable>
<h:form>
I have to validate such as the user should select at least one checkbox before clicking delete command button.
If I use validator it will check only checked or uncheked.... I need to check the checkbox when delete commandButton clicked
Add this code in your bean
private boolean checked;
public boolean isChecked()
{
if(selected.values().contains(true))
checked=true;
else
checked=false;
return checked;
}
use a popup panel to display error message and set the rendered attribute to #{bean.checked}
So I have the following table:
<h:dataTable id="shoppingCartTable" value="#{cartBean.shoppingCartList}" var="shoppingCartItem" width="100%" >
<h:column>
<f:facet name="header">
<h:outputText value="Item" />
</f:facet>
<h:commandLink value="#{shoppingCartItem.name}">
</h:commandLink><br/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Quantity" />
</f:facet>
<h:inputText id="quantity" value="#{shoppingCartItem.quantity}" size = "2" /><br/>
</h:column>
</h:dataTable>
With the following commandButton
<p:commandButton
value="Submit"
>
<f:ajax event="click"
execute="shoppingCartTable"
render="#all" />
</p:commandButton>
Now there is a lot of other stuff on the page and all I want to do is update the Quantity values of the shopping cart items but this does not seem to be working. Am I doing something wrong?
Try to replace f:ajax with p:commandButton attributes:
<p:commandButton value="Submit" update="#all" process="shoppingCartTable"/>
I have a form which contains a list in a datatable. To add a New record to the list, click "Add" and the dialog box <p:dialog> appears, in that any empty datatable with 2 columns having two input text boxes to fill. In the dialog box I have Save and Cancel buttons. Once we click on Save button, a new record should saved into the database and the list in the form should show with the new record. The datatable is of primefaces inline row editing functionality. I'm using growl to display the error messages. Once I update my record with empty data, it shows the required message. But when I click on the Add button, it is again showing the same required message. It is showing the previous error. I don't want to have that. Could anyone help me in this context. The "Add" is an ajax request.
<h:body>
<ui:composition template="/WEB-INF/facelets/template/adminLayout.xhtml">
<ui:define name="view">
<h:form id="myForm" prependId="false">
<div class="header" >
<div class="titleColor">
T_COD_Prefil
</div>
</div>
<div class="divPosition">
<p:dataTable var="profile" id="profileTable" value="#{profileView.profileModelList}" rowEditListener="#{profileView.rowEditListener}" onRowEditUpdate="buttonPanel" >
<p:column style="width:60px;">
<p:rowEditor/>
<h:commandButton style="padding-left:5px;" image="/resources/images/delete.jpeg" styleClass="spa" value="delete" immediate="true" actionListener="#{profileView.delete}" >
<f:attribute name="delteProfile" value="#{profile}" />
</h:commandButton>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="IDprefil" />
</f:facet>
<h:outputText value="#{profile.profileId}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="description" />
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{profile.profileDescription}" />
</f:facet>
<f:facet name="input">
<h:inputText required="true" requiredMessage="#{msg.desProfileEmpty}" maxlength="255" value="#{profile.profileDescription}" />
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</div>
<div class="divButPosition">
<h:panelGroup id="buttonPanel">
<p:commandButton id="buttons" value="Add" actionListener="#{profileView.addEmptyProfile}"
async="true" update="myForm" rendered="#{!profileView.addNewRow}" oncomplete="profileDialog.show();" />
</h:panelGroup>
</div>
<p:growl id="growl" showDetail="false" />
<p:dialog id="profileDialog" header="Profile Detail" prependId="false" widgetVar="profileDialog" resizable="false" width="500" showEffect="explode" hideEffect="explode" modal="false" closable="false">
<h:dataTable var="newProfile" value="#{profileView.newProfile}">
<h:column>
<f:facet name="header">
<h:outputText value="IDprefil" />
</f:facet>
<h:inputText value="#{newProfile.profileId}" required="true" requiredMessage="not empty" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="description" />
</f:facet>
<h:inputText value="#{newProfile.profileDescription}" required="true" requiredMessage="Desctiption should not be empty" />
</h:column>
</h:dataTable>
<p:commandButton value="Save" actionListener="#{profileView.saveProfile}" async="true" update="growl,buttonPanel,profileTable" oncomplete="handleRequest(args ,document.getElementById('profileDialog'))" />
<p:commandButton value="Cancel" immediate="true" update="buttonPanel" async="true" actionListener="#{profileView.cancelProfile}" oncomplete="profileDialog.hide();" />
</p:dialog>
</h:form>
Try writing your growl at the top of the code, and update it when clicking on the button.
Well, doesn't work on IE8.
After submit button click, all fields will be validated first so, if some of them empty then requried message will be popup. So keep submit related data under different tag. Basically different forms for different submit buttons