PRIMEFACES: What java code can be run in XHTML files in PRIMEFACES

UI Components for JSF
Post Reply
Ben11
Posts: 1
Joined: 12 Jan 2022, 07:19

12 Jan 2022, 07:26

Traditionally,all the java methods in XHTML code in Primefaces is of the form

Code: Select all

<p:commandButton action="#{bean.variable}">
Is there another way to call java methods in XHTML code like

Code: Select all

<p:commandButton action="#{bean.method()}">
I need to run the class below. I can use but unsure how the method will be called even if i place a PostConstruct on public void build(); Something is missing and i dont know how to fix it.

Code: Select all

 public class SimpleReport_Step01 {

    public SimpleReport_Step01() {
        build();
}

private void build() {  
    try {
        report()//create new report design
          .columns(//add columns
            //            title,     field name     data type
            col.column("Item",       "item",      type.stringType()),
            col.column("Quantity",   "quantity",  type.integerType()),
            col.column("Unit price", "unitprice", type.bigDecimalType()))
          .title(cmp.text("Getting started"),cmp.horizontalList().add(
                      
                      cmp.hListCell(projectOverview()),
                      cmp.hListCell(projectStatus())       
                      ))//shows report title
          .pageFooter(cmp.pageXofY())//shows number of page at page footer
          .setDataSource(createDataSource())//set datasource
          .show();//create and show report
    } catch (DRException e) {
        e.printStackTrace();
    }
}
    
    private ComponentBuilder<?, ?> projectOverview(){
        HorizontalListBuilder hlb = cmp.horizontalList();
        hlb.add(cmp.text("max")).newRow();
        hlb.add(cmp.text("con")).newRow();
        hlb.add(cmp.text("fex")).newRow();
           return cmp.verticalList(cmp.text("PROJECT OVERVIEW"),hlb);}
    
     private ComponentBuilder<?, ?> projectStatus(){
        HorizontalListBuilder hlb = cmp.horizontalList();
        hlb.add(cmp.text("")).newRow();
        hlb.add(cmp.text("")).newRow();
        hlb.add(cmp.text("")).newRow();
           return cmp.verticalList(cmp.text("PROJECT STATUS"),hlb);}

private JRDataSource createDataSource() {
    DRDataSource dataSource = new DRDataSource("item", "quantity", "unitprice");
    dataSource.add("Notebook", 1, new BigDecimal(500));
    dataSource.add("DVD", 5, new BigDecimal(30));
    dataSource.add("DVD", 1, new BigDecimal(28));
    dataSource.add("DVD", 5, new BigDecimal(32));
    dataSource.add("Book", 3, new BigDecimal(11));
    dataSource.add("Book", 1, new BigDecimal(15));
    dataSource.add("Book", 5, new BigDecimal(10));
    dataSource.add("Book", 8, new BigDecimal(9));
    return dataSource;
}
}
I know this is a swing app and probably i can change it to run on the browser by using the usual jasper methods used.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 37 guests