Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8553059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:33:47+00:00 2026-06-11T14:33:47+00:00

I have created a composite component, based on PrimeFaces components that works as a

  • 0

I have created a composite component, based on PrimeFaces components that works as a multi-line text component. Text is added to an input, an “Add” button is clicked, and that text is added to a menu. The items in the menu are the submitted value. This works fine, until I set it up as a Composite Component. Then, the initial “Add” click does not add a value. Subsequent clicks work fine. From what I can tell the ViewState is not created until the second click. I assume this is the issue. Am I doing something wrong? Is it a bug? Here is the code:

Composite Component:

    <cc:interface>
        <cc:attribute name="value" type="java.util.Collection" />
    </cc:interface>
    <cc:implementation>
        <p:inputText value="#{multiTextBean.text}" id="txtInput" />
        <p:commandButton value="Add" action="#{multiTextBean.add}"
            update="menu txtInput" />
        <p:commandButton value="Clear"
            action="#{multiTextBean.clear}" update="menu txtInput" />
        <p:selectManyMenu id="menu"
            value="#{multiTextBean.removes}">
            <f:selectItems id="items"
                value="#{multiTextBean.items}" />
        </p:selectManyMenu>
        <p:commandButton value="Remove"
            action="#{multiTextBean.remove}" update="menu" />
    </cc:implementation>

Backing Class for component:

package util;
import java.io.IOException;
import java.util.Set;
import javax.faces.component.NamingContainer;
import javax.faces.component.UIInput;
import javax.faces.component.UISelectItems;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;

import org.primefaces.component.selectmanymenu.SelectManyMenu;


public class multitext extends UIInput implements NamingContainer {

public String getFamily(){
    return "javax.faces.NamingContainer";
}

@SuppressWarnings("unchecked")
@Override
protected Object getConvertedValue(FacesContext context, Object newSubmittedValue)
        throws ConverterException {
    SelectManyMenu menu = (SelectManyMenu) findComponent("menu");
    UISelectItems items = (UISelectItems) menu.findComponent("items");
    Set<String> localItems = (Set<String>) items.getValue();
    return localItems;
}

@Override
public Object getSubmittedValue() {
    return this;
}

@Override
public void encodeBegin(FacesContext context) throws IOException {
    super.encodeBegin(context);
}       
 }

Bean referenced by Composite Component

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class MultiTextBean {
private String text;
private Set<String> items;
private List<String> removes;

@PostConstruct
public void init(){
    items = new HashSet<String>();
    removes = new ArrayList<String>();
}

public String getText() {
    return text;
}

public void setText(String text) {
    this.text = text;
}

public Set<String> getItems() {
    return items;
}

public List<String> getRemoves() {
    return removes;
}

public void setRemoves(List<String> removes) {
    this.removes = removes;
}

public void add(){
    if(!text.isEmpty())
    {items.add(text);}
    text = null;
}

public void clear(){
    items.removeAll(items);
    text = null;
}

public void remove(){
    items.removeAll(removes);
}
 }

The component looks like:
enter image description here

Using the component on this test page:

 <!DOCTYPE html>
<html lang="en"
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:mt="http://java.sun.com/jsf/composite/util"
xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>Insert title here</title>
</h:head>
<h:body>
    <ui:debug hotkey="x"/>
    <form>
    <mt:multitext value="#{backingBean.submittedValues}"/>
    <p:commandButton value="Submit" action="Submit" update="@all"     process="@all"/>
    #{backingBean.submittedValues}
    </form>
</h:body>
 </html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:33:48+00:00Added an answer on June 11, 2026 at 2:33 pm

    In order to invoke (ajax) actions in JSF, you need a <h:form> instead of <form>.

    Fix it accordingly:

    <h:form>
        ...
    </h:form>
    

    See also:

    • commandButton/commandLink/ajax action/listener method not invoked or input value not updated
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a composite component in JSF2. I works great. I would like
I have created an android application that calls (using kSOAP library) a SOAP based
I have a custom composite control that contains a text box, some validators, as
I've created a composite component that has a commandLink embedded inside of a ui:repeat.
A pretty normal case: We have a 'portlet' composite component that has two states:
I am trying to use a composite that I have created in a separate
I have a org.eclipse.swt.browser.Browser instance created in a composite. I would like to know
I have created some JQuery that will expand a div 'popup' on hover and
I have created a function that shows/hides different messages according to a combination of
I want to extend the RadioButton component in Flex 3, adding a text input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.