aspose file tools*
The moose likes JSF and the fly likes Bind a multple InputText values into HashMap<String,ArrayList<Integer>> in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Bind a multple InputText values into HashMap<String,ArrayList<Integer>> in JSF" Watch "Bind a multple InputText values into HashMap<String,ArrayList<Integer>> in JSF" New topic
Author

Bind a multple InputText values into HashMap<String,ArrayList<Integer>> in JSF

Suresh Kumar Rajendran
Greenhorn

Joined: Oct 31, 2007
Posts: 21
Hello,

Basically I want to read table records, edit and update dynamically. Reading part is fine, only update part is having problem. Once I retrieve the records from table I'm assigning those values to dynamic InputText fields. Table has 5 records and 6 columns. I don't wants to hardcode the InputText fields with array like this below. If you see the below columns all are hard coded with numbers.

Can you please suggest me any Logic for this condition in JSF2 framework. It's Basically N rows x N Columns.


Rows:

R1

C1 C2 C3
<h:inputText value="#{controller.Tl[0]}" /> <h:inputText value="#{controller.Tl[1]}" /> <h:inputText value="#{controller.Tl[2]}" /> <h:inputText value="#{controller.Tl[3]}" /> <h:inputText value="#{controller.Tl[4]}" />

R2
C1 C2 C3
<h:inputText value="#{controller.Tl[0]}" /> <h:inputText value="#{controller.Tl[1]}" /> <h:inputText value="#{controller.Tl[2]}" /> <h:inputText value="#{controller.Tl[3]}" /> <h:inputText value="#{controller.Tl[4]}" />






Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

Yes. First of all, backing beans are not Controllers, they are Models. In JSF, almost invariably the Controllers are pre-written code that is part of the JSF system itself, not user-implemented code.

Aside from being pedantic, however, when you have a collection of objects, the easiest way to work with them is to use one of the collection-display JSF constructs. For tabular displays (m x n), I recommend the h:dataTable tag. For cases where a tabular layout isn't what is desired (such as when you have a collectionm of items to layout horizontally instead of vertically, you can use the ui:repeat tag. In either case, the iteration is done automatically using the underlying Model object.

Note that in cases where you are intending to incorporate input controls into one or more cells of a table, you should not attempt to use a raw collection as the table mode. Construct a JSF DataModel object and use it to wrap the underlying collection. The DataModel provides essential cursor functionality.


Customer surveys are for companies who didn't pay proper attention to begin with.
Suresh Kumar Rajendran
Greenhorn

Joined: Oct 31, 2007
Posts: 21
Thank you so much for reply.I was using bean only not controller.

I have tried <repeat> and <foreach> both tags none of them worked. My requirement is to update entire records (all column field) of the table, so i retrieved complete records assign to Inputtext for editing the value.

As i mentioned its an n rows x n columns. My code has mentioned below, i'm sure it's incorrect logic. Please let me know if you see any logic for this specific requirement.

Ist forech represents row count.

2nd foreach represents columns value for all the record.

Say I have table having 3 columns and 2 records on it .


Bean Code:

public String retrieve() {



parentlist=new ArrayList<Integer>();
parentlist.add(1); //Row 1
parentlist.add(2); //Row 2

list = new ArrayList<Integer>();
list.add(0,1); //Column 1 value of Row1
list.add(1,2); //Column 2 value of Row1
list.add(2,3); //Column 3 value of Row1
list.add(3,4); //Column 1 value of Row2
list.add(4,5); //Column 2 value of Row2
list.add(5,6);//Column 3 value of Row2
}

//This is will return column value based index
public List<Integer> getList() {

return list;
}

//Submit
public String processRequest() {

try {
System.out.println("***********User Saved data*****************" + list);//list

} catch (Exception anException) {
}

return "";
}



JSF code

<c:forEach items="#{backedbean.parentlist}"
var="prntstationCodeString" varStatus="prentrowCounter"
id="parentloop">

<h:outputLabel style="text-valign:middle;"
value="#{counter}"
escape="false" />

<c:forEach items="#{backedbean.list}"
var="CodeString" varStatus="rowCounter" id="loop">

<c:if test="#{rowCounter.index lt 2}"> //Since total column is 3 so it loop through up to 2

<h:inputText
value="#{bean.list[counter]}" /> // getList() will be called.

</c:if>

<c:set var="counter" value="${counter + 1}" />

</c:forEach>
</c:forEach>
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

Hint: to make sample code and XML more readable, use our "Code" button to wrap formatting tags.

JSTL does not work well mixed with JSF. JSF has better equivalents. In any case, I strongly discourage "programming" on the View Definition (xhtml). The View Definition should be a display template, not a place where coding is done.

I recommend that you get a good book on JSF and study how dataTables work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bind a multple InputText values into HashMap<String,ArrayList<Integer>> in JSF