-1

I have a UI include that have a dynamic content , this content will be loaded when I press in a certain command link. the problem is when I press the command link the UI include is loaded without the Javascript created the PrimeFace:

could this problem be related to @Resource Dependency.

This my controller:

@Named
@ViewScoped
public class Test {

    private String value;
    private List<String> options=new ArrayList<>();
    private String url="";

    public String changeUrl(){
        url="/snippets/test2.xhtml";
        return "#";
    }

    @PostConstruct
    public void init(){
        options.add("test 1");
        options.add("test 2");
        options.add("test 3");
        options.add("test 4");

    }

    //getter and setter
}

and this the xhtml page:

<h:form>
text
<ui:include src="#{test.url}" />
<p:commandLink action="#{test.changeUrl()}" value="submit" process="@this" update="@form"/>
</h:form>

And this the included Page:

<ui:composition>
    <h:form>
    <p:selectOneMenu value="#{test.value}">
    <f:selectItems value="#{test.options}"/>
    </p:selectOneMenu>
    </h:form>
    </ui:composition>
Cœur
  • 37,241
  • 25
  • 195
  • 267
bob-cac
  • 1,272
  • 2
  • 17
  • 35

1 Answers1

2

Two problems here: the ui:composition declaration in your included page is missing all of the required namespace declarations, and you are embedding a form within another form.

Your included page should look like this:

<ui:composition
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.org/ui">
 <p:selectOneMenu value="#{test.value}">
  <f:selectItems value="#{test.options}"/>
 </p:selectOneMenu>
</ui:composition>
codeturner
  • 993
  • 1
  • 8
  • 20
  • there is no need to mention name space and imports in the question , surly they are exist – bob-cac Sep 15 '14 at 12:58
  • 1
    Surely? How am I to know you knew that? You're creating invalid html with nested forms. I can't assume anything if I am to help. – codeturner Sep 15 '14 at 14:26
  • It is a policy here to have a short question that doesn't contain such non important part, besides there no developer that do not know about namespace (unless you want my question to be closed) , anyway i will remove my down vote(please make any edit to your answer) sorry... – bob-cac Sep 15 '14 at 14:30
  • I do want to help. What about the nested h:form tags? – codeturner Sep 15 '14 at 14:40
  • i am obliged to use nested forms and there is not a rule not to use nested forms but its better not to use nested forms – bob-cac Sep 18 '14 at 05:41
  • 1
    Nested forms elements are invalid in html and won't work as you expect. See this [answer](http://stackoverflow.com/a/7372315/193347). – codeturner Sep 18 '14 at 14:50