使用 Facelets / JSF 显示动态视图

发布于 2024-12-12 20:10:58 字数 1878 浏览 0 评论 0原文

我即将开始使用 JSF/Facelets 的项目,该项目将与第三方库集成。

该第三方库包含屏幕定义,并具有以下 API:

/** This method gets the screen information**/
public Screen getScreen(int screenId);

/** This method gets the first screen id **/
public int getFirstScreenId();

/** This method submits the screen with the user supplied 
    values and gets the next   screen id **/
public int submitScreen(int screenId, Map<String,Sring> keyValuePair) 
  throws ScreenValidationException;

“Screen”对象包含控件列表。 “控件”是一个具有大约 25 个实现的接口 - 即 LabelControl、TextBoxControl、TextAreaControl、DropDownListControl 等...

以下是如何使用 API 从用户收集数据的示例:

步骤 1:调用 getFirstScreenId() ==>这将返回要显示给用户的第一个屏幕的 ID。

步骤 2:使用屏幕 id 调用 getScreen()

步骤 3:步骤 2 中返回的 Screen 对象包含控件列表。向用户显示屏幕的 HTML 表示形式以及所有控件(作为 HTML 表单)。

步骤 4:用户已提交 HTML 表单。使用submitScreen() 提交值。 第三方库将返回下一个屏幕 ID,如果没有更多屏幕可显示,则返回 -1。

步骤5:重复步骤2-4,直到submitScreen()返回-1。如果返回-1,则意味着 数据收集步骤结束,向用户显示“谢谢”页面。

commitScreen() 可能会抛出 ScreenValidationException - 在这种情况下,使用以下命令重新显示当前屏幕 ScreenValidationException 对象中存在验证消息。


所以,我的问题是在这种情况下如何使用 JSF/Facelets 来显示用户界面?

我可以想象我需要以下

  1. 一个托管 bean,它具有执行与第三方库交互的操作方法。尽管我认为 servlet 可能最适合此操作?

  2. 用于 25 个奇数控件(textboxControl 、 dropdownlistControl 等...)的 Facelets UI 模板

  3. 循环的代码“屏幕”对象中的控件,并执行类似

    // render the "html form start tag" , i.e, 

    for (Control control : screen.getControls()) {
        if (control instanceof LabelControl)
        {
           // render the LabelControl using the "label template"
        }
        else if (control instanceof DropDownListControl)
        {
           // render the DropDownListControl using the "dropdownlist template"
        }
        ....... }

    // render the "html form end template" , i.e, 

我无法想象如何将这三个放在一起的操作。有人可以帮助我吗?

I am about to commence work on a project using JSF/Facelets that shall integrate with a third party library.

This third party library contains the screen definition and it has the following API :

/** This method gets the screen information**/
public Screen getScreen(int screenId);

/** This method gets the first screen id **/
public int getFirstScreenId();

/** This method submits the screen with the user supplied 
    values and gets the next   screen id **/
public int submitScreen(int screenId, Map<String,Sring> keyValuePair) 
  throws ScreenValidationException;

The "Screen" object contains a list of controls. A "control" is an interface that has about 25 implementations
- namely LabelControl, TextBoxControl, TextAreaControl, DropDownListControl etc....

Here is an example of how the API will be used to collect data from the user:

Step 1: call getFirstScreenId() ==> This will return the id of the first screen to display to the user.

Step 2: call getScreen() using the screen id

Step 3: The Screen object returned in Step 2 has the list of controls. Display a HTML representation of the screen with all the controls (as a HTML form) to the user.

Step 4: The user has submitted the HTML form. Use the submitScreen() to submit the values.
The third party library will return the next screen id, or -1 if there are no more screens to show.

Step 5: Repeat steps 2-4 until the submitScreen() returns -1. If -1 is returned it means that the
data collection step is over, display the "thank you" page to the user.

The submitScreen() can throw a ScreenValidationException - In this case, redisplay the current screen with the
validation messages present in the ScreenValidationException object.


So, my question is how can I use JSF/Facelets to display the User Interface in this scenario?

I can picture that I need the following

  1. a managed bean that has an action method that performs the interaction with the third party library. Although I think a servlet might be best suited for this?

  2. Facelets UI templates for the 25 odd controls (textboxControl , dropdownlistControl etc....)

  3. Code that loops through the controls in the "Screen" object and does something like

    // render the "html form start tag" , i.e, 

    for (Control control : screen.getControls()) {
        if (control instanceof LabelControl)
        {
           // render the LabelControl using the "label template"
        }
        else if (control instanceof DropDownListControl)
        {
           // render the DropDownListControl using the "dropdownlist template"
        }
        ....... }

    // render the "html form end template" , i.e, 

I cannot picture how I can put these three together. Can someone help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文