0

I am interested to know if Java Swing has an a comparable feature to Partial Views in ASP.NET?

I have several web pages with common HTML. I would like to split out the common bits to one place for better maintainability. Then just automatically include that bit of HTML in the same place in the other web pages.

The HTML in question would just be a snippet and not a whole web page.

I did some searching of internet and stack overflow but nothing obvious came up.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
yogibear
  • 320
  • 2
  • 13
  • 2
    Swing is not an HTML framework. – RealSkeptic Jan 06 '20 at 10:05
  • Could you explain what is `PartialView`? If I correctly understoold the explanations in Web - each Swing component is a partial view. – Sergiy Medvynskyy Jan 06 '20 at 10:09
  • Partial view is where you have a small portion of HTML (not a complete page) and you can get it to be included in other web pages. for example. You may have web page 1, 2 and 3, and a partial html file. Each page 1,2 and 3 would display there own content, but also include the partial html file. In terms of ASP.net ; https://www.red-gate.com/simple-talk/dotnet/asp-net/tips-and-tricks-about-razor-partial-views/ – yogibear Jan 06 '20 at 11:24
  • Partial views are very good way to put navigation links which are same for all pages in one place. – yogibear Jan 06 '20 at 11:24
  • The application I am using makes use of; org.springframework, javax.servlet, org.eclipse.jetty . – yogibear Jan 06 '20 at 11:25
  • Unfortunately I was given an existing project and haven't been involved in Java web stuff before. My experience as you may have guessed was with ASP.NET and C# – yogibear Jan 06 '20 at 11:27
  • I might have found the answer, let me try it out. https://stackoverflow.com/questions/20030773/how-to-include-an-html-fragment-in-a-jsp-that-loads-at-run-time – yogibear Jan 06 '20 at 11:32
  • @yogibear You cannot include HTML code into a Swing application, but each component in Swing can be included in multiple pages. – Sergiy Medvynskyy Jan 06 '20 at 11:50

1 Answers1

1

The solution is very simple. I tried different search terms and eventually found the following page; Stackoverflow answer1

The simple answer is to move the HTML fragment you need into it's own file. Then where the code was insert the following

<jsp:include page="navigation.jsp" />

Then in this case navigation.jsp was the file I put the fragment of HTML in. This file simply has ... block of code.

yogibear
  • 320
  • 2
  • 13