在IBM WebSphere Commerce中如何从命令调用外观而不是从jsp调用它。我们从jsp中称之为
<wcf:getData type="com.ibm.commerce.catalog.facade.datatypes.CatalogNavigationViewType" var="catalogNavigationView"
expressionBuilder="${navigationView}" varShowVerb="showCatalogNavigationView"
maxItems="${pageSize}" recordSetStartNumber="${WCParam.beginIndex}">
<wcf:param name="searchProfile" value="${searchProfile}" />
<wcf:param name="searchTerm" value="${newSearchTerm}" />
<wcf:param name="intentSearchTerm" value="${intentSearchTerm}" />
<wcf:param name="searchType" value="${searchType}" />
<wcf:param name="searchSource" value="${WCParam.searchSource}" />
<wcf:param name="metaData" value="${WCParam.metaData}" />
<wcf:param name="orderBy" value="${WCParam.orderBy}" />
<c:forEach var="facetValue" items="${param.facet}">
<c:if test="${fn:contains(facetValue , '|')}">
<c:set var="facetValue" value="${fn:replace(facetValue,'|',',')}"/>
</c:if>
<wcf:param name="facet" value="${facetValue}" />
</c:forEach>
<wcf:param name="advancedFacetList" value="${newAdvancedFacetList}"/>
<wcf:param name="categoryId" value="${currentCategoryId}" />
<wcf:param name="filterTerm" value="${newFilterTerm}" />
<wcf:param name="filterType" value="${WCParam.filterType}" />
<wcf:param name="filterFacet" value="${removeFacet}" />
<wcf:param name="manufacturer" value="${newManufacturer}" />
<wcf:param name="minPrice" value="${WCParam.minPrice}" />
<wcf:param name="maxPrice" value="${WCParam.maxPrice}" />
<wcf:contextData name="storeId" data="${WCParam.storeId}" />
<wcf:contextData name="catalogId" data="${WCParam.catalogId}" />
</wcf:getData>
这是我们如何从jsp调用它,但我想从命令(从java代码)调用这个Facade 请给我任何建议
由于 Ankit
答案 0 :(得分:3)
你可以这样做:
public someMethod(){
....
CatalogFacadeClient catalogFacadeClient = new CatalogFacadeClient(getBusinessContextType(), null);
GetType getVerb = CatalogFacadeClient.createGetVerb("_wcf:XPath", getXPathExpressionString());
ShowCatalogNavigationViewDataAreaType showDataArea = catalogFacadeClient.getCatalogNavigationView(getVerb);
response = showDataArea.getCatalogNavigationView();
....
}
public String getXPathExpressionString() {
StringBuffer expression = new StringBuffer();
expression.append("{_wcf.ap='IBM_Store_CatalogEntrySearch';");
expression.append("_wcf.search.term='" + toto+ "';");
expression.append("_wcf.search.spellcheck='false';");
expression.append("_wcf.search.type='1000';");
expression.append("_wcf.search.source='Q'}");
expression.append("/CatalogNavigationView");
return expression.toString();
}
protected BusinessContextType getBusinessContextType() {
BusinessContextType businessContext = CommerceFoundationFactory.eINSTANCE.createBusinessContextType();
ContextDataType storeId = CommerceFoundationFactory.eINSTANCE.createContextDataType();
storeId.setName("storeId");
storeId.setValue(currentStoreId);
ContextDataType catalogId = CommerceFoundationFactory.eINSTANCE.createContextDataType();
catalogId.setName("catalogId");
catalogId.setValue(currentCatalogId);
ContextDataType langIdContext = CommerceFoundationFactory.eINSTANCE.createContextDataType();
langIdContext.setName("langId");
langIdContext.setValue(langId.toString());
businessContext.getContextData().add(storeId);
businessContext.getContextData().add(catalogId);
businessContext.getContextData().add(langIdContext);
return businessContext;
}
答案 1 :(得分:0)
你的代码有效!!非常感谢你!
关于getXPathExpressionString()方法的一些注释:
1.-为了正确准备表达式构建器,请检查get-data-config.xml并按名称获取表达式构建器。名称是wcf:getData
中的expressionBuilder
参数
expressionBuilder="${navigationView}"
<wcf:getData type="com.ibm.commerce.catalog.facade.datatypes.CatalogNavigationViewType" var="catalogNavigationView"
expressionBuilder="${navigationView}" varShowVerb="showCatalogNavigationView"
maxItems="${pageSize}" recordSetStartNumber="${WCParam.beginIndex}">
$ {navigationView}的值是=&#34; getCatalogNavigationView&#34;
在get-data-config.xml文件中搜索此值,如下所示:
<expression-builder>
<name>getCatalogNavigationView</name>
<data-type-name>CatalogNavigationView</data-type-name>
<expression-template>{_wcf.ap='$accessProfile$';_wcf.search.profile='$searchProfile$';_wcf.search.facet.field.limit='$facetLimit$';_wcf.search.term='$searchTerm$';_wcf.search.intent.term='$intentSearchTerm$';_wcf.search.originalterm='$originalSearchTerm$';_wcf.search.category='$categoryId$';_wcf.search.type='$searchType$';_wcf.search.exclude.term='$filterTerm$';_wcf.search.exclude.type='$filterType$';_wcf.search.manufacturer='$manufacturer$';_wcf.search.price.minimum='$minPrice$';_wcf.search.price.maximum='$maxPrice$';_wcf.search.facet='$facet$';_wcf.search.advanced.facet='$advancedFacetList$';_wcf.search.exclude.facet='$filterFacet$';_wcf.search.sort='$orderBy$';_wcf.search.meta='$metaData$';_wcf.search.source='$searchSource$';_wcf.search.store='$physicalStoreIds$'}/CatalogNavigationView</expression-template>
<param>
<name>accessProfile</name>
<value>IBM_Store_CatalogEntrySearch</value>
</param>
<param>
<name>searchType</name>
<value>0</value>
</param>
<param>
<name>searchSource</name>
<value>O</value>
</param>
<param>
<name>searchProfile</name>
<value>IBM_findCatalogEntryByNameAndShortDescription</value>
</param>
</expression-builder>
来源:http://158.85.49.234/WEB-INF/config/com.ibm.commerce.catalog-fep/get-data-config.xml
所以这个标签:<expression-template>
包含宝藏:),即solr查询表达式。
2.-使用这个表达式模板,我们可以创建一个正确的表达式:
public String getXPathExpressionString() throws JspException, AbstractBusinessObjectDocumentException {
String expressionTemplate = "{_wcf.ap='$accessProfile$';_wcf.search.profile='$searchProfile$';_wcf.search.category='$categoryId$';_wcf.search.type='$searchType$';_wcf.search.sort='$orderBy$';_wcf.search.source='$searchSource$';_wcf.search.facet='$facet$';_wcf.search.exclude.facet='$filterFacet$';_wcf.search.meta='$metaData$';_wcf.search.price.minimum='$minPrice$';_wcf.search.price.maximum='$maxPrice$'}/CatalogNavigationView";
ExpressionBuilderConfig expressionBuilderConfig = new ExpressionBuilderConfig();
expressionBuilderConfig.setName("getCatalogNavigationView");
expressionBuilderConfig.setDataTypeName("CatalogNavigationView");
expressionBuilderConfig.setExpressionLanguage("_wcf:XPath");
expressionBuilderConfig.setExpressionTemplate(expressionTemplate);
HashMap<String,String[]> parameters = new HashMap<String, String[]>();
parameters.put("accessProfile", new String[]{"IBM_Store_CatalogEntrySearch"});
parameters.put("searchProfile", new String[]{"IBM_findCatalogEntryByNameAndShortDescription"});
parameters.put("searchType", new String[]{"xyz"});
parameters.put("categoryId",new String[]{ "123"});
parameters.put("minPrice",new String[]{"0"});
ExpressionType expressionType = expressionBuilderConfig.buildExpression(parameters);
return expressionType.getValue();
}
------------------------------- * --------------- ----------------------
这可用于在后端或服务提供商中转换websphere电子商务。有了这个,我们就可以停止使用jsp,scriplets,dojo 1.5并在前端层使用任何类似当前js框架的东西。