logo
down
shadow

How to set submitted values of <h:inputText> inside <ui:repeat> into map, set or list


How to set submitted values of <h:inputText> inside <ui:repeat> into map, set or list

By : Arunas Slepikas
Date : November 27 2020, 01:01 AM
it fixes the issue With a Set, it is not possible as it doesn't allow referencing items by index or key. It's however possible with a List and a Map by just specifying the list index and map key in the input value.
code :


Share : facebook icon twitter icon
Using <ui:repeat><h:inputText> on a List<String> doesn't update model values

Using <ui:repeat><h:inputText> on a List<String> doesn't update model values


By : Praks
Date : March 29 2020, 07:55 AM
Does that help The String class is immutable and doesn't have a setter for the value. The getter is basically the Object#toString() method.
You need to get/set the value directly on the List instead. You can do that by the list index which is available by .
code :
<ui:repeat value="#{mrBean.stringList}" varStatus="loop">
    <h:inputText value="#{mrBean.stringList[loop.index]}" />
</ui:repeat>
Values of h:inputText inside ui:repeat are not processed

Values of h:inputText inside ui:repeat are not processed


By : Andres Martinez
Date : March 29 2020, 07:55 AM
Any of those help Your problem is not connected with PrimeFaces 's behaviour, but rather with a scoping problem that is implicilty created when using the tag.
First of all, let's depart from your example. Basically, you've got
code :
<ui:repeat value="#{bean.strings}" var="s">
    <h:inputText value="#{s}"/>
</ui:repeat>
public class MString {
    private String string;//getter+setter+constructor
}
<ui:repeat value="#{bean.mstrings}" var="ms">
    <h:inputText value="#{ms.string}"/>
</ui:repeat>
<ui:repeat value="#{bean.strings}" var="s" varStatus="status">
    <h:inputText value="#{bean.strings[status.index]}"/>
</ui:repeat>
<h:inputText> doesn't seem to work within <ui:repeat>, only the last entry is submitted

<h:inputText> doesn't seem to work within <ui:repeat>, only the last entry is submitted


By : Rui Filipe Costa Car
Date : March 29 2020, 07:55 AM
around this issue It's caused because you're (re)creating the list in the getter method behind . This method is invoked during every iteration round. So, every next iteration will basically trash the values set during the previous iteration. In the action method, you end up with the list as created during the last iteration round. That's why the last entry seems to work fine.
This approach is indeed absolutely not right. You should not be performing business logic in getter methods at all. Make the list a property and fill it only once during bean's (post)construction.
code :
@ManagedBean(name = "genproducts")
@ViewScoped
public class Genproducts{

    private List<Product> list;

    @PostConstruct
    public void init() throws SQLException {
        list = new ArrayList<>();
        // ...
    }

    public List<Product> getList() {
        return list;
    }

} 
<ui:repeat value="#{genproducts.list}" var="itemsBuying">
Using inputText inside ui:repeat to update ArrayList of values is not working

Using inputText inside ui:repeat to update ArrayList of values is not working


By : Vince
Date : March 29 2020, 07:55 AM
wish help you to fix your issue As BalusC reported here String is immutable.
Use the varStatus attribute to access directly the list member by the index.
code :
<ui:repeat varStatus="loop" value="#{user.emails}">
    <td><h:inputText value="#{user.emails[loop.index]}"/> </td>
</ui:repeat>
<ui:repeat varStatus="loop" value="#{user.numbers}">
    <td><h:inputText value="#{user.numbers[loop.index]}" converter="javax.faces.BigDecimal"/> </td>
</ui:repeat>
input component inside ui:repeat, how to save submitted values

input component inside ui:repeat, how to save submitted values


By : Rabail
Date : March 29 2020, 07:55 AM
this will help You need to associate the input value with the repeated variable var in some way. Right now you're not doing that anywhere and basically binding all input values to one and same bean property. So, when the form gets submitted, every iteration will override the bean property everytime with the value of the current iteration round until you end up getting the value of the last iteration round. This is definitely not right.
The simplest way would be to directly associate it with the object represented by var:
code :
<p:selectOneRadio value="#{question.selectedOption}">
<p:selectOneRadio value="#{formData.selectedOptions[question]}">
private Map<Question, String> selectedOptions = new HashMap<>();
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org