Migrate Apache Tiles definition to JavaConfig - spring

I'm currently migrating my Spring project to JavaConfig. Now there is still the tiles.xml which contains the tiles definition.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<!-- Layouts -->
<definition name = "template.base" template = "/WEB-INF/views/layout/template.jsp" />
<!-- Example Controller -->
<definition name = "test" extends = "template.base" />
</tiles-definitions>
Is it possible to translate that XML configuration file to the new JavaConfig standard?

Related

Alternative to ResourceBundleViewResolver

I have a legacy jsp application with views.properties file, from which I use ResourceBundleViewResolver to load all the views. As ResourceBundleViewResolver has been deprecated from Spring 5.3, I have checked the spring documentation and it says "as of 5.3, in favor of Spring's common view resolver variants and/or custom resolver implementations". I would like to know the alternative to use the BundleViewResolver. Apologies in advance, I am very new to dealing with legacy applications.
Edit
Config.java
public class Configuration_place extends WebMvcConfigurerAdapter {
#Bean
public ResourceBundleViewResolver viewResolver(){
ResourceBundleViewResolver tilesViewResolver = new ResourceBundleViewResolver();
tilesViewResolver.setBasename("views");
return tilesViewResolver;
}
#Bean
public TilesConfigurer tilesConfigurer() {
TilesConfigurer tilesConfigurer = new TilesConfigurer();
tilesConfigurer.setDefinitions("/tiles-def.xml");
return tilesConfigurer;
}
views.properties
index.(class) = org.springframework.web.servlet.view.tiles3.TilesView
index.url = index
login.(class) = org.springframework.web.servlet.view.tiles3.TilesView
login.url = login
tiles-def.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3.0.dtd">
<tiles-definitions>
<definition name = "master.page" template = "/views/templates/layout_main.jsp">
<put-attribute name = "title" value = "JSP Application" />
<put-attribute name = "header" value = "/views/templates/header.jsp" />
<put-attribute name = "menu" value = "/views/templates/menubar.jsp" />
<put-attribute name = "error" value = "/views/templates/errorMessage.jsp" />
<put-attribute name = "content" value = "" />
<put-attribute name = "footer" value = "/views/templates/footer.jsp" />
</definition>
<definition name = "index" extends="master.page">
<put-attribute name="content" value="/views/intro.jsp" />
</definition>
<definition name = "login" extends="master.page">
<put-attribute name="content" value="/views/login.jsp" />
</definition>
</tiles-definitions>

Orbeon static autocomplete not working as expected

I'm using Orbeon v2017.1 and I'd like to add an autocomplete field with a static itemset.
I've tried implementing it as it is defined here
https://doc.orbeon.com/form-runner/component/autocomplete#static
and I've also tried creating a service and action which will fill the data, but it displays it as radio buttons instead of populating the dropdown.
Is there a working example for this version of Orbeon which I could look at?
EDIT:
Here is an example of two autocomplete fields (dynamic and static)
I'm not sure if the used free web service supports filtering, so the fr-search-value was not used for the dynamic one (is it possible to filter it somehow in Orbeon for both static and dynamic?)
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:exf="http://www.exforms.org/exf/1-0"
xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:saxon="http://saxon.sf.net/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sql="http://orbeon.org/oxf/xml/sql"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
xmlns:xxi="http://orbeon.org/oxf/xml/xinclude">
<xh:head>
<xh:title/>
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<xf:instance id="all-countries"
src="http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso/ListOfCountryNamesByName/XML"/>
<!-- Main instance -->
<xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all" xxf:index="id">
<form>
<section-1>
<country-dynamic-autocomplete label=""/>
<country-static-autocomplete label=""/>
</section-1>
</form>
</xf:instance>
<!-- Bindings -->
<xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
<xf:bind id="section-1-bind" name="section-1" ref="section-1">
<xf:bind id="country-dynamic-autocomplete-bind" ref="country-dynamic-autocomplete"
name="country-dynamic-autocomplete"/>
<xf:bind id="country-static-autocomplete-bind" ref="country-static-autocomplete"
name="country-static-autocomplete"/>
</xf:bind>
</xf:bind>
<!-- Metadata -->
<xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
<metadata>
<application-name>insurance</application-name>
<form-name>test</form-name>
<title xml:lang="en"/>
<description xml:lang="en"/>
</metadata>
</xf:instance>
<!-- Attachments -->
<xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all">
<attachments>
<css mediatype="text/css" filename="" size=""/>
<pdf mediatype="application/pdf" filename="" size=""/>
</attachments>
</xf:instance>
<!-- All form resources -->
<!-- Don't make readonly by default in case a service modifies the resources -->
<xf:instance id="fr-form-resources" xxf:readonly="false" xxf:exclude-result-prefixes="#all">
<resources>
<resource xml:lang="en">
<country-dynamic-autocomplete>
<label>Countries Dynamic Autocomplete</label>
<hint/>
</country-dynamic-autocomplete>
<country-static-autocomplete>
<label>Countries Static Autocomplete</label>
<hint/>
</country-static-autocomplete>
<section-1>
<label>Country Section</label>
</section-1>
</resource>
</resources>
</xf:instance>
</xf:model>
</xh:head>
<xh:body>
<fr:view>
<fr:body xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:oxf="http://www.orbeon.com/oxf/processors">
<fr:section id="section-1-control" bind="section-1-bind">
<xf:label ref="$form-resources/section-1/label"/>
<fr:grid>
<xh:tr>
<xh:td>
<fr:autocomplete xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
id="country-dynamic-autocomplete-control"
labelref="#label"
max-results-displayed="300"
resource="http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso/ListOfCountryNamesByName/XML"
bind="country-dynamic-autocomplete-bind">
<xf:label ref="$form-resources/country-dynamic-autocomplete/label"/>
<xf:hint ref="$form-resources/country-dynamic-autocomplete/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xf:itemset ref="/ArrayOftCountryCodeAndName/tCountryCodeAndName">
<xf:label ref="sName"/>
<xf:value ref="sISOCode"/>
</xf:itemset>
</fr:autocomplete>
</xh:td>
</xh:tr>
<xh:tr>
<xh:td>
<fr:autocomplete id="country-static-autocomplete-control" ref="country-static-autocomplete"
dynamic-itemset="false"
bind="country-static-autocomplete-bind">
<xf:label ref="$form-resources/country-static-autocomplete/label"/>
<xf:hint ref="$form-resources/country-static-autocomplete/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xf:itemset ref="instance('all-countries')/ArrayOftCountryCodeAndName/tCountryCodeAndName">
<xf:label ref="sName"/>
<xf:value ref="sISOCode"/>
</xf:itemset>
</fr:autocomplete>
</xh:td>
</xh:tr>
</fr:grid>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
</xh:html>

How to build project by Spring Boot + Mybatis + Mybatis Generator?

I follow mybatis official website to build my project step by step, but it always can not work well, so I hope you could give me a fully guide from beginning to the end, many thanks.
Step 1. Build a new spring boot project named booking.
This step is basically, I will skip it.
Step 2. Add mybatis-generator to project.
This could help us to generate entity and mapper class mybatis needed automatically, it's very useful for us to save our time.
Add plugin config in pom.xml
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
</dependencies>
</plugin>
Create generatorConfig.xml at base resources path.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<context id="MySqlContext" targetRuntime="MyBatis3Simple" defaultModelType="flat">
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/booking?useSSL=false"
userId="root"
password="123456">
<property name="nullCatalogMeansCurrent" value="true" />
</jdbcConnection>
<javaModelGenerator targetPackage="com.clycle.booking.entity" targetProject="C:\Users\a243903\projects\booking\webapi\src\main\java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.clycle.booking.mapper" targetProject="C:\Users\a243903\projects\booking\webapi\src\main\resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="com.clycle.booking.mapper" targetProject="C:\Users\a243903\projects\booking\webapi\src\main\java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<table tableName="%">
</table>
</context>
</generatorConfiguration>
Create maven Run/Debug Configuration to run this plugin.
It will generate all entity, mapper class and mapper xml automatically. -Dmybatis.generator.overwrite=true, means it will overwrite existing entity or mapper class when run mybatis generator with maven.
Step 3. Add mybatis to this project.
Add mybatis dependency in pom.xml
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
Create mybatis-config.xml at base resources path.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="logImpl" value="LOG4J" />
</settings>
<typeAliases>
<package name="com.clycle.booking.entity" />
</typeAliases>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC">
<property name="" value="" />
</transactionManager>
<dataSource type="UNPOOLED">
<property name="driver" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/booking" />
<property name="username" value="root" />
<property name="password" value="123456" />
</dataSource>
</environment>
</environments>
<mappers>
<package name="com.clycle.booking.mapper" />
<!--<mapper resource="com/clycle/booking/mapper/ShopMapper.xml" />-->
</mappers>
</configuration>
Add #MapperScan for application main class.
#SpringBootApplication
#MapperScan({"com.clycle.booking.mapper"})
public class BookingApplication {
public static void main(String[] args) {
SpringApplication.run(BookingApplication.class, args);
}
}
Autowired mapper interface to operate your database.
#Autowired
private ShopMapper shopMapper;
#PostMapping(RoutePath.SHOP_LIST)
public List<Shop> GetList() {
try {
return shopMapper.selectAll();
} catch (Exception ex) {
return null;
}
}
You can download this project: https://github.com/yyqian/spring-boot-mybatis-generator .
Everything just work fine on my computer.

How can i configure my spring aop xml with aop.xml an load time weaving?

I have one "Hello word" application on spring AOP and configured by XML, it looks like this:
public class CustomerBoImpl {
public CustomerBoImpl() {
super();
}
protected void addCustomer(){
System.out.println("addCustomer() is running ");
}
}
public class App {
public static void main(String[] args) throws Exception {
ApplicationContext appContext =
new ClassPathXmlApplicationContext("Spring-Customer.xml");
CustomerBoImpl customer =
(CustomerBoImpl) appContext.getBean("customerBo");
customer.addCustomer();
}
}
My spring configuration looks like this:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">
<aop:aspectj-autoproxy />
<!-- this switches on the load-time weaving -->
<context:load-time-weaver aspectj-weaving="on" />
<bean id="customerBo" class="com.mkyong.saad.CustomerBoImpl"
scope="singleton" />
<!-- Aspect -->
<bean id="logAspect" class="com.mkyong.saad.LoggingAspect" />
<aop:config>
<aop:aspect id="aspectLoggging" ref="logAspect">
<!-- #Before -->
<aop:pointcut id="pointCutBefore"
expression="execution(* com.mkyong.saad.CustomerBoImpl.addCustomer(..))" />
<aop:before method="logBefore" pointcut-ref="pointCutBefore" />
<!-- #After -->
<aop:pointcut id="pointCutAfter"
expression="execution(* com.mkyong.saad.CustomerBoImpl.addCustomer(..))" />
<aop:after method="logAfter" pointcut-ref="pointCutAfter" />
</aop:aspect>
</aop:config>
that doesn't work because of protected method, so I tried to use load time weaving with aop.xml like this:
<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<weaver>
<!-- only weave classes in our application-specific packages -->
<include within="com.mkyong.saad.*"/>
</weaver>
<aspects>
<!-- weave in just this aspect -->
<aspect name="com.mkyong.saad.LoggingAspect"/>
</aspects>
</aspectj>
Source code for the aspect:
public class LoggingAspect {
public void logBefore(JoinPoint joinPoint) {
System.out.println("logBefore() is running!");
System.out.println("hijacked : " + joinPoint.getSignature().getName());
System.out.println("******");
}
public void logAfter(JoinPoint joinPoint) {
System.out.println("logAfter() is running!");
System.out.println("hijacked : " + joinPoint.getSignature().getName());
System.out.println("******");
}
}
but it doesn't work, only if I change to annotation config. SOS PLZ
removing the following code in your aop.xml, then run your jvm with args like this: -javaagent:"yourpath/spring-instrument-***.jar"
<weaver>
<!-- only weave classes in our application-specific packages -->
<include within="com.mkyong.saad.*"/>
</weaver>

Action not forwaded to tiles-definition from forward path in Action

My struts-config.xml has a few forward actions that point to tiles definitions. But it takes path as it is given & doesn't directed to the tiles-definition.xml & showing path does not start with a "/" character
My struts-config.xml is :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<data-sources />
<form-beans >
<form-bean name="feelSafeForm" type="com.feelsafe.struts.form.FeelSafeForm" />
</form-beans>
<global-exceptions />
<global-forwards >
<forward name="login1" path="/feelSafe.do?do=login" />
<forward name="admin" path="/feelSafe.do?do=admin1" />
</global-forwards>
<action-mappings >
<action
attribute="feelSafeForm"
input="/index.jsp"
name="feelSafeForm"
parameter="do"
path="/feelSafe"
scope="request"
type="com.feelsafe1.struts.action.FeelSafeAction">
<forward name="adminmainpage" path="feelsafe.adminmainpage" />
<forward name="login" path="feelsafe.login" />
</action>
</action-mappings>
<message-resources parameter="com.feelsafe.struts.ApplicationResources" />
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-parser-validate" value="true" />
<set-property property="moduleAware" value="true" />
<set-property property="definitions-config" value="/WEB-INF/tiles-definition.xml" />
</plug-in>
</struts-config>
tiles-definition.xml is :
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"
"http://struts.apache.org/dtds/tiles-config_1_1.dtd">
<component-definitions>
<definition name="feelsafe.common" path="/feelsafeLayout/layout.jsp">
<put name="title" type="string" value="FeelSafe Hospital"/>
<put name="header1" value="/feelsafeLayout/header.jsp"/>
<put name="footer1" value="/feelsafeLayout/footer.jsp"/>
</definition>
<definition name="feelsafe.login" extends="feelsafe.common">
<put name="body1" value="/feelsafeJspFiles/login.jsp"/>
</definition>
<definition name="feelsafe.admin" extends="feelsafe.common">
<put name="body1" value="/feelsafeAdminJspFiles/adminlogin.jsp"/>
</definition>
</component-definitions>
When login is called, control goes to forward tag & gives 500 Error saying :
org.apache.jasper.JasperException: javax.servlet.ServletException:
javax.servlet.jsp.JspException: Exception forwarding for name login1:
javax.servlet.ServletException: java.lang.IllegalArgumentException:
Path feelsafe.login does not start with a "/" character
I get the same error when i removed this snippet from init params of my action servlet in web.xml
...
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
...
<init-param>
<param-name>chainConfig</param-name>
<param-value>org/apache/struts/tiles/chain-config.xml</param-value>
</init-param>
So when you use an old version of dtd like 1.1 try to add this init-param to action servlet to your web.xml file.
I tested on 1.3

Resources