aspose file tools*
The moose likes JSF and the fly likes JSF HTML5 video tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF HTML5 video tag" Watch "JSF HTML5 video tag" New topic
Author

JSF HTML5 video tag

Andy Junius
Greenhorn

Joined: Apr 20, 2012
Posts: 3
Hi all,

I create a html5 video tag and within some source tags:

<source src="#{reference.getUri()}" type="#{mediaPath.getType(reference)}" />

The problem is that this renders the following:

<source src="test.mp4" type="video/mp4"></source>

So JSF adds an end tag to the node; and according to the w3c validator, this is wrong for html5.

Error Line 231, Column 56: Stray end tag source.

<source src="test.mp4" type="video/mp4"></source>

It should rather be:

<source src="test.mp4" type="video/mp4" />

What can I do to get this tag properly rendered?

Cheers,
Andy
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

Welcome to the JavaRanch, Andy!

As a personal observation, parameterized methods calls in a View Definition are not what I consider good practice. It makes it look like you are trying to force JSF instead of work with it, and people often misuse such constructs to break the MVC Separations of Concerns. But that's not what's causing your problem.

You should be able to avoid having the JSF renderer reformat your tag by enclosing it within the "f:verbatim" JSF tag. Technically, any time you embed non-JSF content (and that includes raw HTML), it should be wrapped in a verbatim tag, although in current versions of JSF it isn't as essential as it used to be.

Customer surveys are for companies who didn't pay proper attention to begin with.
Andy Junius
Greenhorn

Joined: Apr 20, 2012
Posts: 3
Hi Tim,

Thanks for the warm welcome )
I managed to get the right output now:


I tried the "f:verbatim" JSF tag before, but JSF expressions inside this tag don't get processed.

With respects to method expressions - I can't see any difference to field expressions. I bought Core JavaServer Faces (Prentice Hall) and the author names method expressions as a valid means to get values right next to field expressions. However it appears the method expression parameters aren't part of JSF but pert of JSR 245 (jsp). Anyway as long as it works...

Cheers,
Andy

Andy Junius
Greenhorn

Joined: Apr 20, 2012
Posts: 3
That board is a bit too clever to display the code correctly, see attached image

Andy



[Thumbnail for code.jpg]

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

One of the reasons why "bean.getURI()" is a bad construct is that it's a strictly read-only access of the property. If you code it on a "value=" attribute for a read/write control such as the inputText control, it won't be able to update the backing bean because it's a call and not a reference.

Another reason I don't recommend that sort of thing is that it reduces the abstraction between View and Model. You are explicitly telling the View how to access something rather than letting the Controller worry about it. That couples implementation details between Model and Controller unnecessarily.

A reason for me is that I'm lazy. I'd rather type "bean.URI". 3 letters fewer plus bonus points for not having to press the shift key and type "()"!

I also tend to be wary about parameters in EL. It's often a sign that the Model and Controller are overlapping in responsibilities, and the whole point of MVC is that it makes design and maintenance simpler, faster, and cheaper because responsibilities are strictly defined and not tightly coupled.

Now that you mention it, EL does have issues in verbatim code. I shudder when outputText is used to generate HTML, but offhand, it's the best of a set of bad solutions.

BTW, JSF 2.2 is working on HTML5 support. Which is another reason for keeping your present code clean and simple. That way it will be less work and less frustration to upgrade it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF HTML5 video tag