0

dspace コードのフィードバック フォームを修正して、ユーザーに「ユーザー タイプ」を尋ねるカテゴリを追加しました。

    Select category = form.addItem().addSelect("category");
    category.setLabel("Please select your category");
    category.addOption("UG","Undergraduate/BS");
    category.addOption("MS","MS Student");
    category.addOption("PHD","PhD Student");
    category.addOption("FAC","Faculty");
    category.addOption("RES","Researcher");
    category.addOption("TRA","Trainee");
    category.addOption("BUS","Businessman/Private");
    category.addOption("FF","Fish farmer");
    category.addOption("OT","Other");

    String itemSelected = parameters.getParameter("category","");
    if (StringUtils.equals(itemSelected,"OT"))
    {
        TextArea other = form.addItem().addTextArea("other");
        other.setHelp("Write here if you selected Other");
        other.setValue(parameters.getParameter("other",""));
    }

ここでの私の目標は、ユーザーが Other を選択した場合にのみテキスト領域を表示することです。また、ユーザーがその他を選択した場合、テキスト領域は必須フィールドである必要があります。どうすればこれを達成できますか?また、選択の代わりにラジオボタンを使用してみたいと思います。

[編集] DSpace に慣れていない方のために、DSpace github から変更した元のコードを以下に示します:フィードバック フォーム

4

2 に答える 2

3

選択を使用したのと同じ方法で、ラジオ ボタンを使用できます。

Radio category = form.addItem().addRadio("category");
category.setLabel("Please select your category");
category.addOption("UG", "Undergraduate/BS");
...

terrywb が言ったように、Java コードはページ サーバー側をレンダリングします。最初のステップでカテゴリのみを送信する 2 ステップのプロセスを作成できます。ただし、デフォルトで非表示の TextArea を含めてから、javascript を使用して表示する方がユーザー フレンドリーです。

Item item = form.addItem("item-name","hidden");
TextArea other = item.addTextArea("other");

PageMeta に JavaScript ファイルへの参照を追加します。

public void addPageMeta(PageMeta pageMeta) throws SAXException,
            WingException, UIException, SQLException, IOException,
            AuthorizeException
    {       
        pageMeta.addMetadata("javascript", "static", null, true).addContent("static/js/feedbackform.js");
        // leave the rest
        ...
    }

/dspace/modules/xmlui/src/main/webapp/static/js/feedbackform.js提供できるようにJavaScriptを入れてください。

またparameters.getParameter("category","");、そのままでは機能しません。parametersインスタンス変数には、cocoon によって与えられたパラメーターが含まれてい/aspects/ArtifactBrowser/sitemap.xmapます。

<map:match pattern="feedback">
        <map:act type="SendFeedbackAction">
                <map:transform type="FeedbackForm">
                        <map:parameter name="comments" value="{comments}"/>
                        <map:parameter name="email" value="{email}"/>
                        <map:parameter name="page" value="{page}"/>
                </map:transform>

                <map:serialize type="xml"/>
        </map:act>
        <map:transform type="FeedbackSent"/>
        <map:serialize type="xml"/>
</map:match>

SendFeedbackActionリクエストからデータを取得します。

Request request = ObjectModelHelper.getRequest(objectModel);
String page = request.getParameter("page");

そして{page}、それが返すマップにそれを追加することによって値を提供します:

    // Check all data is there
    if ((address == null) || address.equals("")
        || (comments == null) || comments.equals(""))
    {
            // Either the user did not fill out the form or this is the
            // first time they are visiting the page.
            Map<String,String> map = new HashMap<String,String>();
            map.put("page",page);
            ...
            return map;

commentemailおよび表示したい他のすべてのフィールドについても同じことが起こります。必須フィールドの強制もそこで行う必要があります。

于 2014-09-23T12:27:52.230 に答える