English 中文(简体)
JSF 2.0:我如何能够动态生成投入部分
原标题:JSF 2.0: how can I dynamically generate Input component

在我的申请中,我有以下同仁阶层。

public class Constants {
    ...
    public static final int MAX_NUM_OF_PICTURES = 2
    ...
}

在我使用共同财产调查方案之前,我设法积极投入领域,根据这一不变情况重载档案:

<%
    for (int i = 1; i < Constants.MAX_NUM_OF_PICTURES + 1; i++) {
%>
<tr>
    <td>Upload Picture <%= i %></td>
    <td><input name="<%= i%>" type="file" /></td>
</tr>
<tr>
    <td>Description <%= i %></td>
    <td><input type="text" name="<%= "description" + i%>" id="description" /></td>
</tr>
<%
    }
%>

目前,我正试图利用联合武装部队完成上述任务。 如果这些投入领域不是动态生成的,我可以很容易地在我的背信标中界定以下特性:

@ManagedBean
@RequestScoped
public class MrBean {
   ...
   private UploadedFile picture1;
   private String       pictDescription1;
   ...
}

然而,由于这些领域目前是动态生成的,我无法知道,我需要事先确定多少财产,以掌握这些上载的档案。

如果有人能就我应如何处理这一问题向我提出建议,我将非常感谢。

最佳做法

James Tran

最佳回答

将这些财产归另一类动物,在你管理的海滩上收集这些 j。

E.g.

public class Picture {

    private UploadedFile file;
    private String description;

    // ...
}

以及

@ManagedBean
@ViewScoped
public class Profile {

    List<Picture> pictures;

    public Profile() {
        pictures = new ArrayList<Picture>();

        for (int i = 0; i < Constants.MAX_NUM_OF_PICTURES; i++) {
            pictures.add(new Picture());
        }
    }

    // ...
}

然后,您可在以下网址上查阅:<ui:repeat> (或be<h:dataTable>,但如果你想要两个重复行,而不是一个,则这确实是合适的。

<table>
    <ui:repeat value="#{profile.pictures}" var="picture" varStatus="loop">
        <tr>
            <td>Upload Picture #{loop.index + 1}</td>
            <td><t:inputFileUpload value="#{picture.file}" /></td>
        </tr>
        <tr>
            <td>Description #{loop.index + 1}</td>
            <td><h:inputText value="#{picture.description}" /></td>
        </tr>
    </ui:repeat>
</table>

我对你重新使用上载档案的图书馆没有任何想法,因此,我假定这只是Tomahawk。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签