jsf,jsf-2,reference,uiinclude , Every include should refer to other instance

Every include should refer to other instance


Tag: jsf,jsf-2,reference,uiinclude

I include a part of the XHTML page to my Web Application. This part can be included multiple times. And that's the problem! Because every include refers to the same java object. That means that every element has the same value. But I want for each include a new Java object. So whats the best way to solve this problem?

Main page with includes:

<ui:composition template="./templates/template.xhtml">
<ui:define name="mainContent">

    <ui:include src="include/includeAbleEditor.xhtml">
        <ui:param name="includeParam" value="MyClass" />

    <ui:include src="include/includeAbleEditor.xhtml">
        <ui:param name="includeParam" value="YourClass" />



<h:commandButton value="#{editorVisibility.evb.value}"
                 action="#{editorVisibility.evb.toggle}" />

<h:inputTextarea rendered="#{editorVisibility.evb.enabled}" />

This <h:inputTextarea> is an example for my problem. Every included inputTextarea has a toggle button. By clicking the button the textarea should be shown or hidden. But because of the same reference of the boolean value all <h:inputTextarea> will always have the same rendered value.

Do you have any suggestions?

Thanks a lot!


You'll have to hold as many instances of editorVisibility.evb as you have editors. You could for example create a List<TypeOfEvb> evbList in your EditorVisibility bean, and pass only one element to the <ui:include> as a <ui:param>:

Main page

<ui:include src="include/includeAbleEditor.xhtml">
    <ui:param name="includeParam" value="MyClass" />
    <ui:param name="evb" value="#{editorVisibility.evbList[0]}" />


<h:commandButton value="#{evb.value}"
                 action="#{evb.toggle}" />
<h:inputTextarea rendered="#{evb.enabled}" />

You could also create a composite component.

See also:



Render hidden elements using JSF and AJAX

I've been facing some problems using JSF with AJAX to render a table without reloading the whole page every time I submit a form. When I first run the server, my database is empty, so the page is supposed to show only a form to add books. When user submits...

h:selectmanyListbox make “choose” option unselectable when at least one option is selected

Is it possible to have in <h:selectManyListbox> a default option like "--choose--" which can be selected when no option is selected. When the some value is chosen, then it must be unselectable. <h:selectManyListbox value="#{bean.value}" class="form-control"> <f:selectItems value="#{bean.dropdownValues}" var="value" itemLabel="#{value}" itemValue="#{value}"/> </h:selectManyListbox> ...

Parameters from f:param not submitted with AJAX request when form enctype is multipart/form-data

I'm running Wildfly 8.2 and I'm using the JSF version bundled with it, 2.2.8-jbossorg-1. I have the following facelet: <h:form enctype="multipart/form-data"> <h:commandButton value="Submit"> <f:param name="myparam" value="true"/> <f:ajax execute="@this" render="@this"/> </h:commandButton> </h:form> When I press the submit button, several parameters are submitted, but not myparam. If I remove enctype="multipart/form-data" from the...

how stick out a menu when clicking on a menu [on hold]

I have a type of menu created in JSF. <p:menubar styleClass="menuPrincipal" id="menuBar" > <p:menuitem value="Inicio" url="/Inicio.xhtml" style="text-decoration:none" icon="ui-icon-home" id="inicio" /> <p:menuitem value="Agregar Excepciones" id="agregarExcepcion" url="/ExcepcionNuevo.xhtml" style="text-decoration:none" rendered='#{excepcionPendienteView.usuarioActual.tipoSolicitante eq "Administrador"}' /> </p:menubar> I want that when you click on a menu, highlight the option me where I am working. if I...

java.util.ServiceConfigurationError when running tests using arquillian+omnifaces

I am getting the following error "java.util.ServiceConfigurationError: javax.servlet.ServletContainerInitializer: Provider org.omnifaces.ApplicationInitializer not found" when running Arquillian tests. I have put the most basic test case I could here: https://www.dropbox.com/s/kou5v8kqs5g4g4m/test.zip?dl=0...

Creating command links dynamically from a managed bean

I have a need to create command links dynamically based on content coming from elsewhere. When a user clicks on a link it should call a method in a managed bean, and the method needs to know which link was clicked. I can create the command links using the following...

javax.servlet.ServletException the request doesn't contain a multipart/form-data or multipart/mixed stream

I've the below form which uploads a file via <h:inputFile> and <f:ajax>. <h:form enctype="multipart/form-data"> <h:inputFile id="file" value="#{bean.file}" /> <h:commandButton value="Upload" action="#{bean.upload}"> <f:ajax execute="file" render="file" /> </h:commandButton> </h:form> When I submit it, I get a JavaScript alert with the below error information: serverError: class javax.servlet.ServletException the request doesn't contain a multipart/form-data...

Manually added faces message doesn't appear in tab of accordion panel

I'm adding a faces message in an action method as below: FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_WARN, "Mail invalide", "Vérifier le mail"); FacesContext.getCurrentInstance().addMessage("connection:mail", message); I'm expecting it to show up at the below position in the tree: <h:body> <p:layout fullPage="true"> <p:layoutUnit position="center" > <p:accordionPanel multiple="true" activeIndex="0"> <p:tab title="Se connecter" > <h:form...

af:convertNumber element removes zero in the end of the value

My code: <af:inputText id="it1" label="Test"> <af:convertNumber groupingUsed="true" type="number" messageDetailConvertNumber="#,###,##" maxFractionDigits="2"/> </af:inputText> When I type 100,51 -- everything is fine, but if I would type 100,50, then '0' will be removed and entered value will be 100,5. How can I leave this '0' in the end? I need <af:convertNumber> element for...

Dynamic rendering - unable to find component with clientId

I am rendering a xhtml to a dialog whose components are added dynamically from server side using Dynamic example. Using PrimeFaces 5.1, JSF 2.1 Mojarra and tomcat 7. When i click the close button of the pop up a large number to of unable to find the component is being...

CommandButton execution while rendering

Question: How can I prevent the execution of a while the website is rendering? Thats where my Button sits: <p:dialog widgetVar="newComment" height="200" width="500"> <h:form> <h:panelGrid> <h:outputText value="#{commentDialog.username}" /> <h:inputTextarea id="in_text" value="#{commentDialog.text}" /> <p:message for="in_text" /> </h:panelGrid> <p:commandButton validateClient="true" value="Abschicken" ajax="true" actionListener="#{popupRequestView.update}"...

Submit form without attached file

I want to create JSF form with attached file. But also to give a option form the users to submit the for without attach file. I don't want this to be mandatory. <h:form id="form" enctype="multipart/form-data"> <div class="string"> <label class="name"> <h:inputText id="name" value="#{contacts.name}" pt:placeholder="Name*:"/> </label> </div> <label class="message"> <h:inputTextarea value="#{contacts.comment}" pt:placeholder="Comment*:"/>...

set focus to next input element after jsf's change value listener

in one of our front-end screens we have the following layout as follows <h:outputLabel for="firstName" value="first name" /> <h:inputText styleClass="required" id="firstName" size="30" maxlength="30" value="#{ownershipStoreInfoController.form.ownerFirstName}" onchange="submit()" valueChangeListener="#{ownershipStoreInfoController.useOwnerInfo}"> <e:validateRegExpr pattern="([A-Z,a-z,0-9,%@()#&amp;,.;:_\$\/\-\{\}\[\]\'\\s*]{1,30})?" /> </h:inputText> <h:outputLabel for="lastName" value="last name"...

JSF link to external site without showing username and password in the URL

I was able to do a SSO(Single sign on) on click of external link from the code below. SSO works but username/password is seen on url. https://example.org/index.php?userLogin=user1&userPassword=pass123 <h:outputLink styleClass="ui-menuitem-link ui-corner-all" value="https://example.org/index.php"> <h:outputText value="Ext Tool" /> <h:outputText styleClass="ui-icon ui-icon-suitcase" style="float:left" rendered="#{userBean.in}" /> <f:param name="userLogin" value="#{userBean.user.eUser}" /> <f:param...

a4j:support - Value retrieved from h:selectOneMenu is always NULL

There's a datatable with a h:selectOneMenu in each row. I want to be able to retrieve the value selected in the selectOneMenu in the bean. I'm using richfaces a4j:support tag to make AJAX calls to the backing bean. You can see the code below: DataTable header: <t:dataTable id="datatable" var="row" value="#{myBean.dataTableRows}">...

Is there a JSF toggle component or a way to theme an h:selectBooleanCheckbox with images?

I tried using a toggle like below. Although it works, it breaks when used inside of a composite component - changing the singleSelect value outside of the component never updates inside the component: <h:commandButton disabled="#{cc.attrs.singleSelect}" image="/resources/img/collapse-single.gif"> <f:ajax listener="#{cc.toggleSingleSelect}" render="#{cc.clientId}"/> </h:commandButton> <h:commandButton disabled="#{! cc.attrs.singleSelect}" image="/resources/img/expand-single.gif"> <f:ajax...

Primefaces: Dialog with inputTextarea not updating controller's variable

I have this Dialog: <p:dialog header="Ingrese Comentario" widgetVar="dlg1" appendTo="@(body)" modal="true" position="top" hideEffect="fold" showEffect="fold" closable="true" draggable="true" > <h:form id="d_ingresarComentario"> <h:panelGrid columns="2"> <p:inputTextarea value="#{tareaController.comentarioNuevo.comentario}" rows="7" cols="60" placeholder="Ingrese su comentario aquí" counter="display1" maxlength="200" counterTemplate="{0} Caracteres faltantes." > </p:inputTextarea> <br/>...

Unable to load servlet listener class: com.sun.faces.config.ConfigureListener

I'm using apache-tomee-jaxrs-1.7.1 and I'm trying to deploy with maven 3 getting this error: Unable to load servlet listener class: com.sun.faces.config.ConfigureListener: These are my dependencies in pom.xml: ... <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp.jstl</groupId>...

Refresh parent node from backing bean with primefaces tree

Currently I am working on a project that use primefaces 3.4.1 version which does not support drag and drop in tree component. So I am using a contextMenu instead of drag and drop. <p:tree id="treeHierarchy" value="#{hierarchyManagementBackingBean.root}" var="node" dynamic="true" selectionMode="single" cache="false" style="width:99%;" selection="#{hierarchyManagementBackingBean.selectedNode}"> <p:treeNode id="idtreenode"> <h:outputText value="#{node.name} (#{node.entityType})" /> </p:treeNode> </p:tree>...

Portlet IPC after recieved Event

I have a Navigation portlet which schows all Students, when a Student gets clicked im sending a event with the id of the clicked student to other portlets. Sending and receiving the event is not the problem, that works fine. What i don't get, is how to proceed with the...

Retrieve the id of an Entity object as soon as the entity was instantiated?

Is there a way in JPA to retrieve the id of an Entity object as soon as the entity was instantiated? e.g Person person = new Person(); Currently i am using in my entity class the following strategy: @GeneratedValue(strategy = GenerationType.IDENTITY) If not is there a "Dummy Id" strategy for...

Refresh selection model of p:datatable on row deselection

I have a problem with the selection model of a Primefaces 5.0 datatable. This selection model does not process deselection properly: Selection of rows adds these roles as expected to the list of selected rows. But a deselection has no influence on this list; deselected rows remains in it. Only...

Eclipse + Wildfly + Maven EAR project, is it possible to have files update without redeploy?

I'm working on my first JavaEE/JSF project. It's currently set up with maven so that several jars and a war are deployed inside an EAR container. I spent a lot of time trying to get some kind of hot/autoredeploy type setup going a few weeks ago but gave up and...

Use JSF, JPA, JTA, JAAS, CDI, Bean Validation with Tomcat? [closed]

Is it possible to use the following APIs with tomcat (as a lightweight server): JSF, JPA, JTA, JAAS, CDI, Bean Validation. ...

JSF facets not available in Eclipse

So I am watching a tutorial about how to configure JSF in eclipse. I understand that you click file -> new -> Dynamic Web Project. And then it gives you a few options. The Target Runtime will be (for me) Apache Tomcat version 8, and dynamic web module version will...

How to click on a p:commandButton using javascript [duplicate]

This question already has an answer here: How to select JSF components using jQuery? 2 answers There are many tag in my JSF page.I want to click a p:commandButton using javascript in one of the forms. But it doesn't work. When I debug it use chrome ,it prompt The...

Why are fields reset after ajax update with Primefaces

On a form I have some personal information (name, address etc.) and a changeListener which updates the salutation and letter salutation according to the gender and last name. If the underlying entity was already stored in the database it works fine. If I'm entering data for a new (not saved)...

Is there a way to get the Base URL from an Application-scoped bean in JSF?

In my JSF Facelets pages I know I can just use #{request.requestURL} To get the full URL to build exportable links and the like. However I have an @ApplicationScoped bean where I need the base URL (i.e. "http://dnsname/app") for the purposes of reports and other data. Is there a standard...

selectonemenu, when editable=false, cannot submit the form

My form is working if editable is set to true but not when it's false. When false the submit action method is not even called. I need it to be false (not editable so I can store the correct value in db). This is the menu I added. <tr><td> <h:outputLabel...

Execute a script on f:ajax “success” event only when validation has not failed

I have created a composite component that extends the command button and add some ajax functions (onBegin, onComplete and onSuccess), but I have some problems that I couldnt solve: When I click on the button and a validation error occur, in success event function is passed #{facesContext.validationFailed} = false instead...

JSF Composite Component with conditional popup panel

I'm trying to render a composite component that shows a popup panel based on the outcome of a backing bean method. So far no success. Would appreciate some help. GlassFish 4.1 Mojarra 2.2 RichFaces 4.5.4 Composite Component (conditionalActionLink.xhtml): <ui:component xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich" xmlns:ui="http://java.sun.com/jsf/facelets"...

Can @ManagedBean and @XxxScope be placed in a base class?

I have two @ManagedBean (javax.faces.bean.ManagedBean), parent and child. The parent managed bean is not abstract because we have to give liberty to the developer to use the parent if enough or inherit it with a child that holds specifically funcionality. I have problems with the injections bean and the @PostConstruct...

Distinguish view from normal view in ViewHandler#createView()

I have defined error page in my web.xml for error 404 in this way: <error-page> <error-code>404</error-code> <location>/common/messages/pageNotFoundError.jsf</location> </error-page> Handling invalid page url works as intended - user is redirected to pageNotFoundError page. I have also defined custom view handler in faces-config.xml. The view handler overrides method createView(FacesContext context, String viewId)....

Render outcome of “action” attribute?

i want to completely rewrite a <h:commandButton> renderer. Now i'm stuck at rendering the "action" attribute of the button. Is there a possibility to render this attribute the same way it gets rendered by the standard renderer ? Is there a possibility to retrieve the generated script from somewhere ?...

How to generate a component multiple times in JSF?

I need to highlight the boundary of a country, for which I am using GMaps4JSF aimed at integrating Google maps with JSF. To draw polygon and polylines, the library provides polygonComponent polylineComponent components. I have loaded the data points from the fusion tables into our own DB. <m:map width="1000px" height="500px">...

Putting inside a causes “weird” display

I want to create dynamic forms with ajax update on event. Therefore dynamic-id is important. However, binding the id attribute to a bean value causes Empty Id exception. I saw one of the stackoverflow questions that suggests use html. So I used span. The xhtml code is as follows: <?xml...

How to display PDF in JSF, with content from ServletResponse

In my application, I use jsf & richfaces, I want to display a generated pdf in web browser , I have generated this PDF in serverside and it is available in ServletResponse, but I am unable to display it in my web page. I have tried this question but, it...

Why can't I reference net.sf.jasperreports.engine.DefaultJasperReportsContext from JSF?

I grabbed an old JSF (in Netbeans) project that I needed to update. I noticed that the libraries were missing, so I went and snagged the current version of JasperReports (.jar) and all the commons/other support .jars necessary. Ultimately, when I try to run the project it fails at the...

How can I load a resource bundle properties file within a composite component?

My component library directory tree is setup as the following: resources mylib css mycomponent.css properties mycomponent.properties mycomponent.xhtml I'd like to load the properties file within mycomponent.xhtml to use for messages. What is the proper way of doing this? Is there an f:loadbundle type of solution?...

Double dispatching in jsf

Is it possible in Mojarra-2.1. If I do dispatching to another view from the action method by clicking action buttons: <h:commandButton value="dispatch" action="#{myBean.action()}" /> The bean: @ManagedBean @RequestScoped public class MyBean{ public String action(){ //do some return "view"; } } my browser then recieve the content of the view view....

Output and Command Link in one in JSF

Is there a possibility to use both outcome and action in the same command link? I tried <h:commandLink outcome="page?faces-redirect=true" value="Got to Page" action="#{Bean.setValue("...")}" /> but it ignores the outcome. I have a table with data like this: ID Name Other Things Link to Next Page So I want to give...

Setting f:setPropertyActionListener value with a f:param value

I'm trying to use the setPropertyActionListener tag to set a value in my backing bean. However, it doesn't work as I expected. Context: userService is an instance of my backing bean, which contains an int member, reqID. This, in turn, is the key to a map of objects that belong...