如何检查布尔值是否为空?所以,如果我知道"hideInNav"为空.如何阻止它进一步执行?像下面的东西似乎不起作用,但为什么?
boolean hideInNav = parent.getProperties().get("hideInNav", false);
String hideNavigation = hideInNav != null ? hideInNav : "";
Run Code Online (Sandbox Code Playgroud) 我有一个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)
关于我做错了什么的任何想法?在这个问题上,我一直在墙上撞了好几个小时.谢谢!
我是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) 我无法理解为什么在吊索中使用资源而不是节点.所以说我有一些简单的访问节点,如下所示:
NodeIterator headerNode = currentNode.getNodes();
//loop through and do something with the nodes.
Run Code Online (Sandbox Code Playgroud)
你将如何在资源而不是节点上工作.我听说你应该通常在吊索中使用资源而不是节点.但为什么?我真的不明白这会带来什么好处.我想我也很难掌握哪些资源.我知道有文档,但我找不到任何关于如何使用它们的代码示例.
我正在使用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) 我是一个完整的新手,所以我提前道歉.我正在尝试创建一个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的新手,并试图找出如何将下面的代码转换为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)
任何帮助是极大的赞赏!谢谢!
在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 /.我正在尝试使用资源来获取路径,但无法找到任何可以做到这一点.我知道这一定是小事,我只是在俯视.谢谢您的帮助!
这似乎是一个相当简单的查询,但我一直在敲打我的头几个小时.我有一个类似于下面的节点结构:
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)
感谢任何帮助,因为我过去几天一直在这里.
我现在一直在敲打几个小时.我正在尝试动态填充选择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是未定义的
任何帮助表示赞赏!