Below jsp displays the returned HashMap value from the webservice
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%#page import="com.action.AuraDecisionWorsheetDetailsService"%>
<%#page import="com.action.AuraDecisionWorsheetDetailsServiceLocator"%>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<form name="form1" method="post" action='gawd.jsp'>
<center><h1>DETAILS</h1></center>
<%
try{
AuraDecisionWorsheetDetailsService psi = new AuraDecisionWorsheetDetailsServiceLocator();
com.action.AuraDecisionWorsheetDetails ps = psi.getAuraDecisionWorsheetDetails();
if(request.getParameter("PolId")!=null){
String pol_id=request.getParameter("PolId");
%>
<center><b>RESULT :</b> <%= ps.service(pol_id)%></center>
<% }else
{%>
<TABLE align="center">
<TR>
<TD>ENTER POLICY NUMBER</TD>
<TD><input type="text" name= "PolId" /></TD>
</TR>
<TR>
<TD colspan="2" align="center"> </TD>
</TR>
<TR>
<TD colspan="2" align="center"><input type="submit" value="Submit"></TD>
</TR>
</TABLE>
<% }
}catch(Exception exe)
{
exe.printStackTrace();
}
%>
</form>
</BODY>
</HTML>
Received below exception
faultString: java.io.IOException: No serializer found for class com.solcorp.pathfinder.uidefs.UIElement in registry org.apache.axis.encoding.TypeMappingDelegate#c87621
Caused by: java.io.IOException: No serializer found for class com.solcorp.pathfinder.uidefs.UIElement in registry org.apache.axis.encoding.TypeMappingDelegate#c87621
Web service takes one parameter i.e. pol_id and returns HashMap.
It is created using Apache Axis.
You have so many problems in this code:
It is a bad practice to call webservices from the jsp, you should do it in the servlet. The jsp should mainly focus on presentation not on logic. Try using jstl.
You are doing alert(pol_id); without opening any script tag. alert is a javascript function and must be contained inside <script></script>.
You have this line: <TD><input type="text" name= "PolId" %></TD>, it should obviously be: <input type="text" name= "PolId" /></TD> (note that i changed % at the end to /.
in this line: <%= ps.service(pol_id)%> you are missing ; at the end.
You have this condition:
`if(request.getParameter("PolId")!=null){
String pol_id=request.getParameter("PolId")==null?"":request.getParameter("PolId");}`
you are doing the same check twice, either remove the if or the ternary operator.
Fix these problems (the first one is really more of a best practice, so you can skip it for now), and then if you have more problems come back and post your question.
EDIT:
in your code you are eching the result from the service:
`<center><b>RESULT :</b> <%= ps.service(pol_id)%></center>`
but as you mentioned it is a Hashmap, so i don't think you can echo it directly. you need to echo the values you extract from it, so try doing this for testing:
//in the java snippet
Map map = ps.service(pol_id);
...
//in the html
<center><b>RESULT :</b> <%= map.get(0)%></center>
Related
I am currently working on a part of a Laravel app that tracks reading progress for books. I am using Livewire and have two components. The main component is the BookManager class, which shows all the books and updates when books are updated or deleted.
class BookManager extends Component
{
public $name;
public $books;
protected $listeners = ['refreshBookManager' => '$render'];
public function mount()
{
$this->books = Book::all();
}
public function render()
{
return view('livewire.book-manager');
}
}
It loops over all the books in the blade-file and renders a BookField component for each book.
// livewire/book-manager.blade.php
<div>
<table class="table table-striped">
#foreach($books as $book)
<livewire:book-field :book="$book" :key="$book->id" />
#endforeach
</table>
</div>
I figured that each BookField component could keep track of its own individual Book and so this is where the user can update their progress for each book individually or mark the book as finished.
class BookField extends Component
{
public $pages_read;
public Book $book;
public function render()
{
return view('livewire.book-field');
}
public function update()
{
//...
}
public function finish()
{
//...
}
}
// livewire/book-field.blade.php
<div>
<tr>
<td>
{{$book->name}}
</td>
<td>
<progress value="{{ ($book->pages_read / $book->pages_total) * 100 }}" max="100"></progress>
</td>
<td>
<input class="form-control" type="number" wire:model.defer="pages_read" placeholder="{{$book->pages_read}}">
</td>
<td>
/ {{$book->pages_total}}
</td>
<td width="15%">
<button class="btn btn-primary" type="submit" wire:click="update()">Update</button>
<button class="btn btn-success" type="submit" wire:click="finish()">Finish</button>
</td>
</tr>
</div>
I've had a hard time trying to get each BookField to be bound properly to their Book model. The error I get when I click the update button is:
Livewire\Exceptions\MethodNotFoundException
Unable to call component method. Public method [update] not found on component: [book-manager]
I get a similar error for the properties:
Livewire\Exceptions\PropertyNotFoundException
Property [$pages_read] not found on component: [book-manager]
All the BookFields are rendered successfully with the correct information for their particular Book model. When I dump the $book variable in a BookField component I get the correct Book instance with all its properties and methods.
But for some reason it seems to be looking for the $pages_read property or the update() or finish() methods on the parent class instead of its own instance of the BookField class. I don't have enough experience with Livewire to know what could be causing this problem or how to fix it, so if someone could help me out that would be much appreciated.
Wrapping a table row with the div causes this error.
Livewire required that your blade template has a single root,
so, removing the wrapping "div" tag and using the "tr" tag as root fixes it.
So, your code on livewire/book-field.blade.php should be as below:
<tr>
<td>
{{$book->name}}
</td>
<td>
<progress value="{{ ($book->pages_read / $book->pages_total) * 100 }}" max="100"></progress>
</td>
<td>
<input class="form-control" type="number" wire:model.defer="pages_read" placeholder="{{$book->pages_read}}">
</td>
<td>
/ {{$book->pages_total}}
</td>
<td width="15%">
<button class="btn btn-primary" type="submit" wire:click="update()">Update</button>
<button class="btn btn-success" type="submit" wire:click="finish()">Finish</button>
</td>
</tr>
Make sure view is wrapped with div TAG
view of the component should have tag DIV
Try using :wire:key and not :key, here:
instead of:
<livewire:book-field :book="$book" :key="$book->id" />
use
<livewire:book-field :book="$book" :wire:key="$book->id" />
I want to use regular expression to match the following html table:
<tbody class=\"DocTableBody \">
<tr data-fastRow=\"1\" class=\"DataRow TDRE\">
<td id=\"g-f-1\" class=\"TDC FieldDisabled Field TCLeft CellText g-f\" >
<div class=\"DTC\">
<label id=\"c_g-f-1\" class=\"DCC\" >01-Apr-2015</label>
</div>
</td>
<td id=\"g-g-1\" class=\"TDC FieldDisabled Field TCLeft CellTextHtml g-g\" >
<div class=\"DTC\">
<label id=\"c_g-g-1\" class=\"DCC\" >ACTIVE</label>
</div>
</td>
</tr>
<tr data-fastRow=\"2\" class=\"DataRow TDRO\">
<td id=\"g-f-2\" class=\"TDC FieldDisabled Field TCLeft CellText g-f\" >
<div class=\"DTC\">
<label id=\"c_g-f-2\" class=\"DCC\" >01-Apr-2015</label>
</div>
</td>
<td id=\"g-g-2\" class=\"TDC FieldDisabled Field TCLeft CellTextHtml g-g\" >
<div class=\"DTC\">
<label id=\"c_g-g-2\" class=\"DCC\" >ACTIVE</label>
</div>
</td>
</tr>
</tbody>
I expected to extract the following value:
"1"
01-Apr-2015
ACTIVE
"2"
01-Apr-2015
ACTIVE
I tried the following to extract the value in data-fastRow:
(?sUi)<tr data-fastRow=\\"(\d+)\\".+>.*<\/tr>
But I couldn't extract the nested items in <label.+>(.*)</label> in single regular expression.
Is that possible to extract parent and nested items in single regular expression?
It's a really bad idea to parse HTML with regular expressions.
Each languahe has its own libraries to parse HTML.
In Python for example you have BeautifulSoup.
It's by far much better to use such libraries.
Usually, such libraries has jQuery-Selector-like interface (or something like that), which allows you to find your data with extremely easy queries.
I have the following code :
{% for assessments in list_assessments%}
<form action="/test/" method="post">{%csrf_token%}
<tr>
<td>{{assessments.assessment_id}}</td>
<td>{{assessments.name}}</td>
<td>{{assessments.assessment_begin_date}}</td>
<td>{{assessments.assessment_end_date}}</td>
<td>{{assessments.is_active}}</td>
<td>{{assessments.is_complete}}</td>
<td>{{assessments.created_at}}</td>
<td>{{assessments.updated_at}}<br></td>
<td><input type="submit" value="Edit Assessment" /></td>
</tr>
{%endfor%}
</form>
All the data here are dynamically coming.
In this following code, i need to assign an name to assessments.name dynamically, something like
<td name="dynamic_name">{{assessment.name}}</td>.
And on clicking the button "Edit Assessment", i want the dynamic_name to be passed and received my the view.
The idea is each assessment has its own set of parameters. I want to display only the parameters related to the name. So if i could pass the value i would be able to do it.
Any help appreciated.
Your ending **</form>** tag should be before for loop.
{% for assessments in list_assessments%}
<form action="/test/" method="post" name="form-{{ assessments.counter }}">{%csrf_token%}
<tr>
<td>{{assessments.assessment_id}}</td>
<td>{{assessments.name}}</td>
<td>{{assessments.assessment_begin_date}}</td>
<td>{{assessments.assessment_end_date}}</td>
<td>{{assessments.is_active}}</td>
<td>{{assessments.is_complete}}</td>
<td>{{assessments.created_at}}</td>
<td>{{assessments.updated_at}}<br></td>
<td><input type="submit" value="Edit Assessment" /></td>
</tr>
</form>
{%endfor%}
Now, You can get specific block values by form name ( see above code ) in javascript as well as in python.
In Javascript,
form = document.getElementByTagName("form")
elems = form.children("td")
elems will give you all td elements.
I have the following HTML stored in a variable in ColdFusion 9. I need to insert a new table row after the 4th </tr>. i.e. before the Submit button.
<form name="form1" id="form1" action="" method="post">
<table>
<tr style="visibility:hidden;display:none;"><td> <input type="hidden" id="ref1" name="ref1" value="1" > </td></tr>
<tr style="visibility:hidden;display:none;"><td> <input type="hidden" id="ref2" name="ref2" value="2" > </td></tr>
<tr>
<th style="text-align:left;">Name * </th>
<td><input type="text" name="foo" id="foo" size="30" maxlength="50" value=""></td>
</tr>
<tr>
<th title="Please enter plain text or HTML." style="cursor:help;text-align:left;">Comment * </th>
<td><textarea name="bar" id="bar" cols="40" rows="10" ></textarea></td>
</tr>
<tr>
<th colspan="1"></th>
<td>
<input style="width:80px" type="submit" value="Submit">
<input style="width:80px" type="button" value="Cancel">
</td>
</tr>
</table>
ReReplace seems like the way to go, but I'm having trouble getting the regexp right. Another option would be to split the string and rebuild it with my new HTML in the middle. Any suggestions would be appreciated.
Regex is the wrong tool for this - you want a HTML parser.
Here's how you can do it with JSoup:
<cfsavecontent variable="InputHtml">
[insert code from question]
</cfsavecontent>
<cfsavecontent variable="NewRow">
<tr><th>whatever</th><td>stuff</td></tr>
</cfsavecontent>
<!--- Read "Creating Objects From Jar Files" --->
<cfset jsoup = createObject('java','org.jsoup.Jsoup') />
<cfset HtmlDom = jsoup.parse(InputHtml) />
<cfset HtmlDom.select('tr:eq(4)').after( NewRow ) />
<cfoutput>
<pre>#XmlFormat(HtmlDom.body().html())#</pre>
</cfoutput>
You can see details of what selectors are supported in the JSoup Selector API
If you don't know/care how many lines are in the table, you can do...
HtmlDom.select('table>tbody').append( NewRow )
...to just add the new row at the end.
Creating Objects From Jar Files
The above code most likely wont work instantly if you copy and paste it, because your server doesn't know about JSoup - you need to download the Jar file and put it in a sensible location.
For CF9, you need to copy the jsoup-1.6.3.jar into your {coldfusion}/lib directory then restart the server.
For CF10, you can use this.JavaSettings in your Application.cfc (as described here) to place it in a different location.
For Railo and OpenBD, you can specify the location of the JAR file as a third argument, e.g:
<cfset jsoup = createObject('java','org.jsoup.Jsoup','lib/jsoup-1.6.3.jar') />
I recommend doing this with jQuery:
$(document).ready(function(){
$($('form tr')[3]).after('<tr><td>row</tr></tr>');
});
Much easier.
I am trying to re-using templates over multiple domains.
Template looks like this:
<div id="emailEntry">
<Table>
<tr class="prop">
<td valign="top" class="name">
<label for="email" id="email"><g:message code="default.email.label" default="Primary e-mail address* :" id="email" /></label>
</td>
<td valign="top" class="value ${hasErrors(bean: instanceToUse, field: 'email', 'errors')}">
<g:textField name="email" value="${instanceToUse?.email}"/>
</td>
</tr>
</Table>
</div>
and my view calls this template like this:
<g:render template="/templates/frmEmailTableEntry" />
Both of my class "customer" and "employee" have email attributes.
so my question is, if I want to reuse template "frmEmailTableEntry" for class "customer" and "employee", what should I put to "instanceToUse" in template.
I read about rendering with var declared, but I am not so sure how to pass this. Please help me with this.
Thanks in advance.
It doesn't really matter what you put in the template. If you leave it just as is you could use it in other gsp's like this:
//say the instance you wish to use is "customerInstance"
<g:render template="/templates/frmEmailTableEntry" model="[instanceToUse: customerInstance]" />
That passes the customerInstance into the ${instanceToUse} variable in the template.