Exploring methods to iterate through information in a Java enumeration and display it within a VueJS component

Is it possible to display report data stored in a Java enum using Vue CLI?

enumExample.java

public enum DefaultFormatE {
    Report001    ("Report001",    "HTML",   "ReportName001"),
    Report002    ("Report002",    "PDF",    "ReportName002"),
    Report003    ("Report003",    "XLS",    "ReportName003");

    DefaultFormatE(String reportId, String defaultFormat, String reportName){
        this.reportId = reportId;
        this.defaultFormat = defaultFormat;
        this.reportName = reportName;
    }

    public static String FORMAT_PDF = "PDF";
    public static String FORMAT_EXCEL = "XLS";

    private String reportId;
    private String defaultFormat; 
    private String reportName;

    public String getReportId() {
        return reportId;
    }

    public void setReportId(String reportId) {
        this.reportId = reportId;
    }

    public String getDefaultFormat() {
        return defaultFormat;
    }

    public void setDefaultFormat(String defaultFormat) {
        this.defaultFormat = defaultFormat;
    }

    public String getReportName() {
        return reportName;
    }

    public void setReportName(String reportName) {
        this.reportName = reportName;
    }

     public static String getFileFormat(String reportId){
        for(DefaultFormatE s : DefaultFormatE.values()){
            if(s.getReportId().equalsIgnoreCase(reportId)){
                return s.getDefaultFormat();
            }
        }
        return null;
    }
}

Listing.vue

<template>
  <!-- Using a loop to display reports from the enum -->
</template>

<script>
import Report  from '../enum/enumExample.java';//Is this the correct way to import?

export default {

}
</script>

<style>
    
</style>

I would like to showcase all reports on my website as follows:

report id report name format
Report001 ReportName001 HTML
Report002 ReportName002 PDF
Report003 ReportName003 XLS

Answer №1

If you're using Vue, keep in mind that you won't be able to directly call a Java class. Instead, you'll need to create a rest API that can be accessed by your Vue application. This setup typically involves a Front End built with Vue and a corresponding Back End written in Java.

For more information on this process, check out this helpful video here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When the VueJS element is rendered on Chrome addon, it suddenly vanishes

I have been using a developer mode addon successfully in Chrome for quite some time. Now, I want to add a button to my Vue-powered page. Here's the code snippet: let isletCtl = document.createElement('div') isletCtl.id ...

Java if else statement for partial matching

As I navigate through Selenium WebDriver, I often come across perplexing examples. One task at hand is to read a string (succeeded) and create a conditional statement that checks for the presence of specific text. Let's consider this example. Strin ...

Is it possible to implement the splice() method within a forEach loop in Vue for mutation

Hey there! I'm looking for a more efficient way to replace objects that match a specific index with my response data. Currently, I'm attempting to use the splice() method within a forEach() loop in Vue.js. However, it seems to only remove the obj ...

Encountering a org.apache.http.conn.HttpHostConnectException error when trying to access a URL through the Eclipse

For our current project, we have integrated BrowserStack into our testing process. The portal we are testing has been whitelisted for our IP address. We are also accessing the internet behind a proxy. However, when running the following code snippet: p ...

Obtain some content using Java along with Selenium WebDriver

I only want to extract the text "Invitation sent to xxxxx". I do not need the content inside the button tag. <button class="action" data-ember-action="" data-ember-action-3995="3995"> Visualizar profile </button> This is how I am c ...

Calendars malfunctioning following the execution of npm run build

While utilizing the vue2-datepicker for a calendar, I encountered an issue during development. When clicking on the input box in my form, the calendar appeared as expected above the input. However, after running npm run build and loading up the resulting p ...

Utilizing the $set method to capture a jQuery variable and append it to a Vue array object

Currently, I am retrieving data from an API using jQuery's getJson method to extract the information. After successfully obtaining the data, my aim is to assign it to a Vue array object by making use of app.$set. Although I have managed to extract an ...

Creating a collection by compiling a selection of choices

Presently, I have a piece of code that identifies the Show id, then proceeds to locate the elements in the option tags below it and prints them out individually. WebElement dropDown = driver.findElement(By.id("Show")); List<WebElement> optio ...

Title Tooltip Capitalization in Vue.js: A Guide

Is there a way to change only the first letter of the title tooltip (from a span) to be capitalized? I attempted using CSS with text-transform: capitalize;, however, it didn't have the desired effect. <template lang="pug"> .cell-au ...

How can parameters be passed using annotations in TestNG/Webdriver/Java?

Having recently delved into the realms of Java, TestNG, and Selenium Webdriver (just 3 weeks ago), it appears that I am experiencing some challenges passing parameters as per TestNG requirements. Although the test executes flawlessly, an error message pop ...

What is the best way to bundle an Express server into an Electron application?

Currently in the process of developing an Electron app using vue-cli-electron-builder. My setup includes a local MySQL database and an Express server. I am wondering how to bundle my Express server with the Electron app? The Express server is used for d ...

Is there a way to exclusively submit form elements using Vue[2].js?

Currently, I have developed a form page that serves both creation and updating purposes. The structure of my form fields is as follows: myForm: { name: (...) email: (...) password: (...) } Successfully, I am able to make submission requests. Howev ...

Exploring the variations in method declarations within Vue.js

Today, while working with Vue, I came across an interesting observation. When initially using Vue, there were two common ways to define a method: methods: { foo: () => { //perform some action } } and methods: { foo() { / ...

Reactivity in Vue.js powered by ES6 classes

I am attempting to create a computed property in Vue.js that is associated with an ES6 class. Here is an example of my Vue instance setup: ... props: ['customClass'], computed: { localClass: { get() { return this.custom ...

The error message java.lang.NumberFormatException: Unable to parse the input string: "2017-01-28 13:28:20" occurred

During the execution of my java project, I encountered an error with a Gson deserializer function. The error message states: java.lang.NumberFormatException: For input string: "2017-01-28 13:28:20" at java.lang.NumberFormatException.forInputString(NumberF ...

Issue with redrawing pie chart positions in vue2-highcharts

For my project, I am creating a 3-pie chart using a single Highchart in a resizable container with VueJs and the vue-highcharts component. To achieve this, I need to adjust the positions and sizes of the pies whenever the container is resized. However, I a ...

Creating methods in Vue that can alter elements created during the mounted lifecycle hook can be achieved by defining functions

I am trying to implement a button that can recenter the canvas. The idea is that when the button is clicked, it will trigger the rec() method which should reposition the canvas that was created in the mounted() function. However, this setup is not working ...

Transfer data from SqLite to MySQL using PHP without the need for JSON

I'm currently attempting to transfer data from an Android SQLite database to a MySQL database. I have found several references, but my main concern is whether it's possible to achieve this without using JSON. JSON seems quite complex, and I have ...

Passing data from one Vue component to another

I am trying to transfer data from one Vue.js component to another. Below is the code I have so far: Can someone please point out where I went wrong? Your help is greatly appreciated! Thank you! ...

Compiling Vue with TypeScript: Troubleshooting common errors

Using Vue Components with Templates Multiple Times in TypeScript I am working on utilizing a component with a template multiple times within another component. The code is split between a .html file and a .ts file. The .html file structure is as follows: ...