Skip to content

Decoupling Java from HTML [SPR-12089] #16705

@spring-projects-issues

Description

@spring-projects-issues

Andrew Luhring opened SPR-12089 and commented

  1. Problem:
    Spring's view technologies do not offer a method to only access the lowest level of front-end data.
<form:form modelAttribute="searchCriteria" action="${hotelsUrl}" method="get" cssClass="inline">
    <span class="errors span-18">
        <form:errors path="*"/>
    </span>
    <fieldset>
        <div class="span-8">
            <label for="searchString">SeaString:</label>
            <form:input id="searchString" path="searchString"/>
        </div>
    </fieldset>

The problem is that most of that is unnecessary. In reality the only information the front end needs is:

"form" : {
    "name" : "searchCriteria"
  , "action" : "hotelsUrl"
  , "method": "get"
  , "errors" : [{
        "name" : (error cause)
     ,  "line" : (line number)
     ,  "trace": (stack trace)
     } , {
         (etc)
     }]
  ,  "inputs" : [{
       "name" : "search-string"
     , "type" : "text"
     } , {
       "name" : "other-input"
     , "type" : "number"
     } , { 
       "name" : "another-input"
     , "type" : "color"
     }]
}

By giving us data as a JSON or XML object, you decouple the data requirements of the requests from the implementation of the html.

For instance, this:

<label for="searchString">SeaString:</label>
<form:input id="searchString" path="searchString"/>

will output this:

<label for="searchString">SeaString:</label>
<input type="text" id="searchString" name="searchString" />

so what is a Front-End dev supposed to do if they disagree with that markup for that implementation? What if they want the markup, in this case, to be:

  <label><span class="accessibility-text">SeaString</span>
    <input 
       type="search" 
       min="3" 
       maxlength="30"
       placeholder="SeaString"
       autocomplete="on"
       required
       autofocus
    />
  </label>

Most of that can actually be done with jsp (or the other templating languages), EXCEPT this part:

<label>
  <input />
</label>

That seems like not a big deal, and it isn't if it were just that one case, but if you take this problem and do it for every templating element, it becomes a serious problem-- and that's assuming the Front-End isn't using any of the new frameworks like Backbone, Angular or Ember. If they ARE, they would be forced to mix JSP or worse Java, with their JavaScript.

So, please consider a shift in how spring implements the bridge between the front and back ends. The front end is growing more complicated by the day and back-end developers shouldn't have to think about whether they should template something as a section, article, main or aside element.

We collaborate through data, but lets keep our concerns separate.


Reference URL: http://spring.io/understanding/view-templates

0 votes, 6 watchers

Metadata

Metadata

Assignees

Labels

status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions