【问题标题】:Connection to repository Hippo cms连接到存储库 Hippo cms
【发布时间】:2015-02-18 12:12:35
【问题描述】:

我仍在尝试访问存储库以添加新用户。我的组件连接到侧面,我在 FormMap 中有所有需要的值。

问题是我不知道该怎么做。在我的最后一个问题Registration users in Hippo cms 中,我得到了需要将组件连接到 /hippo:configuration/hippo:users 的答案。

怎么办?

这是我的实际组件:

package org.example.components;
import javax.jcr.Session;

import org.hippoecm.hst.component.support.bean.BaseHstComponent;
import org.hippoecm.hst.core.component.HstComponentException;
import org.hippoecm.hst.core.component.HstRequest;
import org.hippoecm.hst.core.component.HstResponse;
import org.hippoecm.hst.component.support.forms.FormMap;
import org.hippoecm.hst.component.support.forms.FormUtils;
import org.hippoecm.hst.component.support.forms.FormField;
import org.hippoecm.hst.content.annotations.Persistable;
import org.hippoecm.hst.content.beans.Node;
import org.hippoecm.hst.content.beans.standard.HippoFolderBean;


public class SignUpComponent extends BaseHstComponent {

@Override
public void doBeforeRender(HstRequest request, HstResponse response) {
    super.doBeforeRender(request, response);
}

@Persistable
@Override
public void doAction(HstRequest request, HstResponse response) throws HstComponentException {
    FormMap map = new FormMap(request, new String[]{"username","email","password"});
    FormField username = map.getField("username");
    FormField password = map.getField("password");
    FormField email = map.getField("email");

    try {
        // NOTE: This session will be logged out automatically in the normal HST request processing thread.
        Session persistableSession = request.getRequestContext().getSession();
    } catch (Exception e) {

    }
    Node users = persistableSession.getNode("/hippo:configuration/hippo:users");

}

虽然导入节点不起作用

error: cannot find symbol

我也试过了

Node users = getSiteContentBaseBean(request).getNode().getSession().getRootNode().getNode("/hippo:configuration/hippo:users"); 

【问题讨论】:

    标签: jcr hippocms


    【解决方案1】:

    下面的代码可以用来持久化对文档的更改。我已经根据您的示例对其进行了修改。

    import javax.jcr.Node;
    import javax.jcr.RepositoryException;
    import javax.jcr.Session;
    
    import org.hippoecm.hst.component.support.bean.BaseHstComponent;
    import org.hippoecm.hst.core.component.HstComponentException;
    import org.hippoecm.hst.core.component.HstRequest;
    import org.hippoecm.hst.core.component.HstResponse;
    import org.hippoecm.repository.api.HippoNodeType;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    public class PersistenceExampleComponent extends BaseHstComponent {
    
        public static final Logger log = LoggerFactory.getLogger(PersistenceExampleComponent.class);
        public static final String USERS_PATH = "/hippo:configuration/hippo:users";
    
        @Override
        public void doAction(final HstRequest request, final HstResponse response) throws HstComponentException {
            Session writableSession = null;
            try {
                writableSession = this.getPersistableSession(request);
                Node usersNode = writableSession.getRootNode().getNode(USERS_PATH);
                final Node someusername = usersNode.addNode("someusername", HippoNodeType.NT_USER);
                writableSession.save();
            } catch (RepositoryException e) {
                log.error(e.getMessage());
            } finally {
                if(writableSession != null) {
                    writableSession.logout();
                }
            }
        }
    }
    

    现在您需要注意,默认情况下,站点连接到存储库的用户可能没有适当的权限写入此文件夹。您可能想阅读Access rights page for HST based writes,如果这还不够,您需要了解repository security and it's domains 的概念,以更改现有域以满足您的需求。

    您可能还想查看follow code snippet,这是一个如何将信息从组件存储到存储库的示例。

    【讨论】:

    • 如果答案OK,能否请您将问题标记为正确?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-04
    • 1970-01-01
    • 2019-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多