小编Lud*_*net的帖子

Angular 2路由和直接访问特定路由:如何配置Apache?

我开发了一个小型Angular2测试应用程序,除其他功能外,还利用了路由.

只要用户首次访问主页,它就可以正常工作,然后导航到子页面.

如果用户尝试直接访问子页面,如果我没有配置Web服务器,则会得到404.这是完全正常的,因为没有对应于路线的"真实页面".

我尝试在apache 2.2中添加以下配置来处理HTML5 Push State:

<Directory /var/www/html/angular2-sens>
    Options Indexes FollowSymLinks
    RewriteEngine On
    RewriteBase /angular2-sens
    RewriteRule ^index\.html$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /angular2-sens/index.html [L]
</Directory>
Run Code Online (Sandbox Code Playgroud)

它使事情变得更好,因为我不再拥有404.但是,我"仅"被重定向到应用程序的主页并且不执行路由.

我该怎么做才能纠正这个问题?

我的index.html页面是:

<html>

<head>
    <title>Angular 2 QuickStart</title>

    <link rel="stylesheet" href="simplegrid.css" type="text/css">
    <link rel="stylesheet" href="sen.css" type="text/css">

    <script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <script src="node_modules/rxjs/bundles/Rx.js"></script>
    <script src="node_modules/angular2/bundles/angular2.js"></script>
    <script src="node_modules/angular2/bundles/http.js"></script>
    <script src="node_modules/angular2/bundles/router.js"></script>
<!-- dev
    <script src="node_modules/angular2/bundles/angular2.dev.js"></script>
    <script src="node_modules/angular2/bundles/http.dev.js"></script>
    <script src="node_modules/angular2/bundles/router.dev.js"></script>
-->

    <!-- 2. Configure SystemJS -->
    <script>
    System.config({
        map: {
            rxjs: 'node_modules/rxjs' //or …
Run Code Online (Sandbox Code Playgroud)

apache angular2-routing angular

15
推荐指数
1
解决办法
1万
查看次数

并行部署的所有Webapp版本的缓存都将被关闭

我在webapp中使用ehcache,其版本 Tomcat实例上并行部署.这是在不停止应用程序的情况下部署新版本的便捷方法.

但是我有这样一个问题要继续:即使我给缓存和磁盘存储不同的名称,取决于webapp的版本,所有缓存在停止一个实例时停止.

我的配置是:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="ehcache.xsd" name="mywebapp-${project.version}_build_${buildNumber}">
<defaultCache
    maxElementsInMemory="1000"
    maxElementsOnDisk="10000"
    eternal="false"
    timeToLiveSeconds="300"
    timeToIdleSeconds="300"
    overflowToDisk="true"
    diskPersistent="false"
    memoryStoreEvictionPolicy="LRU"
    statistics="true"
/>

<cache
    maxElementsInMemory="1000"
    maxElementsOnDisk="10000"
    name="org.hibernate.cache.internal.StandardQueryCache"
    eternal="false"
    timeToLiveSeconds="300"
    timeToIdleSeconds="300"
    overflowToDisk="true"
    diskPersistent="false"
    statistics="true"/>

<cache
    name="org.hibernate.cache.spi.UpdateTimestampsCache"
    maxElementsInMemory="10000"
    maxElementsOnDisk="100000"
    timeToLiveSeconds="300"
    timeToIdleSeconds="300"
    eternal="false"
    overflowToDisk="true"
    diskPersistent="false"
    statistics="true"/>

<cache
    name="query.Presences"
    maxElementsInMemory="100"
    maxElementsOnDisk="1000"
    eternal="false"
    timeToLiveSeconds="300"
    timeToIdleSeconds="300"
    overflowToDisk="true"
    diskPersistent="false"
    statistics="true"/>

<diskStore path="java.io.tmpdir/mywebapp-${project.version}_build_${buildNumber}"/> 

</ehcache>
Run Code Online (Sandbox Code Playgroud)

${project.version}${buildNumber}

在构建过程中被maven取代.

有人知道如何避免这种不受欢迎的行为吗?

我使用的是ehcache-core-2.4.3和hibernate-ehcache-4.3.8.

java tomcat ehcache

8
推荐指数
1
解决办法
378
查看次数

如何为JSF自定义组件动态生成CSS

我正在开发一个执行"响应式"多列显示的JSF自定义组件.

它使用"CSS多列布局模块"(http://www.w3.org/TR/css3-multicol/)(法语教程:http://www.alsacreations.com/tuto/lire/1557- les-multicolonnes-en-css3.html).

我实际上有以下解决方案,其工作原理:

组件类:

@Log4j
@FacesComponent(ResponsiveMultiColumnsTable.SENAT_COMPONENT_TYPE)
@ResourceDependency(library="senat",name="senat-columns.css")
public class ResponsiveMultiColumnsTable extends UIData {
    public static final String SENAT_COMPONENT_FAMILY = "fr.senat.faces.components";
    public static final String SENAT_COMPONENT_TYPE = SENAT_COMPONENT_FAMILY + ".ResponsiveMultiColumnsTable";
    public static final String DEFAULT_RENDERER = SENAT_COMPONENT_FAMILY + ".ResponsiveMultiColumnsPanelRenderer";

    private enum PropertyKeys { style, styleClass }

    public ResponsiveMultiColumnsTable() {
      setRendererType(DEFAULT_RENDERER);
    }

    @Override
    public boolean getRendersChildren()
    {
        return true;
    }

    public String getStyle() {
        return (String) getStateHelper().eval(PropertyKeys.style);
    }

    public void setStyle(String param) {
        getStateHelper().put(PropertyKeys.style, param); …
Run Code Online (Sandbox Code Playgroud)

html css jsf css3 jsf-2

6
推荐指数
1
解决办法
2028
查看次数

如何强制npm展平依赖关系?

我有一个项目,其中几个前端共享一个公共库。

这些项目的模块依赖性由npm管理。

因此,在每个项目的package.json中,我都有:

  "dependencies": {
    "mylib": "file:../<...path...>/mylib",
    ...other deps...
  },
Run Code Online (Sandbox Code Playgroud)

我将“ mylib”用于两个目的:

  • 分享一些课;
  • 共有共同的依赖关系

直到现在,我一直在使用npm 3.3.12并在运行之后使用npm installmylib的角度依赖关系,该角度依赖关系在我的顶级项目的node_modules目录下。

所以,例如

node_modules
    @angular
        core
        common
        ....
    mylib
Run Code Online (Sandbox Code Playgroud)

现在,使用npm 5.4.2,我有:

node_modules
    mylib
        node_modules
            @angular
                core
                common
Run Code Online (Sandbox Code Playgroud)

这会在我的构建过程中引起很多问题,它需要通过添加诸如以下指令来进一步配置打字稿:

"baseUrl": "",
"paths": {
    "@angular/common": ["node_modules/mylib/node_modules/@angular/common/"],
    "@angular/core": ["node_modules/mylib/node_modules/@angular/core/"],
    "@angular/compiler": ["node_modules/mylib/node_modules/@angular/compiler/"],
    "@angular/compiler-cli": ["node_modules/mylib/node_modules/@angular/compiler-cli/"],
    "@angular/forms": ["node_modules/mylib/node_modules/@angular/forms/"],
    "@angular/http": ["node_modules/mylib/node_modules/@angular/http/"],
    "@angular/platform-browser": ["node_modules/mylib/node_modules/@angular/platform-browser/"],
    "@angular/platform-browser/animations": ["node_modules/mylib/node_modules/@angular/platform-browser/animations/"],
    "@angular/platform-browser-dynamic": ["node_modules/mylib/node_modules/@angular/platform-browser-dynamic/"],
    "@angular/router": ["node_modules/mylib/node_modules/@angular/router/"],
    "primeng/primeng": ["node_modules/mylib/node_modules/primeng/primeng"],
    "rxjs/Rx": ["node_modules/mylib/node_modules/rxjs/Rx"]
    }
Run Code Online (Sandbox Code Playgroud)

在tsconfig.json中

当您必须对AOT,汇总等进行类似的配置时,这真的很烦人。

我尝试使用npm重复数据删除来简化此操作。由于项目有很多依赖项,因此其中一个项目需要超过1000万个依赖项:

npm dedupe
...
...
removed 824 packages and moved 1020 packages in 623.196s …
Run Code Online (Sandbox Code Playgroud)

npm typescript angular angular-aot

6
推荐指数
1
解决办法
2377
查看次数

如何以编程方式实例化复合组件或标签组件?

我想以编程方式实例化复合或标记组件.

此实例化将由自定义组件执行,通常将这些组合或标记组件添加为子组件.

我在抓取论坛时找到的最佳答案是:http://www.java.net/node/701640#comment-791881.它看起来很像我在这个论坛上找到的另一个答案:如何以编程方式或动态创建JSF 2中的复合组件.

在处理这个问题时,我最终编写了一些代码,用于使用MyFaces 进行复合实例化(链接中的示例似乎是Mojarra特有的).我把它复制到那里因为我花了一些时间来写它并希望它能帮助别人:

public UIComponent instantiateComposite(String namespace, String componentName) {
    FacesContext ctx = FacesContext.getCurrentInstance();
    Resource resource = ctx.getApplication().getResourceHandler().createResource( componentName + ".xhtml", namespace );
    UIComponent cc = ctx.getApplication().createComponent( ctx, resource );
    UIPanel panel = (UIPanel) ctx.getApplication().createComponent( UIPanel.COMPONENT_TYPE );

    // set the facelet's parent
    cc.getFacets().put( UIComponent.COMPOSITE_FACET_NAME, panel );

    FaceletFactory ff = (DefaultFaceletFactory) DefaultFaceletFactory.getInstance();
    if(ff == null) {
        FaceletViewDeclarationLanguage vdl = new FaceletViewDeclarationLanguage(ctx);

        Method createCompiler = null;
        Method createFaceletFactory = null;
        try …
Run Code Online (Sandbox Code Playgroud)

jsf components jsf-2

5
推荐指数
1
解决办法
894
查看次数

以编程方式实例化 ValueExpressions

我在 PreRenderViewEvent 上动态添加组件,使用以下方法http://blog.kennardconsulting.com/2010/10/safely-manipulating-component-tree-with.html

它适用于组件添加部分,但是当我尝试动态实例化 ValueExpression-s 时遇到问题。

更具体地说,当我尝试使用动态传递的参数伪造动态 ValueExpression 时遇到问题。

让我们试着解释一个例子......

在顶层,我使用了标签组件(在标签文件中描述的组件,不是复合组件,也不是自定义组件。

<my:topComponent param=#{toto}"/>
Run Code Online (Sandbox Code Playgroud)

在 my:topComponent 中,我将 param 传递给嵌套组件。

<my:nestedComponent param2=#{param}/>
Run Code Online (Sandbox Code Playgroud)

这个nestedComponent 正在使用一个自定义组件(在我的例子中,我从primefaces Datatable 派生的一个组件),将它的param2 作为另一个参数传递......

<my:customComponent finalParam=#{param2}/>
Run Code Online (Sandbox Code Playgroud)

在customComponent中,我在PreRenderViewEvent上动态添加了一些子组件,并为customComponent设置了一些ValueExpression-s。

其中一些表达式使用 finalParam。所以,我解开 finalParam 值,然后构建一个新的 ValueExpression :

String varName = getValueExpression("finalParam").getExpressionString().replace("#{", "").replace("}", "");
Run Code Online (Sandbox Code Playgroud)

然后我使用这个辅助函数实例化我的动态值表达式:

public static ValueExpression createValueExpression(String expression, Class clazz) {
        FacesContext fc = FacesContext.getCurrentInstance();
        ELContext elContext = fc.getELContext();
        ExpressionFactory expFactory = fc.getApplication().getExpressionFactory();
        ValueExpression ret = expFactory.createValueExpression(elContext, expression, clazz);
        return ret;
    }
Run Code Online (Sandbox Code Playgroud)

例子 :

ValueExpression dynExpression …
Run Code Online (Sandbox Code Playgroud)

jsf components el dynamic

5
推荐指数
1
解决办法
4133
查看次数