I have to click twice in a command link to refresh a layout

UI Components for JSF
Post Reply
evillalona
Posts: 11
Joined: 09 Jan 2011, 14:44

09 Jan 2011, 15:17

I'm new using primefaces and i am testing de components developping a simple application in a full page layout. In the left side i have a few command links menu and any time an option is clicked a page must be dinamically loaded into the central layout unit, but it only happens after clicking twice the command link. Here is my code:

index.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<body>
<h:head>
<title>Facelet Title</title>
<link type="text/css" rel="stylesheet" href="#{request.contextPath}/css/redmond/skin.css" />
</h:head>
<h:form id="frPrincipal">
<p:layout id="frlayout" fullPage="true">
<p:layoutUnit position="top" height="75" resizable="false" closable="false" collapsible="false">
<h:outputText value="**Sample Demo Page**"></h:outputText>
</p:layoutUnit>

<p:layoutUnit position="left" width="200" header="Menu" resizable="true" closable="false" collapsible="false">
<p:menu style="width:100%">
<p:submenu label="Tablas del Sistema">
<p:menuitem>
<p:commandLink immediate="true" id="Page1" value="Page1" actionListener="#{menuController.sideBarAction}" type="submit" update="frCentral" ajax="true">
<f:param id="page1ParamId" name="pageViewId" value="Page1"/>
</p:commandLink>
</p:menuitem>
<p:menuitem>
<p:commandLink immediate="true" id="Page2" value="Page2" actionListener="#{menuController.sideBarAction}" type="submit" update="frCentral" ajax="true">
<f:param id="page2ParamId" name="pageViewId" value="Page2"/>
</p:commandLink>
</p:menuitem>
</p:submenu>
</p:menu>
</p:layoutUnit>

<p:layoutUnit id ="CuadroCentral" position="center">
<p:outputPanel id="frCentral">
<ui:include src="#{menuController.currentPage}"/>
</p:outputPanel>
</p:layoutUnit>

<p:layoutUnit position="bottom" height="75" resizable="false" closable="false" collapsible="false">
<h:outputText value="Footer text...!"/>
</p:layoutUnit>
</p:layout>
</h:form>
</body>
</html>

formtest.xhtml:
<div xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:h="http://java.sun.com/jsf/html">
<h:outputLabel value="This is the Formtest page"/>
</div>

formtest1.xhtml:
<div xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:h="http://java.sun.com/jsf/html">
<h:outputLabel value="This is the Formtest1 page"/>
</div>

formtest2.xhtml:
<div xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:h="http://java.sun.com/jsf/html">
<h:outputLabel value="This is the Formtest2 page"/>
</div>

MenuController.java:

package HDesk2Pkg;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class MenuController implements Serializable {

private String currentPage = "/formtest.xhtml";
private FacesContext context;
public MenuController() {
}

public String sideBarAction() {
context = FacesContext.getCurrentInstance();
String selectedPageViewId = context.getExternalContext().getRequestParameterMap().get("pageViewId");
System.out.println("Selected Page: "+selectedPageViewId);
if (selectedPageViewId.equalsIgnoreCase("Page1")) {
currentPage = "/formtest1.xhtml";
} else if (selectedPageViewId.equalsIgnoreCase("Page2")) {
currentPage = "/formtest2.xhtml";
}
else
currentPage = "/formtest.xhtml";
String viewId = context.getViewRoot().getViewId();
System.out.println("View IDr "+viewId);
return currentPage;
}

public String getCurrentPage() {
return currentPage;
}

public void setCurrentPage(String currentPage) {
this.currentPage = currentPage;
}
}

Thanks in advance!
Netbeans 12
Primefaces Elite 8.0.6
Java EE 8
OpenJDK 13
apache-tomee-plume-8.0.0

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 16 guests