Vaadin Table: no components in table - java

In my table I render rows contains components. After loading data source to table sometimes there are empty fields (components aren't visible, text - yes). I have not any exceptions.
This happens when I scrolling table content. After refreshing table data source everything is ok.
What's wrong?
In attachement there is an example.

I found solution. I think so that might be an bug.
INVALID SOLUTION:
Load data to table
Scroll table with data to eg. 50% of table content
Load new data to table
Table doesn't display all components
CORRECT SOLUTION:
Load data to table
Scroll table with data to eg. 50% of table content
Scroll table to top, to the first table item
Load new data to table
Table display all components
In Vaadin 7.4.1 there is that same bug. Maybe recreating table should help?
OK. Now it works. This is temporary solution. I re-create table and load data to new table:
private void createTable() {
pzbs = (FilterTable) buildTable();
h.addComponent(pzbs);
h.setExpandRatio(pzbs, 1.0f);
}
private void recreateTable() {
h.removeComponent(pzbs);
createTable();
}
private Component buildRoutes() {
routes = new ListSelect() {
{
setNullSelectionAllowed(false);
setSizeUndefined();
setWidth(100.0f, Sizeable.Unit.PERCENTAGE);
setHeight(100.0f, Sizeable.Unit.PERCENTAGE);
setImmediate(true);
}
};
routes.addValueChangeListener((Property.ValueChangeEvent event) -> {
if (routes.getValue() != null) {
recreateTable();
countAndUpdatePercentage(countCorrectReadouts());
sendedToPSG.select(null);
selectedRoute = (KTREntity) routes.getValue();
updateTable();
}
});
return routes;
}

Related

"No explicit selection and an implicit one could not be determined" error for my JPA request

I have three SQL tables
The "Accedant" table that has an idAccedant
The "Emetteur" table that has an idEmetteur and a foreign key towards the Accedant table
The "Asso_Etab_Emet" table which is an assocation table between a table called "Etablissement" and the "Emetteur" table.
So the "Asso_Etab_Emet" table has two foreign keys, one towards the Etablissement table and one toward the Emetteur table
I want to build a
Specification<Etablissement>
with the idAccedant as input data, to get, at the end, the list of all the Etablissement linked to an Emetteur :
Page<Etablissement> etablissementsPage = etablissementDao.findAll(specEtab, configPage);
My code that aims at building the Specification is the following
#Override
public Specification<Etablissement> findActifByExploitantSpec(Long idAccedant) {
return ((root, query, builder) -> {
Subquery<Emetteur> emetteurSubquery = query.subquery(Emetteur.class);
Root<Emetteur> emetteurRoot = emetteurSubquery.from(Emetteur.class);
emetteurSubquery
= emetteurSubquery.where(builder.equal(emetteurRoot.get(Emetteur_.accedant).get(Accedant_.id), idAccedant));
Subquery<Etablissement> etablissementSubquery = query.subquery(Etablissement.class);
Root<Etablissement> etablissementRoot = etablissementSubquery.from(Etablissement.class);
Root<EtablissementEmetteur> etablissementEmetteurRoot = etablissementSubquery.from(EtablissementEmetteur.class);
etablissementSubquery
= etablissementSubquery.select(etablissementEmetteurRoot.get(EtablissementEmetteur_.etablissement));
etablissementSubquery = etablissementSubquery.where(
builder.in(etablissementEmetteurRoot.get(EtablissementEmetteur_.emetteur)).value(emetteurSubquery));
return builder.in(root).value(etablissementSubquery);
});
}
I have a
"No explicit selection and an implicit one could not be determined" error
when testing via my Angular webapp

Transactions Rollback issue in Spring

Facing an issue while rollback saving data.
Problem:
In my java method there are three saving actions. Data save to different table. I want when a saving fails then all saved transaction will be rollback.
Example, there are three tables consist of master table and sub table. All table save in a method. APVoucherEntryDetails is the child table, when it saves fail then upper transactions should be rollback.
How can I do it ?
Thanks in advance
#Override
public ApiResponse saveVoucher(APVoucherBatch batch) {
APVoucherBatch savedBatch = voucherBatchRepo.save(batch); //table 1
//==========save entry=============
List<APVoucherEntry> entryList = batch.getEntryList();
for(APVoucherEntry info: entryList){
info.setVoucherBatch(savedBatch);
info.setBatchNo(savedBatch.getBatchNo());
APVoucherEntry savedEntry = entryRepo.save(info); //table 2
//==========save detail=============
List<APVoucherEntryDetails> detailsList = info.getDetailsList();
for(APVoucherEntryDetails dtl: detailsList){
dtl.setBatchList(savedBatch);
dtl.setEntryInfo(savedEntry);
detailsRepo.save(dtl); //table 3
}
}
return new ApiResponse();
}

Getting selected item from an ADF SelectOneChoice in managed bean

I am currently reworking an ADF Fusion Web application using Jdev v12.2.1.4.0 (Oracle 12c).
On one of the jsf pages I have a SelectOneChoice inside a table column. The jsf-implementation looks like this:
<af:column
headerText="#{ManagedBean.column5HeaderText}"
sortable="false"
visible="true"
id="c5">
<af:selectOneChoice
binding="#{ManagedBean.bindingErrorCaseSelectOneChoice}"
label="error case"
unselectedLabel="---"
autoSubmit="true"
id="soc1">
<f:selectItems value="#{ManagedBean.errorCases}" id="si1"/>
</af:selectOneChoice>
</af:column>
I left out the required attribute because it is not necessary for the process to select a value here.
The coherent parts of my ManagedBean.java are as following:
//declaring
private RichSelectOneChoice bindingErrorCasesSelectOneChoice;
private List<SelectItem> errorCases = new ArrayList<SelectItem>();
//...
//populating errorCases List from a database
public void getErrorCasesFromDB() {
errorCases= new ArrayList<SelectItem>();
try {
//HC is a helper class to connect to a specific database
Conection conn = HC.getConn();
PreparedStatement pstmt = conn.prepareStatement("some SQL");
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
errorCases.add(new SelectItem("i"+ rs.getRow(), rs.getString(1)));
}
conn.close();
} catch(Exception e) {
e.printStackTrace();
}
}
As I run the jsf page the SelectOneChoices inside the table get rendered and all the expected items are enlisted. I am facing a problem whenever i try to access the selected item of the SelectOneChoice.
I want to read the value of the selectedItem when I hit a button on the page, so I figured I could leave out having to deal with that in a valueChangeListener, and did the following in my button action:
public void buttonSaveReceivedResults(ActionEvent actionEvent) {
//...
if (bindingErrorCaseSelectOneChoice.getValue != null) {
//... insert the selected value into an SQL statement
//in the case the unselected label is selected, skip
System.out.println(bindingErrorCasesSelectOneChoice.getValue().toString())
}
}
This block always gets skipped. Also when i inspected the process, the getValue() call always returned null, even if i select an item from the list.
Now i'm asking you guys, where is the missing part in the chain? Did I do the data bindings correctly. Do I access the elements in the wrong way? Thanks in advance.
The value attribute stores the output of af:selectOneChoice component. Since you have not added it, value returned was null.

values are getting overwritten in the table -PDFbox

I want to display the set of records in rows and columns. Am getting output but the thing is, it is getting overlapped. should i modify the loop can someone pls suggest.
ArrayList<ResultRecord> Records = new ArrayList<ResultRecord>(MainRestClient.fetchResultRecords(this.savedMainLog));
for(j=0; j<Records.size(); j++)
{
Row<PDPage> row4 = table.createRow(100.0f);
Cell<PDPage> cell10 = row4.createCell(15.0f, temp.getNumber());
Cell<PDPage> cell11 = row4.createCell(45.0f, temp.getDescription());
Cell<PDPage> cell12 = row4.createCell(15.0f, temp.getStatus());
Cell<PDPage> cell13 = row4.createCell(25.0f, temp.getRemarks());
}
The below is the full code for opening a PDF file. I want to retreive set of records in the row4 in the corresponding cells. But the is over written one above the another.
Expected output:
IT should display one below the another.
Is the overlapping reason,is it because of defining the row as row4.
try {
//table.draw();
cell.setFontSize(12);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
First of all, you should clarify the table drawing library you use. PDFBox only is the underlying PDF library. Considering the classes used I would assume you are using Boxable on top of it.
Furthermore, the reason why all the tables are printed over each other is that you start each table at the same position on the same page, you use
BaseTable table = new BaseTable(yPosition, yStartNewPage,
bottomMargin, tableWidth, margin, document, page, true, drawContent);
without ever changing yPosition or page.
To get one table after the other, you have to update yPosition and page accordingly, e.g. by using the return value of table.draw() and the state of table then, i.e. by replacing
table.draw();
by
yPosition = table.draw();
page = table.getCurrentPage();

How to remove row from Different JTables with Single Remove Button

I have a Tabbed Layout in my application
Please see this Image
So as you can see in the above Image I've 2 Tables in 2-different Tabs in first tab (SALON STOCK tab)
i want to remove the selected row
what did is : removebutton's actionPerformed Method
int row_num =jTable4.getSelectedRow();
try{dtm_stock.removeRow(row_num);}
catch(ArrayIndexOutOfBoundsException e){
JOptionPane.showMessageDialog(this,"Please select a Product");
}
this works fine for the current tab(SALON TAB)
but how to implement same for the other Tab (Stock for Sale).
Further Details :
I have 2-table in the 2-diff tabs and bothe have 2-different TableModel (Default)
at initialization the data is set to null
after that the Data is retrieved from database and set to the corresponding TableModel.
now there is a remove button which will remove the selected row from table
i want to remove the selected row from tables irrespective of any Tab
CODE : initialization
jTable4 = new javax.swing.JTable();
dtm_stock = new DefaultTableModel(new Object [][] {
{null,null, null, null},
{null,null, null, null}
},
new String [] {
"ID","NAME", "PRICE", "QUANTITY"
});
jTable4.setModel(dtm_stock
);
ADDING DATA :
//-----ADD STOCK TO THE STOCK TABLE --------------//
try {
ResultSet r7 = con.createStatement().executeQuery("select * from stock");
while(r7.next()){
dtm_stock.insertRow(dtm_stock.getRowCount(),new Object[]{r7.getString("id"),r7.getString("p_name"),r7.getString("price"),r7.getString("qty")});
}
} catch (SQLException e) {
JOptionPane.showMessageDialog(this,e.toString());
}
if i'm adding the same TableModel to the other Table then the data goes to that table and the current goes blank:
this seems to have did the trick :`
int selectedIndex = jTabbedPane2.getSelectedIndex();
if(selectedIndex == 0 ){
int row_num =stock_table.getSelectedRow();
try{
dtm_stock.removeRow(row_num);
}
catch(ArrayIndexOutOfBoundsException/*|SQLException*/ e){
JOptionPane.showMessageDialog(this,"Please select a Product");
}
}//if
if(selectedIndex == 1){
int row_num =sale_Stock_table.getSelectedRow();
try{
dtm_sale_stock.removeRow(row_num);
}
catch(ArrayIndexOutOfBoundsException/*|SQLException*/ e){
JOptionPane.showMessageDialog(this,"Please select a Product");
}
}
from here :
enter link description here
if they share same model how can they have different data, please explain
You can control which columns to display in the view (JTable).
Look at the removeColumn(...) method of JTable. It removes a column from the view. However the data is still in the TableModel.
If I understand corectly you can put some flag which will hold value for current visible tab and use if statment to remove row from correct Model. On the other hand better solution would be creating some kind of controller. The controller would store active tab, and would have removeRow method. Switching tab would trigger event so controller would know from which tab delete row.

Categories

Resources