Multi-line Text in Spring String Bean as HTML template with context variables


There is a String bean view1Html in the context configuration file /durian/src/main/resources/springweb/pages-context.xml .

Similar to the previous page, the bean
  • is a java.lang.String bean
  • specifying constructor argument:
    <constructor-arg><value> html text </value></constructor-arg>
  • making use of the CDATA enclosure
The Java class injected with the String bean view1Html is com.synthful.angst.mvc.durian.DurianControllerAsView
public class DurianControllerAsView extends AAngsta {

    private String plantFruitName;
    @Value(value = "${}")
    private void setPlantFruitName(String plantFruitName) {
        this.plantFruitName = plantFruitName;"plantFruitName 1:{}", plantFruitName);
    @Value(value = "${plant.fruit.type}")
    private String plantFruitType;

    @Inject private String view1Html;
    @RequestMapping(value = "/v1", method = RequestMethod.GET)
    public String requestHandler (ModelMap model) throws Exception {"plantFruitName 2:{}", plantFruitName);"plantFruitType:{}", plantFruitType);
        return view1Html;

Note that the controller is generating its own view

  • due to the annotation @ResponseBody.
  • IOW, the String bean is the view
  • and the application-properties / context-variables are the model.

Where the context variable substitution is due to the property file appbase/properties/
plant.fruit.type = peanut
plant.fruit.etymology.language = Malay
plant.fruit.etymology.meaning = thorny
plant.genus = Durio
plant.tribe = Durioneae
plant.subfamily = Malvaceae
plant.order = Malvades

HTML template as multi-line text inSpring String Bean

The String bean view1Html in ScriptTemplates-context.xml
  <bean id="view1Html" class="java.lang.String" scope="prototype">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "">
<html template="true"><head>
  <meta content="text/html; charset=UTF-8" http-equiv="content-type">
<table style="text-align: left;" border="1" cellpadding="5" cellspacing="2">
  <tbody style="vertical-align: top;">

The page is accessed as http://localhost:8080/durian/v/durianview/v1 with the resulting view:

No comments:

Post a Comment