I am practicing with XPATH to extract text within HTML.
I have the following structure:
<tbody>
<tr class="table-row">
<td class="table-cell">
Name
<br />
Address
<br />
Postcode
<br />
Phone: 111111
<br />
Fax: 123456
<br />
Email: <a class="mail" href="mailto:mail#example.com">mail#example.com</a>
<br />
</td>
</tr>
<tr class="table-row">
<td class="table-cell">
Name
<br />
Address
<br />
Postcode
<br />
Phone: 111111
<br />
Fax: 123456
<br />
Email: <a class="mail" href="mailto:mail#example.com">mail#example.com</a>
<br />
</td>
</tr>
(...)
</tbody>
I manage to navigate different nodes but I can't figure out how to extract within a text node.
In particular, I need to extract text within "Phone:" and following <br /> and "Email:" and following <br /> in all rows in the table.
how about //td/text()[4] for Phone and //td/a for the email value
Related
I am working on an application that needs to display a set of questions as a drop down(the user needs to answer 3 questions) in the jsp page.
It works fine, but the issue is for each time I display the drop down list(the questions are same), the questions selected by default are different - the actual question I set in the controller. I need to be able to just display the first or "Select" string as the default option.
My jsp:
<tr>
<br />
<form:label path="qs1">
<span class="">qs 1</span>
</form:label>
<br />
<form:select path="qs1" multiple="false">
<form:option value="${obj.qs0}" label="${obj.qs0}" />
<form:option value="${obj.qs1}" label="${obj.qs1}" />********In this instance this option is shown in the drop down
<form:option value="${obj.qs2}" label="${obj.qs2}" />
<form:option value="${obj.qs3}" label="${obj.qs3}" />
</form:select>
<br />
</tr>
<tr>
<br />
<form:label path="as1">
<span class="">as 1</span>
</form:label>
<br />
<form:input class="" path="as1" />
<br />
</tr>
<tr>
<br />
<form:label path="qs2">
<span class="">qs 2</span>
</form:label>
<br />
<form:select path="qs2" multiple="false">
<form:option value="${obj.qs0}" label="${obj.qs0}" />
<form:option value="${obj.qs1}" label="${obj.qs1}" />
<form:option value="${obj.qs2}" label="${obj.qs2}" />********In this instance this option is shown in the drop down
<form:option value="${obj.qs3}" label="${obj.qs3}" />
</form:select>
<br />
</tr>
<tr>
<br />
<form:label path="as2">
<span class="">as 2</span>
</form:label>
<br />
<form:input class="" path="as2" />
<br />
</tr>
I even tried selected="selected" for the right ones, but it did not work. Any suggestions would be helpful. Thanks.
EDIT: I should have been clear. I did try the option Amit suggested, as of now the obj.qs0 has the value instead of mentioning that in the JSP. I have just added that option along with the questions. The issue is I need to set the questions to the Questions object like below
Questions qs = new Questions();
qs.setQs0("----------Select-------------");
qs.setQs1("what is the name");
qs.setQs2("what is the color");
and so on.
So in the jsp I am setting the path
<form:select path="qs1" multiple="false">
<form:select path="qs2" multiple="false">
So those questions(q1, q2, and so on) are selected automatically and I cannot change the selection to always point to the qs0(where I have the default option). I also need to set the paths differently as I need to be able to capture the different questions & answers the users select.
1) To display "Select" as default, you can add below line :-
<form:select path="qs1" multiple="false">
**<form:option value="NONE" label="--- Select ---" />**
<form:option value="${obj.qs0}" label="${obj.qs0}" />
<form:option value="${obj.qs1}" label="${obj.qs1}" />
<form:option value="${obj.qs2}" label="${obj.qs2}" />
<form:option value="${obj.qs3}" label="${obj.qs3}" />
</form:select>
2) Use the LinkedHashMap or LinkedList to store the drop-down values in order to maintain ordering.
I used an input text, upload file and command button properties.My File upload mode is basic.In command button i made ajax=false.I used required=true in both the fields.While clicking save with empty fields, corresponding method is executing and message is displaying in console, but error message is not displaying in UI.
<p:dialog widgetVar="addDialogWidgetVar" id="addDialogWidgetVarId" dynamic="true" >
<table style="width: 100%;">
<tr>
<td>
<p:messages for="errorMsgId" id="errorMsgId" autoUpdate="true" showDetail="false" showSummary="true" closable="true"/>
</td>
</tr>
</table>
<h:form id="formId" enctype="multipart/form-data">
<table>
<tr>
<td>
<label style="margin-top: 5%"><h:outputText value="Name:"/><h:outputText value="*" style="color:red"/></label>
</td>
<td width="10%"/>
<td>
<p:inputText value="#{manageBean.attachment.fileName}" id="fileNameId" maxlength="60" style="width:70"
required="#{not empty param[save.clientId]}" requiredMessage="Please enter Attachment name"></p:inputText>
</td>
</tr>
<tr height="10"></tr>
<tr>
<td>
<label style="margin-top: 5%"><h:outputText value="Upload Attachment:"/><h:outputText value="*" style="color:red"/></label>
</td>
<td width="10%"/>
<td>
<p:fileUpload label="Select a file" mode="simple" value="#{manageBean.attachment.file}"
allowTypes="/(\.|\/)(pdf|doc|docx|xls|xlsx|gif|jpg|jpeg|png|PNG|GIF|JPG|JPEG)$/"
invalidFileMessage="Allow only (pdf|doc|docx|xls|xlsx|gif|jpg|jpeg|png|PNG|GIF|JPG|JPEG) file."
multiple="false" required="#{not empty param[save.clientId]}" requiredMessage="Please select a file" >
</p:fileUpload>
</td>
</tr>
</table>
<br />
<table style="margin-left: 30%;">
<tr align="center">
<td>
<p:commandButton value="Close" actionListener="#{manageBean.cancelAttachment}" oncomplete="addDialogWidgetVar.hide()" />
</td>
<td>
<p:commandButton id="submitbtnid" value="Save" ajax="false" binding="#{save}"
actionListener="#{manageBean.saveAttachment}" update=":errorMsgId"/>
</td>
</tr>
</table>
</h:form>
</p:dialog>
Try do submit without ajax for test, and also put p:growl in the page, try get messages without update messages component and find bug.
Here is the view that I wish to reference registerViewTwo.jsp
<%#page import="java.util.Calendar"%>
<%#page import="net.tanesha.recaptcha.ReCaptcha"%>
<%#page import="net.tanesha.recaptcha.ReCaptchaFactory"%>
<%#page import="com.ewusu.util.Props"%>
<head>
<title>Register</title>
</head>
<jsp:directive.include file="includes/top.jsp" />
<form:form method="post" id="fm1" cssClass="fm-v clearfix" commandName="${commandName}" htmlEscape="true">
<table style="padding-top: 10px; padding-bottom: 20px;">
<tr><td>First Name:</td><td> <form:input cssClass="required" cssErrorClass="error" id="firstname" size="50"
path="firstname" autocomplete="false" htmlEscape="true" /></td> <td><form:errors path="firstname" cssClass="errors" /></td> </tr>
<tr> <td>Last Name:</td> <td><form:input cssClass="required" cssErrorClass="error" id="lastname" size="50"
path="lastname" autocomplete="false" htmlEscape="true" /></td> <td><form:errors path="lastname" cssClass="errors" /></td> </tr>
<tr> <td>Email:</td> <td><form:input cssClass="required" cssErrorClass="error" id="emailaddress" size="50"
path="emailaddress" autocomplete="false" htmlEscape="true" /></td> <td><form:errors path="emailaddress" cssClass="errors" /></td> </tr>
<tr> <td>Password:</td> <td><form:password cssClass="required" cssErrorClass="error" id="password" size="50"
path="password" autocomplete="false" htmlEscape="true" /></td> <td><form:errors path="password" cssClass="errors" /></td> </tr>
<tr> <td>Gender:</td>
<td><form:select path="gender">
<form:option value="NONE" label="- Select Gender -"/>
<form:option value="Male" label="Male"/>
<form:option value="Female" label="Female"/>
</form:select></td>
<td><form:errors path="gender" cssClass="errors" /></td> </tr>
<tr> <td>Birthday:</td>
<td><form:select path="day">
<form:option value="0" label="- Day: -"/>
<% for(int i = 1; i <= 31; i++) { %>
<form:option value="<%=i %>" label="<%=String.valueOf(i) %>"/>
<% }%>
</form:select>
<form:select path="month">
<form:option value="0" label="- Month: -"/>
<%
String[] months = new String[] {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
for(int i = 0; i < months.length; i++) {
%>
<form:option value="<%=i+1 %>" label="<%=months[i] %>"/>
<% } %>
</form:select>
<form:select path="year">
<form:option value="0" label="- Year: -"/>
<%
int year = Calendar.getInstance().get(Calendar.YEAR) - 5;//seriously how many 5 yrs olds use the net?!?
int minYear = year - 90; //sure 80 year olds have better things to do with their time
for(; year >= minYear; year--) {
%>
<form:option value="<%=year %>" label="<%=String.valueOf(year) %>"/>
<% } %>
</form:select></td>
<td><form:errors path="day" cssClass="errors" /></td>
</tr>
<tr> <td>Remember me:</td>
<td><form:checkbox path="rememberLogin" value="1"/></td>
<td><form:errors path="rememberLogin" cssClass="errors" /></td>
</tr>
</table>
<%
ReCaptcha c = ReCaptchaFactory.newReCaptcha(Props.PUBLIC_RECAPTCHA_KEY, Props.PRIVATE_RECAPTCHA_KEY, false);
out.print(c.createRecaptchaHtml(null, null));
%>
<form:errors path="recaptcha" cssClass="errors"/>
<div>
<span style="padding-right: 10"> <input class="btn-submit" type="submit" name="_eventId_submit" value="submit" /> </span>
<span> <input class="btn-submit" type="submit" name="_eventId_cancel" value="cancel"/> </span>
</div>
<input type="hidden" name="lt" value="${flowExecutionKey}" />
</form:form>
<jsp:directive.include file="includes/bottom.jsp" />
Here is the web.xml file cas servlet mapping
**<servlet-mapping>
<servlet-name>cas</servlet-name>
<url-pattern>/register</url-pattern>
</servlet-mapping>
<!-- Added reguser servlet mapping 4th May 2014 -->
<servlet-mapping>
<servlet-name>cas</servlet-name>
<url-pattern>/reguser</url-pattern>
</servlet-mapping>**
<!-- Section removed to fit Stackoverflow -->
<session-config>
<!-- Default to 5 minute session timeouts -->
<session-timeout>5</session-timeout>
</session-config>
Here is a snippet from my cas-servlet.xml file which maps the url reguser to the webflow registertwo-webflow.xml
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"
p:flowExecutor-ref="flowExecutor"
p:flowUrlHandler-ref="flowUrlHandler" />
<bean id="flowUrlHandler" class="org.jasig.cas.web.flow.CasDefaultFlowUrlHandler" />
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
<webflow:flow-execution-attributes>
<webflow:always-redirect-on-pause value="false" />
</webflow:flow-execution-attributes>
</webflow:flow-executor>
<webflow:flow-registry id="flowRegistry" flow-builder-services="builder">
<webflow:flow-location path="/WEB-INF/login-webflow.xml" id="login" />
<webflow:flow-location path="/WEB-INF/remind-webflow.xml" id="remind" />
<webflow:flow-location path="/WEB-INF/register-webflow.xml" id="register" />
<!-- Added new register for Customer and Spec 4th May 2014 -->
**<webflow:flow-location path="/WEB-INF/registertwo-webflow.xml" id="reguser" />**
<webflow:flow-location path="/WEB-INF/update-webflow.xml" id="update" />
</webflow:flow-registry>
Here is my webflow xml file registertwo-webflow.xml and I am trying to call registerViewTwo.jsp in the second to last line shown in this file.
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<on-start>
<evaluate expression="initialFlowSetupAction" />
</on-start>
<!-- VIEW STATES -->
<view-state id="register" view="registerViewTwo" model="customer">
<!-- <var name="customer" class="com.ewusu.model.Customer"/> -->
I am trying to call the registerTwoView.jsp in the registertwo-webflow register state, but when I start the Tomcat webserver and try to access the relevant URL, I receive a null pointer exception (see below)
SEVERE: Servlet.service() for servlet [cas] in context with path [/sso] threw exception [Request processing failed; nested exception is org.springframework.webflow.execution.FlowExecutionException: Exception thrown in state 'register' of flow 'reguser'] with root cause
java.lang.NullPointerException
at org.springframework.webflow.mvc.servlet.ServletMvcView.doRender(ServletMvcView.java:50)
at org.springframework.webflow.mvc.view.AbstractMvcView.render(AbstractMvcView.java:180)
at org.springframework.webflow.engine.ViewState.render(ViewState.java:314)
at org.springframework.webflow.engine.ViewState.doEnter(ViewState.java:208)
at org.springframework.webflow.engine.State.enter(State.java:194)
at org.springframework.webflow.engine.Flow.start(Flow.java:535)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:364)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.start
The strange thing is that the existing registerView.jsp can be accessed using the registertwo-webflow.xml file just fine. I hope I have provided enough information as I cannot understand what is wrong
I'm new to Spring and I've been having some trouble trying to show a form errors.
I have the following form:
<form:form action="loginform.html" commandName="loginForm" onsubmit="goWait();">
<table><tr>
<td>User Name: </td>
<td><form:input path="userName" /></td>
</tr>
<tr>
<td>Password: </td>
<td><form:password path="password"/> </td>
<tr>
<td colspan="2">
<input type="submit" value="Login" style="butt-login">
</td>
</tr>
</table>
</form:form>
The form, as can be seen, is backed by a LoginForm Bean that validates it.
I want to show all the errors from the validation, outside this form. Something like this:
<div>
<ul>
<li><form:errors path="userName"/></li>
<li><form:errors path="password"/></li>
</ul>
</div>
This div should be outside the , so I can't use the tag.
How can I do this?
You could just capture the html produced by form:errors and display it somewhere after the form:
<form:form ...>
<c:set var="err">
<form:errors path="*" element="div" id="err" cssClass="hidden" />
</c:set>
</form:form>
....
<c:out value="${err}" />
If you want to show the errors before the form, you can do that with a bit of jQuery
Yes, you can user form:errors tag outside form:form tag
<form:errors path="yourBindedObject.*" />
<form:form action="loginform.html" commandName="loginForm" onsubmit="goWait();">
<table><tr>
<td>User Name: </td>
<td><form:input path="userName" /></td>
</tr>
<tr>
<td>Password: </td>
<td><form:password path="password"/> </td>
<tr>
<td colspan="2">
<input type="submit" value="Login" style="butt-login">
</td>
</tr>
</table>
</form:form>
If you want to show all errors associated with any fields just pass a star to the path attribute.
<form:errors path="*" />
But if you want to show global error messages just pass an empty string:
<form:errors path="" />
More information related: http://www.mkyong.com/spring-mvc/spring-mvc-form-errors-tag-example/
I have jsp using struts bean tag library:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
</head>
<body>
<p><a class="colorGrey" href="Welcome.do">
<bean:message key="menu.label" />
</a> >><bean:message key="menu.link.addnews" /> </p>
<p><br>
</p>
<html:form action="/NewsSave">
<table width="100%" border="0">
<tr>
<td class="colorGrey" width="164" height="35">
<bean:message key="body.news.title" /> </td>
<td width="577">
<html:text property="newsTitle" size="40" value=""/> </td>
</tr>
<tr>
<td colspan="2">
<html:errors property="newstitle" />
</td>
</tr>
<tr>
<td class="colorGrey">
<bean:message key="body.news.date" /> </td>
<td>
<html:text property="newsDate" size="10" value=""/> </td>
</tr>
<tr>
<td height="21" colspan="2" valign="top">
<html:errors property="newsdate" />
</td>
</tr>
<tr>
<td class="colorGrey" height="61" valign="top">
<bean:message key="body.news.brief" /> </td>
<td valign="top">
<html:textarea property="brief" cols="40" rows="6" value=""/>
</td>
</tr>
<tr>
<td height="23" colspan="2" valign="top"><html:errors property="brief" /></td>
</tr>
<tr>
<td class="colorGrey" height="100" valign="top">
<bean:message key="body.news.content" />
</td>
<td valign="top">
<html:textarea property="content" cols="40" rows="12" value=""/>
</td>
</tr>
<tr>
<td height="23" colspan="2" valign="top">
<html:errors property="content" />
</td>
</tr>
</table>
<html:submit value="SAVE"/>
</html:form>
<form method="POST"
action="Link.do?method=newsList"
onsubmit="return confirm('<bean:message key="body.onsubmit.cancel" />')">
<input type="submit" value="CANCEL">
</form>
And I use validator plugin, which means that after receiving incorrect info it gives message bellow text field telling what's wrong. But problem is that everything disappear after submiting. So it no info in text or text-areatags. I know that it happens because of value="". But I have another page with the same fields for adding info, which should be clear from the beginning. And if I remove value="", the info from this fields will be displayed on that page after forwarding. So
What should I do to clear info from forms after forwarding to
another page?
How to make info remain after success validation?
As you mentioned, you should remove value="" as this is setting the fields to empty. If you want to clear the values then you should do this in the Action class in which your Form bean is populated.
If you are finding that your Form beans are retaining their values between requests then check that they are request scope: the scope attribute of the action element should be "request" in struts.config