Creating JSF Pages with Pure Java Code

UI Components for JSF
Post Reply
pavel.ponec
Posts: 4
Joined: 14 Mar 2019, 11:58

14 Mar 2019, 12:15

Hello,
I would like to ask if it is possible to create HTML pages using pure Java code according to the ideas of this article:

https://dzone.com/articles/creating-jsf-pages-pure-java

If so, whether it is possible to take this approach as a vendor-supported solution and possibly where I can find some guidance.

Best regards,
Pavel

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

14 Mar 2019, 17:49

Don't do this. From https://stackoverflow.com/questions/351 ... orm-fields
BalusC wrote:Noted should be that there is absolutely nothing which is only possible in Java (way #2) and impossible in XHTML+XML (way #1). Everything is possible in XHTML+XML as good as in Java. A lot of starters underestimate XHTML+XML (particularly <ui:repeat> and JSTL) in dynamically creating components and incorrectly think that Java would be the "one and only" way, while that generally only ends up in brittle and confusing code.

pavel.ponec
Posts: 4
Joined: 14 Mar 2019, 11:58

15 Mar 2019, 10:18

Everything is possible in XHTML+XML as good as in Java
Here are some reasons for using the Java code:
  1. Java coding is usually faster and type-safe, better refactoring is supported in a NetBeans IDE for example
  2. The compiler does not recognize typing errors of the XHTML to Java API
  3. It is difficult to implement a component factory service to provide a graphical component in XHTML (according to some meta-data model for example)
  4. XHTML technology does not know the simple inheritance of components. A component extended of SelectBooleanCheckbox (for special use) is difficult to use in XHTML for example.
  5. There are probably more reasons for this.
Regards,
Pavel

mdzaebel
Posts: 10
Joined: 28 Jun 2014, 17:15
Location: Germany, Lüneburg

15 Mar 2019, 12:04

Pavel,

of course, this is natural thought. I started the same many years ago. However, I just learned, that separating presentation and business logic is quite usefull. The second learning was, that XHTML is indeed a shorter and better method to represent the view. You can go through some years of experience but you will finally end up with this insight. There will be some problems that get bigger and bigger using low level API's. So just use the 30 man years of Primefaces that deliver components already optimized with their API (and the implementation is sometimes quite complex!). Of course, you'll use Java but only for lists/graphs of objects, that are traversed via view iterators and methods, that you can apply to them.

Marc
PF 7, WildFly 11, Java EE 7, JDK 8

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

15 Mar 2019, 13:24

pavel.ponec wrote:
15 Mar 2019, 10:18
Java coding is usually faster and type-safe, better refactoring is supported in a NetBeans IDE for example
no need to if you encapsulate what you need in 'wrappers' https://stackoverflow.com/questions/682 ... m-componen
pavel.ponec wrote:
15 Mar 2019, 10:18
The compiler does not recognize typing errors of the XHTML to Java API
When do you make those? EL mismatch with @Named beans and its methods IS recognized in a decent IDE
pavel.ponec wrote:
15 Mar 2019, 10:18
It is difficult to implement a component factory service to provide a graphical component in XHTML (according to some meta-data model for example)
Please provide a concrete example? I've done a complex form solution with a 'sort of' factory and many input types that can be compared with what you describe that works perfectly
pavel.ponec wrote:
15 Mar 2019, 10:18
XHTML technology does not know the simple inheritance of components. A component extended of SelectBooleanCheckbox (for special use) is difficult to use in XHTML for example.
Why is this needed, example? There are options to override/extend things if required.

Effectively all you seem to have are arguments of things that you need IF you use java to write components.

pavel.ponec
Posts: 4
Joined: 14 Mar 2019, 11:58

15 Mar 2019, 13:41

separating presentation and business logic is quite usefull.
It is possible that my view may be influenced by the relatively short experience of JSF, however I have many years of experience with the Apache Wicket component framework where there was no problem separate the presentation layer from business logic in the Java code. Therefore, my question remains the same: can anyone advise me how to try it?

Regards,
Pavel

pavel.ponec
Posts: 4
Joined: 14 Mar 2019, 11:58

18 Mar 2019, 10:09

Hello Ronald, thank you for a detail response.
SelectBooleanCheckbox (for special use) ... Why is this needed?
For some historical reasons, my project uses Enum instead of Boolean in data model.
I'd like to implement missing customer data adapter into the SelectBooleanCheckbox component for general data type.
component factory ... Please provide a concrete example?
Imagine that the property of each attribute of a domain object is described by a class containing information:
  • the attribute name
  • data type
  • value validator
  • max length of input text field
Then it will be possible to create a factory method for the production of graphical components according to the model. The development of forms using the factory method is very fast and ensures standard components throughout the all project. Here's a real example of how to use it on components of the Apache Wicket framework:
I'm afraid that such a solution is very difficult to implement using XHTML of JSF.

mdzaebel
Posts: 10
Joined: 28 Jun 2014, 17:15
Location: Germany, Lüneburg

29 Mar 2019, 00:35

You can simply use your logic to create the model with pojos, that are not view components but value objects. This model can be traversed by sequencable view components like p:dataTable, p:TreeTable etc. in the XHTML view. That's it!

Marc
PF 7, WildFly 11, Java EE 7, JDK 8

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

01 Apr 2019, 17:54

Besides https://www.primefaces.org/showcase-ext ... naForm.jsf being available
pavel.ponec wrote:
18 Mar 2019, 10:09
I'm afraid that such a solution is very difficult to implement using XHTML of JSF.
No it is not... See the link I already posted. https://stackoverflow.com/questions/351 ... orm-fields. You can wrap things even in a custom component/tag/...

And
pavel.ponec wrote:
18 Mar 2019, 10:09
SelectBooleanCheckbox (for special use) ... Why is this needed?
For some historical reasons, my project uses Enum instead of Boolean in data model.
I'd like to implement missing customer data adapter into the SelectBooleanCheckbox component for general data type.
The second sentence this is still hard to understand.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 51 guests