小编Del*_*ung的帖子

Java检查boolean是否为null

如何检查布尔值是否为空?所以,如果我知道"hideInNav"为空.如何阻止它进一步执行?像下面的东西似乎不起作用,但为什么?

boolean hideInNav = parent.getProperties().get("hideInNav", false);
String hideNavigation = hideInNav != null ? hideInNav : "";
Run Code Online (Sandbox Code Playgroud)

java performance boolean nullable

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

带括号的电话号码的HTML5模式

我有一个HTML5模式,适用于以下格式的电话号码:

111-222-3333
111 222 3333
(777)-888-9999
(777)888-9999
Run Code Online (Sandbox Code Playgroud)

但是如果用户输入

(777-999-9999
Run Code Online (Sandbox Code Playgroud)

它通过了验证.理想情况下,我希望这会抛出一个错误,因为括号显然没有关闭.这是我的模式:

pattern="^\(?\d{3}\)?[- ]?\d{3}[- ]?\d{4}$"
Run Code Online (Sandbox Code Playgroud)

关于我做错了什么的任何想法?在这个问题上,我一直在墙上撞了好几个小时.谢谢!

regex html5

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

将java bean属性传递给JSTL

我是Java和JSTL的新手,很抱歉,如果这是一个非常简单的问题.我试图举一个例子,我在网上找到并开始工作,但我似乎遇到了问题.所有这一切都是你想要创建一个java bean并从java bean访问属性.但是我在JSTL jsp中调用类的行上得到一个空指针异常:useBean id ="students"class ="com.beans.Students".这是java类:

package com.beans;

public class Students implements java.io.Serializable
{
    private String firstName = null;
    private int age = 0;

    public Students() {
    }
    public String getFirstName(){
        return firstName;
    }
    public int getAge(){
        return age;
    }
    public void setFirstName(String firstName){
        this.firstName = firstName;
    }
    public void setAge(Integer age){
        this.age = age;
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试访问Java bean的JSTL:

<jsp:useBean id="students" 
                class="com.beans.Students"> 
<jsp:setProperty name="students" property="firstName"
                 value="Zara"/>
<jsp:setProperty name="students" property="age" 
                value="10"/>
</jsp:useBean>

<p>Student First Name: 
<jsp:getProperty …
Run Code Online (Sandbox Code Playgroud)

java jstl

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

吊索资源与节点

我无法理解为什么在吊索中使用资源而不是节点.所以说我有一些简单的访问节点,如下所示:

NodeIterator headerNode = currentNode.getNodes();
//loop through and do something with the nodes.
Run Code Online (Sandbox Code Playgroud)

你将如何在资源而不是节点上工作.我听说你应该通常在吊索中使用资源而不是节点.但为什么?我真的不明白这会带来什么好处.我想我也很难掌握哪些资源.我知道有文档,但我找不到任何关于如何使用它们的代码示例.

java sling

4
推荐指数
1
解决办法
3458
查看次数

jQuery自定义html5错误消息

我正在使用HTML5来验证表单并使用setCustomValidity更改错误消息文本.除了某些原因我不能让这个工作.我在控制台或任何东西都没有收到错误消息.我正在尝试采用"数据错误"属性中的内容并将其用作自定义错误消息,但无法解决这个问题我花了好几个小时就完成了这个.

JQUERY

$aboutUs.find("#headerForm :input").each(function(){ 
  var $this = $(this); 
  var errorMessage = $this.attr("data-error");
   for (var i = 0; i < $this.length; i++) {
     $this[i].oninvalid = function(e) {
     e.target.setCustomValidity("test");
     if (!e.target.validity.valid) {
     e.target.setCustomValidity(e.target.getAttribute(errorMessage));
     }
     };
    }                        
   });
Run Code Online (Sandbox Code Playgroud)

HTML表格

<input id="firstName" type="text" required data-error="First Name Message" />
<input id="lastName" type="text" required data-error="Last Name Message" />
<input id="phone" type="text" required data-error="Phone Message" />
Run Code Online (Sandbox Code Playgroud)

jquery html5

4
推荐指数
1
解决办法
7513
查看次数

OSGi组件可通过Apache Felix进行配置

我是一个完整的新手,所以我提前道歉.我正在尝试创建一个OSGi组件,它只显示一个hello world消息,并且可以通过felix的输入进行配置.然后在jsp页面上吐出来.我正在使用scr注释来帮助完成此操作.这是我的java代码

package com.training.cq5.trainingApp;

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.ComponentContext;
import org.apache.sling.commons.osgi.PropertiesUtil;

@Component(label= "Welcome Message",
        description = "Welcome Message for the training excercise",
        immediate = true, enabled = true, metatype=true)
@Properties({
    @Property(name = "welcome.message", value = "WelcomeMessage")
})
@Service(WelcomeMessage.class)
public class WelcomeMessage {

    private static String welcome_message = "Welcome";

    @Activate
    protected void activate(ComponentContext ctx) {
        welcome_message = PropertiesUtil.toString(ctx.getProperties().get(welcome_message), welcome_message);
    }

    public static String getMessage() { 
        return welcome_message;
    }
}
Run Code Online (Sandbox Code Playgroud)

以下是我在JSP中调用它:

<%@ page …
Run Code Online (Sandbox Code Playgroud)

java osgi maven apache-felix sling

3
推荐指数
1
解决办法
5368
查看次数

Java为每个循环或for循环执行while循环

我是Java的新手,并试图找出如何将下面的代码转换为for循环或每个循环.

do {
    testPages.push(testParentPage);
    if(homePage != null && testParentPage.getPath().equals(homePage.getPath())){
        isParent = true;
        break;
    }
} while((testParentPage = testParentPage.getParent()) != null); 
Run Code Online (Sandbox Code Playgroud)

任何帮助是极大的赞赏!谢谢!

java sling

3
推荐指数
1
解决办法
266
查看次数

CQ5 - 模型类中的Sling currentPage

在CQ jsp中,只需调用currentPage.getPath()即可轻松访问currentPage对象.但我正在尝试删除任何脚本,并将它们分离到模型类中,并且无法弄清楚如何访问currentPage对象.我以为我可以这样做:

public void setResource(Resource resource){
    resource.getPath()
}  
Run Code Online (Sandbox Code Playgroud)

但这会返回类似于:

/content/home/subPage/jcr:content/banner
Run Code Online (Sandbox Code Playgroud)

我只是想返回/ content/home/subPage /.我正在尝试使用资源来获取路径,但无法找到任何可以做到这一点.我知道这一定是小事,我只是在俯视.谢谢您的帮助!

java sling aem

3
推荐指数
1
解决办法
6618
查看次数

SQL2 - 获取子节点属性

这似乎是一个相当简单的查询,但我一直在敲打我的头几个小时.我有一个类似于下面的节点结构:

food-group
    jcr:content
        nuts -> type=almonds
        meat -> beef=true
        fruit -> type=apples,oranges,bananas
Run Code Online (Sandbox Code Playgroud)

我需要从子节点收集三种类型的属性:一个是字符串,布尔和字符串数组.我认为以下sql2查询将工作并获取它们的属性,但无论出于何种原因我收到错误:

QUERY

SELECT 
    parent.* 
FROM 
    [cq:PageContent] AS parent 
INNER JOIN 
    [nt:base] as child ON ISCHILDNODE(parent) 
WHERE 
    ISDESCENDANTNODE(parent, [/content/grocerystore/food/])"
Run Code Online (Sandbox Code Playgroud)

错误:

Need to specify the selector name because the query contains more than one selector.
Run Code Online (Sandbox Code Playgroud)

感谢任何帮助,因为我过去几天一直在这里.

jcr jcr-sql2 aem

3
推荐指数
1
解决办法
5740
查看次数

CQ5 - 在选择xtype中动态填充选项

我现在一直在敲打几个小时.我正在尝试动态填充选择xtype中的选项,但无法使其工作.这是我的dialog.xml

<resourceType
            jcr:primaryType="cq:Panel"
            title="Header Type">
            <items jcr:primaryType="cq:WidgetCollection">
                <headerType
                        jcr:primaryType="cq:Widget"
                        fieldLabel="Header Type"
                        name="./headerType"
                        type="select"
                        xtype="selection">
                    <options jcr:primaryType="cq:WidgetCollection">
                        <categories
                            jcr:primaryType="cq:Widget"
                            path="/content/admin/adminView/jcr:content/header-admin-content/cats/type.infinity.json"
                            width="500"
                            xtype="cqinclude" />
                    </options>
                </headerType>
            </items>
        </resourceType>
Run Code Online (Sandbox Code Playgroud)

我正在制作的json:

content/admin/adminView/jcr:content/header-admin-content/cats/type.infinity.json
Run Code Online (Sandbox Code Playgroud)

看起来像这样:

{"jcr:primaryType":"nt:unstructured","item_1":  
{"jcr:primaryType":"nt:unstructured","text":"small","parameter":"small"},"item_2":
{"jcr:primaryType":"nt:unstructured","text":"medium","parameter":"medium"},"item_3":
{"jcr:primaryType":"nt:unstructured","text":"large","parameter":"large"},"item_4":
{"jcr:primaryType":"nt:unstructured","text":"none","parameter":"none"}} 
Run Code Online (Sandbox Code Playgroud)

当我打开对话框时没有任何反应我只是得到一个JS错误TypeError:snippet.xtype是未定义的

任何帮助表示赞赏!

sling aem

3
推荐指数
1
解决办法
7333
查看次数

标签 统计

java ×6

sling ×5

aem ×3

html5 ×2

apache-felix ×1

boolean ×1

jcr ×1

jcr-sql2 ×1

jquery ×1

jstl ×1

maven ×1

nullable ×1

osgi ×1

performance ×1

regex ×1