how to parse the value to integer in <ui:repeat value="..." var="...">?
I have a code like this:
<ui:repeat value="#{myController.fileList}}" var="element" >
<t:inputFileUpload value="#{myController.uploadedFile[eleme开发者_StackOverflow中文版nt]}" />
</ui:repeat>
but this returns an error : java.lang.NumberFormatException: For input string: "[0]}". UploadedFile is an array of Files. When i wrote code like this
...
<t:inputFileUpload value="#{myController.uploadedFile[0]}" />
...
everything is ok, but i want to have there values between 0-8, not only '0', and this has to be returned from my controller. So how to convert this 'element' to int value inside <t:inputFileUpload value="#{myController.uploadedFile[element]}" />
? Thanks for help.
You can use the varStatus
attribute to obtain the loop status.
<ui:repeat value="#{myController.fileList}" var="element" varStatus="loop">
<t:inputFileUpload value="#{myController.uploadedFile[loop.index]}" />
</ui:repeat>
(only available in JSF 2.x by the way, in JSF 1.x your best bet might be c:forEach
)
But why don't you just use the following?
<ui:repeat value="#{myController.uploadedFile}" var="uploadedFile">
<t:inputFileUpload value="#{uploadedFile}" />
</ui:repeat>
Update: the fileList
must be of type List<Integer>
or Integer[]
or int[]
and the uploadedFile
must be of type List<SomeObject>
or SomeObject[]
to get your initial code to work.
Update 2: here's a small reproducible test snippet:
XHTML:
<h:form>
<h:selectManyCheckbox value="#{bean.selectedIndexes}">
<f:selectItems value="#{bean.selectIndexes}" />
</h:selectManyCheckbox>
<h:commandButton value="submit" />
</h:form>
<ui:repeat value="#{bean.selectedIndexes}" var="selectedIndex">
<p><h:outputText value="#{bean.list[selectedIndex]}" /></p>
</ui:repeat>
Bean
:
private List<SelectItem> selectIndexes; // +getter
private List<Integer> selectedIndexes; // +getter +setter
private List<String> list; // +getter
public Bean() {
selectIndexes = new ArrayList<SelectItem>();
selectIndexes.add(new SelectItem(0, "one"));
selectIndexes.add(new SelectItem(1, "two"));
selectIndexes.add(new SelectItem(2, "three"));
selectIndexes.add(new SelectItem(3, "four"));
selectedIndexes = new ArrayList<Integer>();
list = Arrays.asList("one", "two", "three", "four");
}
Works fine here on Mojarra 2.0.3 and Apache Tomcat 6.0.29. You only need to substitute selectedIndexes
as fileList
and list
as uploadedFile
.
精彩评论