首页 > 解决方案 > JSF inserts

 tag automatically, disturbing the order on page

问题描述

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.

标签: htmljsfxhtml-transitional

解决方案


好的,通过尝试我能想到的任何愚蠢的东西,这个问题似乎比我预期的解决得更快。我试着把所有东西都包起来

<h:panelGroup layout="block">

尝试添加div标签。它没有用。然后我只是尝试了普通的div和瞧,现在一切似乎都井井有条,没有额外的标签或其他任何东西:

在此处输入图像描述

如果这是某种默认的 JSF 行为或者可能是故障,我仍然会徘徊?


推荐阅读