根据我几天前发布的问题,我意识到这SimpleFormController不适合处理Ajax请求.因此,我正在将我的应用程序迁移到带注释的控制器.
我正在尝试java.util.List使用Spring MVC 3.0.2和Hibernate通过Ajax使用Jackson 1.9.8(其下载页面)从Oracle数据库返回,但我还没有在任何技术中使用JSON.我已经阅读了一些教程/文章但我无法理解如何返回这样复杂的数据结构并在Spring中使用JSON解析它们.我首先尝试学习类似JSON的概念.
基本上我正在尝试的是当从国家选择框中选择国家时,应该通过Ajax从数据库填充与该国家相对应的州.我不知道如何返回java.util.ListAjax响应,如何解析它并在Java代码中再次使用它.我只达到以下水平.
JS代码.
function getStates(countryId)
{
$.ajax({
datatype:"json",
type: "POST",
url: "/wagafashion/ajax/TempAjax.htm",
data: "countryId=" + countryId,
success: function(response)
{
$('#msg').html(response);
$('#stateList').val('');
},
error: function(e)
{
alert('Error: ' + e);
}
});
}
Run Code Online (Sandbox Code Playgroud)
Spring控制器类中的方法,当onchange在国家/地区选择框的事件上发出Ajax请求时调用该方法.
@RequestMapping(method=RequestMethod.POST, value="ajax/TempAjax")
public @ResponseBody List<StateTable> getStateList(@ModelAttribute("tempBean") TempBean tempBean, BindingResult error, Map model, HttpServletRequest request, HttpServletResponse response)
{
Session session=NewHibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List<StateTable>list=session.createQuery("from StateTable where country.countryId=:countryId order by stateId").setParameter("countryId", …Run Code Online (Sandbox Code Playgroud) Java中的以下方法编译得很好.
public String temp() {
while(true) {
if(true) {
// Do something.
}
}
}
Run Code Online (Sandbox Code Playgroud)
该方法有一个显式的返回类型,尽管它编译得很好但java.lang.String没有return语句.但是,以下方法无法编译.
public String tempNew() {
if(true) {
return "someString";
}
}
Run Code Online (Sandbox Code Playgroud)
发出编译时错误,指示" 缺少return语句 ",即使使用该if语句指定的条件始终为true(它具有boolean永远不会通过反射更改的常量).为了成功编译,必须修改该方法,如下所示.
public String tempNew() {
if(true) {
return "someString";
} else {
return "someString";
}
}
Run Code Online (Sandbox Code Playgroud)
要么
public String tempNew() {
if(true) {
return "someString";
}
return "someString";
}
Run Code Online (Sandbox Code Playgroud)
关于while循环的第一种情况,第二种情况似乎是合法的,尽管它无法编译.
在第二种情况下是否有一个原因超出了编译器的一个特性.
我正在尝试在以下环境中创建企业Web应用程序.
我创建了一个类库(New Project - > Java - > Java Class Library)来放置remote(javax.ejb.Remote)接口,该接口由无状态会话bean实现.类库已添加到两个模块(EJB和WAR)的类路径中.
我已将远程接口和所有实体类放在类库中(我不知道这是方法).
这适用于带注释的接口@Local.@Remote当我尝试返回实体的对象列表时,当JPA涉及时,它甚至可以使用但失败并出现以下异常.
java.rmi.MarshalException:CORBA MARSHAL 1330446347也许; 嵌套异常是:org.omg.CORBA.MARSHAL:警告:IOP00810011:CDRInputStream中的ValueHandler上的readValue异常vmcid:OMG次代码:11完成:也许
完整的堆栈跟踪.
javax.ejb.EJBException: java.rmi.MarshalException: CORBA MARSHAL 1330446347 Maybe; nested exception is:
org.omg.CORBA.MARSHAL: WARNING: IOP00810011: Exception from readValue on ValueHandler in CDRInputStream vmcid: OMG minor code: 11 completed: Maybe
at remote.admin.sessionbeans._AdminRemoteSessionBeanRemote_Wrapper.getZones(remote/admin/sessionbeans/_AdminRemoteSessionBeanRemote_Wrapper.java)
at managedbeans.ZoneBean.getZones(ZoneBean.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) …Run Code Online (Sandbox Code Playgroud) 我需要使用PrimeFaces隐藏一个数据表的所有边界,而不是全部.我尝试了很多东西,没有人工作过.有谁知道怎么做?
我已经将以下样式(单独)应用于ui-datatable该类:
border: hidden !important;
border-style: none !important;
Run Code Online (Sandbox Code Playgroud)
另一件事......
在下面显示的代码片段中,内部类继承外部类本身.
package test;
class TestInnerClass {
private String value;
public TestInnerClass(String value) {
this.value = value;
}
private String getValue() {
return value;
}
public void callShowValue() {
new InnerClass("Another value").showValue();
}
private final class InnerClass extends TestInnerClass {
public InnerClass(String value) {
super(value);
}
public void showValue() {
System.out.println(getValue());
System.out.println(value);
}
}
}
Run Code Online (Sandbox Code Playgroud)
public final class Test {
public static void main(String[] args) {
new TestInnerClass("Initial value").callShowValue();
}
}
Run Code Online (Sandbox Code Playgroud)
main()方法内的唯一语句(最后一个片段)将值分配给类Initial value的私有字段value,TestInnerClass然后调用该callShowValue() …
我添加了一个PhaseListener到faces-config.xml:
<lifecycle>
<phase-listener>com.project.NotificationListener</phase-listener>
</lifecycle>
Run Code Online (Sandbox Code Playgroud)
这个类似乎是正确的,因为它非常简单.
public class NotificationListener implements PhaseListener {
@Inject
private MyCDIStuff stuff;
@Override
public PhaseId getPhaseId() {
return PhaseId.RENDER_RESPONSE;
}
@Override
public void beforePhase(PhaseEvent event) {
this.stuff.doStuff();
}
}
Run Code Online (Sandbox Code Playgroud)
'beforePhase'方法被正确调用,但MyCDIStuff对象为null.我尝试使用@Singleton最可能不正确的类的注释,并且它也没有使注入工作.
有没有办法注入CDI托管bean PhaseListener?
我用,
其中,我使用内置安全令牌来防范CSRF攻击.
<s:form namespace="/admin_side"
action="Category"
enctype="multipart/form-data"
method="POST"
validate="true"
id="dataForm"
name="dataForm">
<s:hidden name="%{#attr._csrf.parameterName}"
value="%{#attr._csrf.token}"/>
</s:form>
Run Code Online (Sandbox Code Playgroud)
它是其中CSRF令牌是不可用的,除非春季安全多部分请求MultipartFilter连同MultipartResolver被适当地配置成使得所述多请求由弹簧处理.
MultipartFilterin web.xml配置如下.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<filter>
<filter-name>MultipartFilter</filter-name>
<filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
</filter>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>MultipartFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>AdminLoginNocacheFilter</filter-name>
<filter-class>filter.AdminLoginNocacheFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AdminLoginNocacheFilter</filter-name>
<url-pattern>/admin_login/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>NoCacheFilter</filter-name>
<filter-class>filter.NoCacheFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>NoCacheFilter</filter-name>
<url-pattern>/admin_side/*</url-pattern> …Run Code Online (Sandbox Code Playgroud) 在从JBoss 7迁移到WildFly的过程中,我遇到了另一个问题.调用受@RolesAllowed("ADMIN")我保护的休息服务时会收到以下错误:
13:46:44,359 ERROR [org.jboss.as.ejb3.invocation] (default task-1) JBAS014134: EJB Invocation failed on component TestFacade for method public java.lang.String net.dice.facade.TestFacade.generateTestdata(): javax.ejb.EJBAccessException: JBAS013323: Invalid User
at org.jboss.as.ejb3.security.SecurityContextInterceptor$1.run(SecurityContextInterceptor.java:66) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final]
at org.jboss.as.ejb3.security.SecurityContextInterceptor$1.run(SecurityContextInterceptor.java:46) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final]
at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:92) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:55) [wildfly-ejb3-8.0.0.Final.jar:8.0.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:448)
at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)
at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:185)
at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:182)
at …Run Code Online (Sandbox Code Playgroud) 我使用<h:outputLink>如下.
<c:set var="cid" value="1"/>
<c:set var="sid" value="2"/>
<h:outputLink value="Test.jsf">
<h:outputText value="Link"/>
<f:param name="cid" value="#{cid}"/>
<f:param name="sid" value="#{sid}"/>
</h:outputLink>
Run Code Online (Sandbox Code Playgroud)
这只是一个例子.两个查询字符串参数都是动态的.因此,<c:set>这里使用的只是为了演示.
在任何时候,可以存在一个,两个或不存在任何参数.在这种情况下,如果只有一个或不存在,则参数/ s被不必要地附加到不应发生的URL.防止将不必要的查询字符串参数附加到URL需要条件呈现<f:param>.
JSTL <c:if>如下
<c:if test="${not empty cid}">
<f:param name="cid" value="#{cid}"/>
</c:if>
Run Code Online (Sandbox Code Playgroud)
不工作.
怎么能有条件地渲染<f:param>内部<h:outputLink>?
我在自己的DataTable上关注了PrimeFaces 的DataTable Filter 展示.每次"onkeyup"事件发生时我都会得到一个
TypeError:PF(...)在Firebug中是未定义的错误,并且未定义的"未捕获的TypeError:无法读取属性'过滤器'
在Chrome控制台中.过滤不起作用.
这是我的XHTML页面:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<h:title>List of User</h:title>
</h:head>
<h:body>
<h:form id="UserForm" name="UserRecords">
<p:dataTable id="users" widgetVar="usersTable" var="user" value="#{userBean.users}" scrollable="false" frozenColumns="0" sortMode="multiple" stickyHeader="true" filteredValue="#{userBean.filteredUsers}">
<f:facet name="header">User<p:inputText id="globalFilter" onkeyup="PF('usersTable').filter()" style="float:right" placeholder="Filter"/>
<p:commandButton id="toggler" type="button" style="float:right" value="Columns" icon="ui-icon-calculator"/>
<p:columnToggler datasource="users" trigger="toggler"/>
<p:commandButton id="optionsButton" value="Options" type="button" style="float:right"/>
<p:menu overlay="true" trigger="optionsButton" my="left top" at="left bottom">
<p:submenu label="Export">
<p:menuitem value="XLS">
<p:dataExporter type="xls" target="users" fileName="users"/>
</p:menuitem>
<p:menuitem value="PDF">
<p:dataExporter type="pdf" target="users" fileName="users"/>
</p:menuitem>
<p:menuitem value="CSV"> …Run Code Online (Sandbox Code Playgroud)