I'm a newbie of DWR World and I have some problems to understand the right behaviour of my application.
I have this situation:
File dwr.xml
<dwr>
<allow>
<create creator="new" javascript="Starred">
<param name="class" value="it.mypackage.entity.Starred" />
</create>
<convert converter="bean" match="it.mypackage.beans.ActivityBean"/>
</allow>
</dwr>
Within my html page I have:
<% String name = "myname"; %>
<li><input type="checkbox" name="a" class="styled" />Monitor</li>
and in my Products.java I have:
public void addProducts(String name, String id) {
System.out.println(name + "_" + id);
}
but when I click on this checkbox nothing happears.
If I change String name with integer value System.out works correctly.
Can you help me please?
You will need to add in your dwr.xml
<create creator="new" javascript="Product">
<param name="class" value="fully qualified name of your Product class" />
<include method="addProducts" />
Then in your JSP, you will need to include the following java script files.
engine.js
util.js
interface/Product.js
Related
I am working with OWL and I have defined 2 classes and they share a data propertie:
<Declaration>
<DataProperty IRI="#hasLastName" />
</Declaration>
<DataPropertyDomain>
<DataProperty IRI="#hasLastName" />
<Class IRI="#Class1" />
</DataPropertyDomain>
<DataPropertyDomain>
<DataProperty IRI="#hasLastName" />
<Class IRI="#Class2" />
</DataPropertyDomain>
In java I have created a project that starting from an owl file and an xml file it creates a form.
in my xml file I define the sections of the form in this way:
<section>
<iri>http://www.sample.com/myontology#class1</iri>
<infoList>
<info type="text" property="http://www.sample.com/myontology#hasLastName" required="true" />
<info type="text" property="http://www.sample.com/myontology#hasFirstName" required="true" />
<info type="text" property="http://www.sample.com/myontology#hasEmail" required="false" />
<info type="text" property="http://www.sample.com/myontology#hasPhone" required="false" />
</infoList>
</section>
<section>
<iri>http://www.sample.com/myontology#class2</iri>
<infoList>
<info type="text" property="http://www.sample.com/myontology#hasLastName" required="true" />
<info type="text" property="http://www.sample.com/myontology#hasUser" required="false" />
<info type="text" property="http://www.sample.com/myontology#hasRole" required="false" />
</infoList>
</section>
How can I access the different Last name Properties for class 1 and class 2?
I retrieve it by http://www.sample.com/myontology#hasLastName
There is something like http://www.sample.com/myontology#Class1#hasLastName ?
Sorry I am a very beginner with Ontology and it is not very clear to me
Assuming you have an ontology as follows:
Datatype: xsd:string
DataProperty: hasLastName
Domain:
Person,
Student
Range:
xsd:string
Class: Person
Class: Student
the following code will retrieve the 2 domains:
IRI lastNamePropertyIRI = IRI.create(ontologyIRI + "#hasLastName");
OWLDataProperty lastNameProperty = dataFactory.getOWLDataProperty(lastNamePropertyIRI);
List<OWLClassExpression> domainClasses =
ontology
.dataPropertyDomainAxioms(lastNameProperty)
.map(OWLDataPropertyDomainAxiom::getDomain)
.collect(Collectors.toList());
for (OWLClassExpression owlClass : domainClasses) {
logger.trace("Domain class = " + owlClass);
}
However, there are some other problems I am concerned with here which relates to the ontology rather than the code.
For the ontology I have given, whenever you specify that an individual john is linked to some surname via hasLastName, the ontology reasoner will infer that john is both a Person and a Student, i.e. the domain of hasLastName is the intersection of Person and Student. Clearly, this is not true for people in general. There are 2 possible solutions to this, depending on your needs:
(1) You can specify that the domain of hasLastName is Person or Student which will take the domain to be the union of Person and Student.
(2) The solution I prefer is to define Student as a subclass of Person and then to state that the domain of hasLastName is the single class Person.
I have learned theory of Struts2 and now practicing. Facing problems while executing project.I searched in Google in many ways but could not find result.Please help me. Below is the code.Please help me friends...
Project structure:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>struts2</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="resources" value="ApplicationResources" />
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default">
<action name="login" class="com.practice.structs.actions.LoginAction"
method="validateUser">
<result name="success">pages/homepage.jsp</result>
<result name="error">pages/login.jsp</result>
</action>
</package>
LoginAction.java
package com.practice.structs.actions;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
private String userName;
private String password;
public String validateUser(){
if(this.userName.equalsIgnoreCase("abc") && this.password.equalsIgnoreCase("abc"))
{
return "success";
}else{
addActionError(getText("error.login"));
return "error";
}
}
/**
* #return the userName
*/
public String getUserName() {
return userName;
}
/**
* #param userName the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
* #return the password
*/
public String getPassword() {
return password;
}
/**
* #param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
}
login.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Login page</title>
</head>
<body>
<H1><I>Login Page</I></H1>
<s:actionerror />
<s:form action="login.action" method="post">
<s:textfield name="uname" key="label.username" size="20"/>
<s:password name="password" key="label.password" size="20"/>
<s:submit method="execute" key="label.login" align="center"/>
</s:form>
</body>
</html>
homepage.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Home Page</title>
</head>
<body>
<H2><I>Welcome</I></H2>
</body>
</html>
change your code like this
<package name="default" namespace="/" extends="struts-default">
<action name="login" class="com.practice.structs.actions.LoginAction"
method="validateUser">
<result name="success">pages/homepage.jsp</result>
<result name="error">pages/![enter image description here][1]login.jsp</result>
</action>
</package>
<s:form action="login" method="post">
<s:textfield name="uname" key="label.username" size="20"/>
<s:password name="password" key="label.password" size="20"/>
<s:submit method="execute" key="label.login" align="center"/>
</s:form>
your action name in form is action.login and in struts.xml is login both should be same and also add the namespace
I know this question is a bit outdated, but I also thought it's worth mentioning, to those who happen to end up stumbling onto this post again and still experiencing the issue; assuming you're 100% sure that your mappings are correct and that your web.xml contains the appropriate filter, try the following:
Stop your Tomcat server
Create a "classes" folder in your "WEB-INF" folder
Move your struts.xml file into the newly created "classes" folder
Right click on your Tomcat Server and select "Clean" - not required, but would recommend doing so.
Start up Tomcat again and hope for the best :-)
As a visual aid, your WEB-INF should end up looking something like this:
If you're still experiencing the issue, double check your struts mappings again, as well as your web.xml
I don't have enough points to respond Ryan's comment nor rate him, but what he says is a valid solution in concrete cases, and I am going to tell why.
Sometimes the folders you create in a project are not taken as resources of the application, and you have to configure it.
Let me explain myself with a practical example that may have occurred to some mates who asked for this problem:
When you are developing with Eclipse, maybe you choose another project explorer than the Eclipse's default "Project Explorer", as the "Navigator", for example.
Using "Navigator" view, you can create folders, but this folders are not package resources (as they are when you create "package resources" with the default "Project Explorer"), so Struts2 cannot find "struts.xml" file to configure the actions.
So, the only folders that your project will process as "package resources" are the ones under WEB-INF as Eclipse do in "Dynamic Web Projects" by default.
So then, be sure of having all the configuration files in a "package resource".
In your LoginAction.java properties you took are
private String userName;
private String password;
But in you login.jsp you wrote as
<s:textfield name="uname" key="label.username" size="20"/>
<s:password name="password" key="label.password" size="20"/>
Change
<s:textfield name="uname" key="label.username" size="20"/> to
<s:textfield name="userName" key="label.username" size="20"/>
I hope this answer solves your problem ...
make the changes on struts.xml file,, add namespace="/" attribute in
like
<package name="default" namespace="/" extends="struts-default">
To solve this problem I had to create a classes folder in WEB-INF and place the struts.xml file there. Then I placed the .jsp files in the web folder and placed '/' before the .jsp files, for example /x.jsp
I m new to Struts2. I want to use Validation Framework for a simple 'register' form. Here is my JSP page form elements;
<s:form action="register">
<s:textfield name="name" label="Name" />
<s:textfield name="age" label="Age" />
<s:textfield name="email" label="email"/>
<s:submit value="Register" />
</s:form>
validation error ? = <s:actionerror /><br/>
---Action Message--- <s:actionmessage/>
Here is struts2.xml file;
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="register"
class="com.action.RegisterAction">
<result name="success">home.jsp</result>
<result name="input">index.jsp</result>
</action>
</package>
</struts>
RegisterAction class has
String name;
int age;
String email; variables with getters and setters. And its execute() just returns SUCCESS
For these fields validations the following validation xml file is used, for now only one field name is checked. Name of the validation file is RegisterAction-validation.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<!-- Author: Aash -->
<validators>
<field name="name">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>name is required.. :) </message>
</field-validator>
</field>
</validators>
Here is the project structure
Please any one let me know how can I come up with this. Thanks in advance.
New Add : According to the struts.xml, if there is an error,(the validation says something is wrong), the page should be redirected to index.jsp ,but when nothing is given for the field 'name', still it goes to home.jsp .
A Solution Found
I added to validation.xml
!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
But it is displayed on the top of Form, I don't know why not printed as actionError. How I get it Printed where I want it to view(example : bottom of the form)?
Since it is a field Error, as you have put elements in the JSP page, the message comes close to the field 'name' . If you wanna get printed it,where u want it to be, <s:fielderror fieldName="name" />
I think the problem is the xml file name. It should be RegisterAction-validation.xml
As this says, the DOCTYPE should be there in the validation.xml.
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
-->
Put parameter validate value make 'true; in in <s:form action="register" validate="true">
I have an applet code like this:
<applet type="applet" codebase="." code="ViewerApplet.class" align="center" width="100%" height="600" archive="icepdf-core.jar, icepdf-viewer.jar, icepdf-applet.jar">
<param name="image" value="my_logo.gif" type="image/gif">
<param name="java_arguments" value="-Xmx128m" />
<param name="classloader_cache" value="true" />
<param name="url" value="<%=test%>" />
</applet>
I want to add style to this line. <param name="image" value="my_logo.gif" type="image/gif">
It means, before loading the pdf i have replaced the java logo with my logo.
The logo should be aligned at center with some style. Is it possible to add style to the
above param tag.
Thanks -
Haan
No, the param tags are only for sending parameters to the applet. Definition on w3c:
The 'param' tag is used to define parameters or variables for an object or applet element.
Imagine that the param tag is the same as sending a string to a function, you can't format the string by sending it in a different way.
My issue is that when I don't see a client side validation error message when I don't enter any values for that field even when it is configured as required. The page is reloaded and goes to the result page and client validation fails. I am not sure what I am doing wrong.
I have a simple form where I have a pull down menu called selection criterion. A value must be selected. If a value is not selected, then the page should reload with configured error message. My input form action_item_search.jsp is given below:
<%# taglib prefix="s" uri="/struts-tags" %>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Action Item Search</title>
</head>
<body>
<s:actionerror/>
<s:fielderror />
<s:form action="action_item_search" validate="true">
<s:select label="Search Criterion" name="searchCriterion"
list="#{'': 'Select One', 'creatorName':'creator name',
assignedTo':'assigned to'}" required="true" />
<s:submit name="search" value="Search"></s:submit>
</s:form>
</body>
I have add validators.xml in my WEB-INF/classes directory of exploded war file as given below:
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator Config 1.0//EN"
"http://www.opensymphony.com/xwork/xwork-validator-config-1.0.dtd">
<validators>
<validator name="required"
class="com.opensymphony.xwork2.validator.validators.RequiredFieldValidator"/>
<validator name="requiredstring"
class="com.opensymphony.xwork2.validator.validators.RequiredStringValidator"/>
<validator name="int"
class="com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator"/>
<validator name="long"
class="com.opensymphony.xwork2.validator.validators.LongRangeFieldValidator"/>
<validator name="short"
class="com.opensymphony.xwork2.validator.validators.ShortRangeFieldValidator"/>
<validator name="double"
class="com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator"/>
<validator name="date"
class="com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator"/>
<validator name="expression"
class="com.opensymphony.xwork2.validator.validators.ExpressionValidator"/>
<validator name="fieldexpression"
class="com.opensymphony.xwork2.validator.validators.FieldExpressionValidator"/>
<validator name="email"
class="com.opensymphony.xwork2.validator.validators.EmailValidator"/>
<validator name="url"
class="com.opensymphony.xwork2.validator.validators.URLValidator"/>
<validator name="visitor"
class="com.opensymphony.xwork2.validator.validators.VisitorFieldValidator"/>
<validator name="conversion"
class="com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator"/>
<validator name="stringlength"
class="com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator"/>
<validator name="regex"
class="com.opensymphony.xwork2.validator.validators.RegexFieldValidator"/>
<validator name="conditionalvisitor"
class="com.opensymphony.xwork2.validator.validators.ConditionalVisitorFieldValidator"/>
</validators>
ActionItemTrackingAction-findByCriteria-validation.xml in WEB-INF/classes directory is given below:
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="searchCriterion" >
<field-validator type="required">
<message>You must enter a search criterion.</message>
</field-validator>
</field>
</validators>
My struts mapping xml:
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<!-- <include file="example.xml"/> -->
<package name="action-item" extends="struts-default">
<action name = "action_item_search_input">
<result name = "success">/action-item-search.jsp</result>
</action>
<action name="action_item_search" class="gov.nasa.spacebook.ActionItemTrackingAction" method="fetchByCriteria">
<result name = "success">/action-item-result.jsp</result>
<result name = "input">/action-item-search.jsp</result>
<result name = "error">/action-item-search.jsp</result>
</action>
</package>
</struts>
My action class
public class ActionItemTrackingAction extends ActionSupport {
private List<ActionItem> actionItems;
public List<ActionItemTracking> getActionItems() {
return actionItems;
}
public void setActionItems(List<ActionItemTracking> actionItems) {
this.actionItems = actionItems;
}
private String searchCriterion;
public String getSearchCriterion() {
return searchCriterion;
}
public void setSearchCriterion(final String criterion) {
this.searchCriterion = criterion;
}
public String fetchByCriteria() throws Exception {
final ActionItemTrackingService service =
new ActionItemTrackingService();
this.actionItems = service.getByField(this.actionItem);
return super.execute();
}
}
I have the same issue when I do not have internet connection on my development machine.
Once internet connection to my development machine is established, I recompile and run the application and the validation works. Seems like the validators.xml requires internet.
You must inlcude <s:head/> tag in your jsp. Other wise client side validations are not possible with struts2x. By default it will not show any alert boxes. you must use onSubmit=<true/false> folowed by function name generated by the HTML . you can check name of the function by seeing source code of generated form in your browser. Hope this will help you.