spring java - reuse tiles - spring

i have a j2ee written with spring framework and we are using tiles for templating.
overtime, developers have created numerous css styles and reuse them all over the jsp pages. for example we created a <table class="tablestyle blue ">, or <select class="style1 style2 style3"> and it is used in multiple pages. the problem i faced is that whenever we create a new table/select, we have to ensure we key in the correct css styles and this is cumbersome.
my question is, is it possible to put this <table> and <select> with its css class styles into a template and reuse it in other templates?

you can have this kind of tile for example it is the table
<table>
<thead>
<tr>
<c:foreach items="${tableColumn}" var="column">
<td><c:out value="${column}"/>
</c:foreach>
</tr>
</thead>
</table>
from the controller you will just put an column attribute to make it more flexible
and the select is all the same right?
<select>
<c:foreach items="${optionItems}" var="option">
<option><c:out value="${option}"/></option>
</c:foreach>
</select>
in this case you could reuse the table and option tile in every jsp you want it.

Related

Is it possible to put Images in table's **td** tag in mpdf Laravel library

I am trying to add an 100 X 100 pixel image in a table in mpdf. But the table disappears when I do so.
<table>
<tr>
<td><img src="https://someimage.jpg" width=100 height=100></td>
</tr>
</table>
But when I use tag outside table it fetches the image and shows it perfectly fine.
How do I put image in table in mpdf (is there any trick)?
From my experience when I tried to use MPDF with tables and images inside cells I couldn't manage to set the correct image sizes. I fixed it with div's instead of table. If possible try this solution
It is possible to put images in a table in mpdf. Earlier i was making syntax mistake. I had forgot a comma. Sorry for inconvineance.
<table>
<tr>
<td><img src="https://someimage.jpg" style="height:50px; width:100px;"></td>
</tr>
</table>

Dandelion Datatables + Thymleaf + dt:format

I've tried to implement the formatting attribute for Dandelion Datatables as specified here using Thymeleaf to no avail, like so:
<table dt:table="true" dt:serverside="true" dt:url="#{/somefnplace}">
<thead>
<tr>
<th dt:property="someCurrencyField" dt:format="{0, number, #.##}">
</tr>
</thead>
</table>
...but this does not do anything. Anyone got an idea on how this is supposed to work, or do I have to create render functions for every column because this feature is broken?
Unfortunately, the dt:format attribute is not compatible with AJAX sources. See the last column of the link you've mentioned.
In the upcoming version, it will simply be removed, because using DOM sources, expression utility objects meet all needs perfectly.
So yes, currently the only way is to use the dt:renderFunction attribute, which will refer to a rendering function, one for each column to need to display in a specific format.

Automatic tables rendering in Spring MVC

Is there any way to automate process of rendering tables with Spring MVC? I'm looking for some mechanism for automated rendering List of POJO's on JSP instead of manual writing code like this:
<c:if test="${not empty objects}">
<table>
<c:forEach var="o" items="${objects}">
<tr>
<td>${o.id}</td>
<td>${o.name}</td>
</tr>
</c:forEach>
</table>
</c:if>
Probably something like this:
<awesometaglib:smarttable data="${listOfPOJOs}"/>
You can try DisplayTag or any other library.

View component of MVC. Should I pre generate HTML tag elements in the Controller for the View?

I'am currently creating a MVC Java Web App with Struts2.
One element of my app is searching for some results via form. When the user submits the form an Action gets the necessary values from the database and populates a Map:
Map<Integer,List<String>> values = new HashMap<Integer,List<String>>();
Which has a list of column values for each row.
By Following this approach I can have generic JSP for displaying the results of any resultbox:
<s:div cssClass='resultContainer'
cssStyle=' min-height: 150px; max-height:%{header}px; overflow: auto; %{display}; '
theme="qxhtml">
<table id='resultTable'>
<tr id='tableHeader'>
<s:iterator value="headers">
<th><s:property /></th>
</s:iterator>
</tr>
<s:iterator value="values">
<tr class='results'>
<s:iterator value="value">
<td><s:property escape="false" /></td>
</s:iterator>
</tr>
</s:iterator>
</table>
I feel now that this is a bad approach. Instead I should change the Map to a List of ResultBoxRow objects. Each ResultBox will have its own View Jsp instead of one generic one allowing me to iterate over the objects and output for example:
<s:iterator value="value">
<td><s:property name="firstname" /></td>
<td><s:property name="lastname" /></td>
etc.
In the case of the table headers I may need to give certain headers individual style properties. I feel these should be defined in the JSP itself rather than get the JSP to reference a value from the controller containing the style for that header.
I think my overall question is how much should the controller control the style/display of elements of the View? I feel it should just generate the individual elements displayed in the tags but not the values to put in the "style" tag of the row for example. Even if this does sacrifice a simple single JSP to handle every result box.
It would be great to get your opinions.
The controller should have nothing to do with the display mechanism: that's the point of MVC, to completely separate the data from its presentation.
You can still DRY up the view layer via custom tags, includes, templates, etc. Styles may be passed as attributes, while the underlying DOM would be created by a single page or template.
It also matters what the nature of the attributes you want to pass. If they're semantic that could logically from from the model or controller that's fine. If they're purely presentational, like colors, widths, etc. then it has no business in the model or controller.

Using Razor "RenderPartial" and "RenderBody", the body is rendered on top

I am developing a site with Header, Main Menu, Body and Footer sections.
I am using a web page base layout _Layout.cshtml where I use the RenderPartial() method to render the Header, Main Menu and Footer. For the body, I am using the RenderBody() method.
In _Layout.cshtml I have the following code:
<body style="margin: 0">
<form name="FormStart" method="post" action="Start.aspx" id="FormStart">
<table cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
<tr>
<td valign="top" width="1px"></td>
<td valign="top" align="center" width="972" bgcolor="#FFFFFF">
<table id="Table1" cellspacing="0" cellpadding="0" width="972" border="0" bordercolor="yellow">
<!-- HEADER -->
#{Html.RenderPartial("_Header");}
<!-- MAIN MENU -->
#{Html.RenderPartial("_Menu");}
<!-- CONTENT -->
#RenderBody()
</table>
<br />
<!-- FOOTER -->
#{Html.RenderPartial("_Footer");}
</td>
</tr>
</table>
</form>
</body>
On the other hand, I created a very simple view with the following code
#{
ViewBag.Title = "Page";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h3>You just clicked </h3><h1>NATURAL ALOE SECTION</h1>
The thing is, that the content of this simple view is displayed at the very top of the page, whereas the rest is on the bottom. Instead of displaying HEADER-MAINMENU-my site-FOOTER it displays it in the order of my site-HEADER-MAINMENU-FOOTER.
I am quite new with MVC all around; I have been reading here about the possibility of using RenderSection instead of RenderPartial in my main Layout site, but could this be the reason while it is displaying this way? Probably I am way off base, any advice is much appreciated.
Thanks in advance.
This might be happening because you render the header, menu and body inside a <table>. At least the body seems to be missing the row and cell tags (<tr><td>...</td></tr>). Therefore there are no rows and cells in your table which can lead to all sorts of rendering problems.
It would probably help if you didn't render into a table and use CSS for layout purposes instead.
This looks to be nothing to do with the MVC side of what you are doing - that looks perfectly fine.
The issue will be with your HTML. I would suggest having a look at the site using one of the browser developer tools (e.g. in Chrome or IE open your site and press F12) - you can use the features of these to examine how the visual elements on your page relate to the HTML. These tools are invaluable as an MVC programmer.
Using tables to control the layout of a web-page is discouraged in favour of using css for layout. You can find some basic css layout templates via Google to get started.

Resources