如何自动填充输入字段?

时间:2018-04-20 06:51:52

标签: jsf

我有一个页面,显示用户可以插入评论的帖子。当我创建我的评论时,我调用了我的managedBean方法CommentsController.Create(),一切都很完美。但我必须在表单中指定帖子ID。我想发送自动填写字段postId,因为我知道当前帖子的postid。

我尝试将输入的类型填充为隐藏但它不起作用...并且用户可以很好地更改客户端的值。

我的表格:

    <h:form>
        <h:panelGrid columns="2">
             ...
             //I want to fill this automatically...
            <h:selectOneMenu id="postId"
                             value="#{commentsController.selected.postId}" 
                             title="#{bundle.CreateCommentsTitle_postId}"
                             required="true"
                             requiredMessage="#{bundle.CreateCommentsRequiredMessage_postId}"
                             >
                <f:selectItems value="#{postsController.itemsAvailableSelectOne}"/>
            </h:selectOneMenu>
           ...
           <h:commandLink action="#{commentsController.create}" 
                          value="#{bundle.CreateCommentsSaveLink}"
                          />
    </h:form>

我的评论控制器:

public String create() {
    try {
        getFacade().create(current);
        JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("CommentsCreated"));
        return "/posts/View.xhtml";
    } catch (Exception e) {
        JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
        return null;
    }
}

0 个答案:

没有答案
相关问题