Overview This guide walks through creating two OSGi modules in Liferay 7.4 and sharing a Java package between them using the standard API + Implementation pattern. This is the most common and correct approach for exposing reusable services in a Liferay-based architecture. In OSGi, a bundle (module) does not expose its internal packages by default — everything is private unless explicitly exported. To share code between modules, the standard practice is to split functionality into: · An API module — contains interfaces/DTOs and exports the package · A Service (Implementation) module — implements the interface, imports the package, and registers the implementation as an OSGi component/service The consuming module then simply imports the API package and looks up the service using @Reference injection. Step 1: Create the API Module Using Liferay Workspace + Blade CLI, generate a new API module: blade create -t api -p com.sgc.greeting greeting-api This generates a Gradle module unde...
Crud Operation on Vaadin portlet
Lets connect vaadin portlet with mysql database :put poretal-ext.properties file under class file with following code
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost:3306/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=root
// this code will write under
public class DemoVaadinApplication extends Application {
String dbUrl = "jdbc:mysql:///lportal";
String dbClass = "com.mysql.jdbc.Driver";
Connection con = DriverManager.getConnection(dbUrl, "root","root");
How to insert data into mysql database table
Here are complete code for inserting data into vadin table
public class DemoVaadinApplication extends Application {
String dbtime;
String dbUrl = "jdbc:mysql:///lportal";
String dbClass = "com.mysql.jdbc.Driver";
@Override
public void init() {
final Window window = new Window();
final TextBox md=new TextBox(“Name”);
final TextBox name=new TextBox(“Fname”);
public void buttonClick(ClickEvent event) {
try {
String valu=(String)md.getValue();
String valu1=(String)name.getValue();
try {
Connection con1 = DriverManager.getConnection(dbUrl, "root","root");
System.out.println("Hi this is insert query:");
Statement st=con1.createStatement();
String mda="insert into vadin(name,fname)values('"+valu+"','"+valu1+"')";
int i=st.executeUpdate(mda);
if(i!=0)
{
System.out.println("Data is inserted");
}
else
{
System.out.println("Faile");
}
//qcSQL1.close();
}
catch(SQLException e) {
e.printStackTrace();
}
System.out.println("Click event value"+valu);
} catch (Exception e) {
// Ignored, we'll let the Form handle the errors
}
}
});
window.addComponent(save);
}
}
Comments
Post a Comment