在AngularJS代码中使用JSP C Tag [英] Using JSP C Tag within AngularJS code

查看:222
本文介绍了在AngularJS代码中使用JSP C Tag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:在我获得使用Angular和Java的经验之后,我正在修改这篇文章。这是为了避免发布新问题。

Note: I am modifying this post, after I gained more experience working with Angular and Java. This is to avoid posting a new question.

在过去几个月中,使用不同的模型在JSP代码中实现可重用的AngularJS部分,最后决定使用jsp include指令<%@ include file =form-part.jsp%> 。这很好用,现在唯一的问题是使用 C标签时的可读性问题。

Over the past few months, working with different models to implement reusable AngularJS parts within a JSP code, finally decided to use the jsp include directive <%@include file="form-part.jsp" %>. This works well, and the only issue now is readability problem when using C Tags.

例如,变量在Eclipse资源文件中定义如下:

For example, the variables are defined in Eclipse resource file as follows:

formhtml5.jsp.photoSubjectFront=Subject Front
formhtml5.jsp.photoSubjectStreet=Subject Street
formhtml5.jsp.photoSubjectRear=Subject Rear

然后,为了在Angular中使用上述变量,我找到的方法如下(因为你必须在JSP文件中使用变量名):

Then, in order to use the above variables in Angular, one way I found is as follows (since you must use the variable name inside the JSP file):

<fmt:message key="formhtml5.jsp.photoSubjectFront" scope="request" var="photoSubjectFront"/>
<fmt:message key="formhtml5.jsp.photoSubjectStreet" scope="request" var="photoSubjectStreet"/>
<fmt:message key="formhtml5.jsp.photoSubjectRear" scope="request" var="photoSubjectRear"/>
...
...
<div class="photos-container" 
    ng-init="subjectPhotos =
                            [{fieldName:'subject_front',
                              title:'${photoSubjectFront}'},
                             {fieldName: 'subject_street',
                              title: '${photoSubjectStreet}'},
                             {fieldName: ''subject_rear,
                              title: '${photoSubjectRear}'}
                            ]">
...
...
</div>

如果您注意到,上面的HTML代码块不太可读。

If you notice, the above HTML code block is not very readable.

初始化数组 subjectPhotos 范围变量的最佳方法是什么,并使用JSP变量 $ {photoSubjectFront} 在初始化中?

What is the best way to initialize the array subjectPhotos scope variable and use the JSP variable ${photoSubjectFront} in the initialization?

我在想是否可以在< script> 块更易读,但我不确定在正常的脚本块中访问范围变量。

I was thinking if I can do that in a <script> block which is much more readable, but I was not sure to access the scope variable inside a normal script block.

感谢您的反馈。

过去3-4个月我一直在使用Angular开发基于表单的应用程序。我准备进入下一阶段,以便我可以将开发的表单(HTML5 +脚本)转换为可重用的组件或部件。开发是使用Eclipse,Java(JSP + Servlets)完成的,当然还有HTML5,JavaScript(Angular)和CSS。

I've been developing forms based applications using Angular for the past 3-4 months. I am preparing to move into next stage so that I can convert the developed form (HTML5 + Script) into reusable components or parts. The development was done using Eclipse, Java (JSP+Servlets) and of course, HTML5, JavaScript (Angular) and CSS.

过去,我已经完成了成功使用ASP.NET,母版页和用户控件。

In the past, I've done that successfully using ASP.NET, Master Pages and User Controls.

我正在寻找的是为HTML5和Code创建模块化和可重复使用的表单部分的方法可以很容易地在另一种形式中重复使用,这种形式具有相同的部分,可能在布局和逻辑上有微小的变化。

What I am looking for is a way to create modular and reusable form parts for both HTML5 and Code so that they can be easily reused in another form that has the same part with probably minor changes in layout and logic.

我目前正在这样做,但只针对代码。我设法开发了Angular Directives,Services和Controllers,它们在可重用性方面实际上达到了我的期望。现在唯一的问题是如何使HTML5(布局)也可以重复使用。

I am currently doing that but only for code. I managed to develop Angular Directives, Services, and Controllers which are actually working up to my expectations in terms reusability. The only issue now is how to make the HTML5 (layout) also reusable.

我做了一些研究,我可以列出一些选项:

I've done some research and I can list some options:


  1. 使用类似于ASP.NET母版页的基于Java的框架。我找到了几个选项。

  1. Use Java based framework which is similar to that of ASP.NET Master Pages. I've found several options.

使用Angular指令和模板。这里的问题是你必须编写一个代表HTML部分的非常长的字符串。它认为这令人困惑。我希望有一种方法可以将可重用的HTML部分保存在一个单独的文件中,并将其包含在指令中或类似的内容中。

Use Angular directives and templates. The problem here is that you have to compose a very long string which will represent the HTML part. It think this is confusing. I hope there is a way to save the reusable HTML part in a separate file and include it in the directive or something like that.

使用JSP开发可重复使用的部分,并将其包含在主窗体中。我可以使用jsp include指令<%@ include file =form-part.jsp%> 来包含可重用的表单部分。

Use JSP to develop the reusable part, and include it in the main form. I can use the jsp include directive <%@include file="form-part.jsp" %> to include the reusable form part.

我正在评估选择最合适的选项的可能选项。

I am evaluating the possible options to select the most appropriate one.

I希望你能指点我一些样本或教程来帮助我达到这个要求。

I hope you can point me to some sample or tutorial that will help me achieve this requirement.

注意:我发现很好教程这将是一个很好的开始。

Note: I found good tutorial which will be an excellent start.

感谢您的反馈。

Tarek

推荐答案

开发可重用表单的最佳方法是使用html templateUrl的指令。
你可能正在使用'模板'功能

The best way to develop a reusable form is a directive using html templateUrl. You are probably using the the 'template' feature

return {
            replace: true,
            templateUrl: 'some_form_template.html',
            // template: '<div>Hello World</div>'
}

在使用特殊验证时,您还可以使用指令来创建验证: http://ng-learn.org/2014/02/Writing_Custom_Validitions/

When it comes to using special validation you also use directives to create validations: http://ng-learn.org/2014/02/Writing_Custom_Validitions/

当涉及到标记错误时请使用ng-messages / ng-message指令: https://docs.angularjs.org / api / ngMessages / directive / ngMessages

When it comes to flagging errors please use the ng-messages/ng-message directives: https://docs.angularjs.org/api/ngMessages/directive/ngMessages

这个问题已经出现了问题:如何创建一个角度输入指令,用于表单验证

This question has already been asnwerd: How to create a angular input directive that works with form validation

这篇关于在AngularJS代码中使用JSP C Tag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆