I have a datatable which I want to edit the value of their component by programing when the user check or uncheck one of their chceckbox
here is the datatable :
<p:dataTable var="car" style="width: 270px;margin-top: 15px;margin-left: 60px" binding="#{editCommandController.hd}" value="#{editCommandController.lp}" id="carList" editable="true">
<f:facet name="header">
Stock Papiers
</f:facet>
<p:column headerText="Libéllé" style="width:70px">
<h:outputText value="#{car.libelle}" style="width: 70px;" label="Year"/>
</p:column>
<p:column headerText="Stock" style="width:40px">
<h:outputText value="#{car.stock}" label="Year"/>
</p:column>
<p:column headerText="Choisir" style="width:40px;margin: auto;">
<p:selectBooleanCheckbox id="karim" binding="#{editCommandController.tmp}" value="#{car.checked}" disabled="#{editCommandController.result gt car.stock}" >
<p:ajax listener="#{editCommandController.checkListener}"/>
</p:selectBooleanCheckbox>
</p:column>
</p:dataTable>
and here is the managedBean :
public void checkListener(AjaxBehaviorEvent e) {
System.out.println("je suis "+e.getComponent().getClientId()+" utilisé : et tmp :" );
List<Papier> lp1;
lp1 = new ArrayList();
lp1 = (List<Papier>) getHd().getValue();
// getHd().se
System.out.println("lp1.size() : "+lp1.size());
Boolean a = true;
System.out.println("ce bool a = "+a);
for(int i = 0 ; i< lp1.size();i++){
System.out.println("alors le cheched est : "+lp1.get(i).getChecked());
if(lp1.get(i).getChecked()){
if(lastChecked != null){
for(int j = 0;j<lp1.size();j++){
if(lp1.get(j).getId().equals(lastChecked)){
lp1.get(j).setChecked(false);
break;
}
}
lastChecked = lp1.get(i).getId();
}else{
lastChecked = lp1.get(i).getId();
}
}
}
System.out.println("avant d'affecter voila ce quilya : ");
for(int i = 0 ; i< lp1.size();i++){
System.out.println("alors le cheched n "+i+" est : "+lp1.get(i).getChecked());
}
org.primefaces.component.datatable.DataTable editdt = new DataTable();
editdt.setValue(lp1);
setHd(editdt);
//getHd().setValue(lp1);
}
also in the managedBean I have :
private org.primefaces.component.datatable.DataTable hd;
public org.primefaces.component.datatable.DataTable getHd() {
return hd;
}
public void setHd(org.primefaces.component.datatable.DataTable hd) {
this.hd = hd;
}
like you see above, I use the binding attribute to link the datatable with the managedBean but when I use
org.primefaces.component.datatable.DataTable editdt = new DataTable();
editdt.setValue(lp1);
setHd(editdt);
//getHd().setValue(lp1);
I don't see my changes on the datatable
do you have any idea
thanks
You're not updating your datatable on the client side to reflect the changes you made on the server side. Refresh the datatable via ajax using update= "carList" to the ajax event.
Related
Need help to convert my following VF page into LWC
VF code:
<apex:page showHeader="true" sidebar="true" controller="OrgWideOppBidContrl">
<apex:form >
<apex:pageBlock >
<apex:pageMessages id="pagMsg"/>
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputText value="From" style="padding-top:5px;"/>
<apex:inputField value="{!opp.StartDate__c}" required="true"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputText value="To" style="padding-top:5px;"/>
<apex:inputField value="{!opp.EstimatedHarvestDate__c}" required="true"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:commandButton value="start Batch " action="{!startBatchJob}" style="margin-left:500px;" reRender="pagMsg"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex code:
public with sharing class OrgWideOppBidContrl {
public Opportunity opp{get;set;}
public OrgWideOppBidContrl(){
opp = new Opportunity();
opp.StartDate__c = Date.today();
opp.EstimatedHarvestDate__c = Date.today();
}
public PageReference startBatchJob(){
OrgWideOpportunityBidSetting__c orgwideOppBidSett = OrgWideOpportunityBidSetting__c.getInstance('OrgWideOppBid');
if(orgwideOppBidSett == null){
ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR,'OrgWideOppBid not found'));
return null;
}
if(orgwideOppBidSett.InProgress__c == true){
ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.WARNING,'Please wait Batch job for Org Wide Opportunity Bid is already in progress'));
return null;
}
String queryString = 'Select id From OrgWideMatch__c';
Database.executeBatch(new BatchExecutor(new DeleteOrgWideMatchData(), queryString, null), 1000);
ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.INFO,'Batch job for Org Wide Opportunity Bid is started successfully'));
orgwideOppBidSett.InProgress__c = true;
orgwideOppBidSett.startDate__c = opp.StartDate__c;
orgwideOppBidSett.EndDate__c = opp.EstimatedHarvestDate__c;
update orgwideOppBidSett;
return null;
}
}
I have a bunch of panels in my form which display images but i have a problem with getting the images to update(load next set of images) with a click of a button. I have tried using the ajax="false" method but this erases the all the variables in the form e.g(the urls used to load the images ) This is my button:
<div style="position : absolute; right:400px; top:1500px" >
<p:commandButton value="Confirm" id="Confirm" actionListener="#{con.confirmButton}" oncomplete="PF('panelP').hide()" ajax="false" />
</div>
The panels and Confirm button are stored in the form like:
<h:form id="form">
<p:galleria id= "ISSimage" style="position : absolute; left:50px; top:550px" value="#{con.gallery}" var="image" panelWidth="500" panelHeight="313" showCaption="true">
<p:graphicImage value="#{image}" alt="Image Description for #{image}" title="#{image}"/>
</p:galleria>
<f:view contentType="text/html">
<p:panel id="satImage" style="position : absolute; right:50px; top:550px" panelWidth="500" panelHeight="400">
<p:gmap id="satview" center="#{con.lati}, #{con.longi}" zoom="6" type="SATELLITE" style="width:600px;height:400px" model="#{con.simpleModel}" />
</p:panel>
</f:view>
I try to store a list of all the image
Is there a way to properly load the next set of images with the click of the confirm button without erasing the image variables?
MY BEAN is 300 lines so i only limited to showing the relevant parts . here it is:
public void confirmButton(ActionEvent actionEvent){
//setting Next Image
//add the point depending on which panels are open then reset the panel booelan values
gallery = new ArrayList<String>();
candidates = new ArrayList<String>();
Connection conn = null;
PreparedStatement stmt = null;
//Statement stmt1 = null;
ResultSet rs = null;
//gallery.clear();
try{
gallery = new ArrayList<String>();
conn = DriverManager.getConnection(CONN_STRING,USERNAME,PASSWORD);
stmt = conn.prepareStatement(op);
//stmt.setString(1, oldconsole);
//stmt.setString(2, oldconsole);
stmt.setDouble(1, oldlati);
stmt.executeUpdate();
stmt = conn.prepareStatement("SELECT * FROM `ISS` WHERE taskinfo__citylat = (SELECT taskinfo__citylat FROM `ISS` LIMIT ?,1)");
int rdmnum = randomise();
stmt.setInt(1, rdmnum);
rs = stmt.executeQuery();
while(rs.next()){
String issimg=rs.getString("taskinfo__link_small");
gallery.add(issimg);
//ADDS IMAGES TO GALLERIA
excl_num = rs.getInt("rownum");
excluded.add(excl_num);
//ADDS ROWNUMBERS TO EXCLUDED ARRAY SO THEY DONT GET CALLED AGAIN.
lati = rs.getFloat("taskinfo__citylat");
longi = rs.getFloat("taskinfo__citylon");
oldlati=lati;
}
catch(SQLException e){
System.err.println(e);
}
public float getLati(){
return lati;
}
public float getLongi(){
return longi;
}
public double getOldlati(){
return oldlati;
}
public double getOldlongi(){
return oldlongi;
}
I have an <input> of type text that I want to populate with a value from a database using AJAX.
First, I define my text zone like the following:
<td><input type=text id='st' value=" " name='stname' onclick="donnom();" /></td>
In javascript, I do the following:
xhr5.onreadystatechange = function(){
if(xhr5.readyState == 4 && xhr5.status == 200) {
selects5 = xhr5.responseText;
// On se sert de innerHTML pour rajouter les options a la liste
document.getElementById('st').innerHTML = selects5;
}
};
xhr5.open("POST", "ajaxIDentifier5.jsp", true);
xhr5.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
id = document.getElementById(idIdden).value;
xhr5.send("id=" + id);
In IDentifier5.jsp, I put the next code:
<%
String id = request.getParameter("id");
System.out.println("idDailyTimeSheet ajaxIDentifier5 as is:" + id);
Session s = null;
Transaction tx;
try {
s = HibernateUtil.currentSession();
tx = s.beginTransaction();
Query query = s.createQuery(
"select from Dailytimesheet dailytimesheet " +
"where dailytimesheet.IdDailyTimeSheet=" + id + " ");
for(Iterator it=query.iterate();it.hasNext();) {
if(it.hasNext()) {
Dailytimesheet object=(Dailytimesheet)it.next();
out.print( "<input type=\"text\" id=\"st1\" value=\"" +
object.getTimeFrom() +
"\" name=\"starting\" onclick=\"donnom()\" ></input>");
}
}
} catch (HibernateException e) {
e.printStackTrace();
}
%>
I want to get only the value in the input type text populated from database, because after that I will be able to change it.
Obviously, your query returns only one result (WHERE ID = ...) that you want to put in your textfield.
Strange things:
The page you are calling via AJAX is priting HTML code, but your are trying to use it as the innerHTML of a element.
It seems you want to add an input more than populating an existing one. Why has it different id/name ?
Maybe instead of :
document.getElementById('st').innerHTML = selects5;
You want to do :
document.getElementById('st').value = selects5;
But then you will need to return only the result of the query in your JSP, not HTML code :
out.print(object.getTimeFrom());
I have struts 2 checkboxlist as followed:
<s:checkboxlist list="listOfOptions" name="someName" />
I would like to add validation to make sure that at least ONE of the checkboxes has been checked. Any thoughts?
Thanks
I use JS to do that.
<sx:submit
id="button_submit"
name="button_submit"
onclick="return validateNotEmptyCheckbox();" />
And JS:
function validateNotEmptyCheckbox() {
var checkboxes = document.getElementsByTagName('input');
for (i = 0; i < arguments.length; i++) {
var fieldName = arguments[i];
var atLeastOne = false;
for (j = 0; j < checkboxes.length; j++) {
if ((checkboxes[j].type == "checkbox" || checkboxes[j].type == "radio")
&& checkboxes[j].name == fieldName
&& checkboxes[j].checked == true)
atLeastOne = true;
}
if (atLeastOne == false) {
alert("Choose one!!!");
return false;
}
}
}
Also for radio buttons, as you can see.
I made an validation method on the action to whom the form is submitted.
deliveryTimesInputList is here the list of integer with the values from the checkboxlist.
#Override
public void validate() {
if(deliveryTimesInputList == null || deliveryTimesInputList.isEmpty()){
addFieldError("deliveryTimesInputList", "Du må velge minst et leveringstidspunkt for dette postnummeret");
}
}
Use the following code for struts2 xml validation .The value of checkbox List is stored as a string.Hence,you can use requiredstring.
<field name="someName">
<field-validator type="requiredstring">
<message>You need to select at least one option</message>
</field-validator>
</field>
I have ridiculous problem with dropdownlist.Through for loop i have inserted dropdown value for Day,Month and Year. But when i am submitting the form after selecting the Day,Month and Year from Dropdownlist,the list item value is reindexing after each submitting.Ex.For Day 1 to 31,Month 1 to 12, year 1970 to 2009.After Submitting the form the list item is becoming double for each dropdownlist.Like in day dropdownlist before submiting it was 1 to 31 after submitting if i check dropdownlist the value will be two times 1 to 31 I mean 1 to 31 again 1 to 31 inside the listitem it happens for each dropdownlist.Here is my code:
aspx:
<asp:DropDownList ID="DropDownDay" runat="server">
<asp:ListItem Text="Select Day"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownMonth" runat="server">
<asp:ListItem Text="Select Month"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownYear" runat="server">
<asp:ListItem Text="Select Year"></asp:ListItem>
</asp:DropDownList>
aspx.cs:
//Inserting day in the day dropdown list.
for (int i = 1; i <=31; i++)
{
ListItem item = new ListItem();
item.Value = i.ToString();
DropDownDay.Items.Add(item.Value);
}
//Inserting month in the month dropdown list.
for (int i = 1; i <=12; i++)
{
ListItem item = new ListItem();
item.Value = i.ToString();
DropDownMonth.Items.Add(item.Value);
}
//Inserting year in the year dropdown list.
for (int i = 1970; i <=2009; i++)
{
ListItem item = new ListItem();
item.Value = i.ToString();
DropDownYear.Items.Add(item.Value);
}
string day = DropDownDay.Text;
string month = DropDownMonth.Text;
string year = DropDownYear.Text;
After adding i have set:
DropDownDay.SelectedIndex = 0;
DropDownMonth.SelectedIndex = 0;
DropDownYear.SelectedIndex = 0;
Thanks,
Sumit
you probably are not checking for Page.IsPostBack option
if it is true, then DO NOT REPOPULATE your drop down lists