JSF inserts <pre> tag automatically, disturbing the order on page

217 views Asked by At

I have a very basic JSF XHMTL page with the following content

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">

<h:head>
<title>Pregled oglasa</title>
</h:head>
<h:body>
<h:outputText value="#{oglasBean.naziv}" />
<br />
<br />
<h:outputText value="#{oglasBean.imeAutora}" />
<br />
<h:outputText value="#{oglasBean.prezimeAutora}" />
<br />

</h:body>
</html>

Here's the piece of code that sets up these variables:

public String pregledOglasa() {
    Map<String, String> reqMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
    int idOglasa = Integer.parseInt(reqMap.get("oglas_id"));

    for (Oglas oglas : aktivniOglasi) {
        if (oglas.getIdOglasa() == idOglasa) {
            this.setIdOglasa(idOglasa);
            this.setNaziv(oglas.getNaziv());
            this.setTekstOglasa(oglas.getTekstOglasa());
            this.setImeAutora(oglas.getImeAutora());
            this.setPrezimeAutora(oglas.getPrezimeAutora());
            this.setLokacijaDo(oglas.getLokacijaDo());
        }
    }

    return "/korisnik/pregledOglasa?faces-redirect=true";
}

What happens here is that "oglasBean.naziv", once when you open the page, comes after "oglasBean.imeAutora" and "oglasBean.prezimeAutora". Inspecting the code revealed that, for some reason, "oglasBean.naziv" is wrapped in pre tag and shows up the last, i.e. after "oglasBean.imeAutora" and "oglasBean.prezimeAutora":

enter image description here

In example given, "title 2" is meant to be above "John" and "Johnson".

Googling for this does't show anything similar, so it seems I am stuck here with a weird problem.

Even if I change "#{oglasBean.naziv}"

to "#{oglasBean.imeAutora}"

the problem remains the same, like JSF just takes whatever is first on the page and wrappes it in pre.

1

There are 1 answers

2
Gishas On

OK, this one seems solved way quicker than I expected by experimenting with literally anything dumb I could have thought of. I tried wrapping everything in

<h:panelGroup layout="block">

to try to add div tag. It didn't work. Then I just tried plain div and voila, everything seems to be in order now, no extra tags or whatever:

enter image description here

I still wander if this is some kind of default JSF behaviour or maybe a glitch?