Wicket Error path: 'label1' does not exist for page: BarPage - wicket

I would like to assert some label label1 in some application. I write the following junit testcase:
wicketTester.assertLabel("label1", "Hello!");
The page, where the label is added looks like this:
FooPage.java
public class FooPage extends WebPage {
public FooPage() {
add(new Label("label1", "Hello!"));
}
}
and the corresponed html page looks like this:
FooPage.html
<body>
..
...
<div wicket:id="label1"></div>
..
<body>
The label label1 - which i would like to assert- is displayed, when someone clicks on the link
<a wicket:id="fooId" href="FooPage">Foo</a>
in the following page:
<html xmlns:wicket="http://wicket.apache.org/">
<body>
<wicket:panel>
<div class="xxx">
<a wicket:id="fooId"
href="FooPage">Foo</a>
</div>
</wicket:panel>
</body>
</html>
When I run the junit Test, I get the following error:
path: 'label1' does not exist for page: BarPage
My Question is: How to get the right path for the label label1?

Have you clicked link 'fooId' in your test (with wicketTester.clickLink) ?

You can find out your component path like this
Modify WicketApplication class
In Wicket 7
getDebugSettings().setComponentPathAttributeName("component_path");
In Wicket 6 or older
getDebugSettings().setOutputComponentPath(true);
Usage example:
#Override
public RuntimeConfigurationType getConfigurationType() {
if (Boolean.valueOf(getProperty("development.mode"))) {
//show component path in html tag
getDebugSettings().setComponentPathAttributeName("component_path");
return RuntimeConfigurationType.DEVELOPMENT;
}
return RuntimeConfigurationType.DEPLOYMENT;
}
From the web browser if you inspect your component, you will find somthing similar to this:
<input type="text" value="" component_path="pageContent_form_username" name="username" id="username3" >
Please don't forget to change all the underscores with (:) colons like this:
pageContent_form_username -> pageContent:form:username

Related

Posting Html with images (WYSIWYG) to ASP.net core controller

I'm having trouble posting my wysiwyg content to my controller in asp.net core. I can't seem to get any value from the form editor. The value for the Content property comes to the controller as null. I'm using the summernote form editor to handle my richtext box editor.
Here is my code
public class Editor
{
public int EditorId { get; set; }
public string Content { get; set; }
}
Controller:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(Editor editor)
{
if (ModelState.IsValid)
{
_context.Add(editor);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(editor);
}
View:
<h2>Create</h2>
<h4>Editor</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Content" class="control-label"></label>
<textarea asp-for="Content" id="summernote" name="editordata"></textarea>
<span asp-validation-for="Content" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</form>
</div>
</div>
<div>
<a asp-action="Index">Back to List</a>
</div>
#section Scripts {
<script>
$(document).ready(function () {
$('#summernote').summernote();
});
</script>
#{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.9/summernote.js"></script>
}
#section Styles{
<!-- include libraries(jQuery, bootstrap) -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet">
<!-- include summernote css/js -->
<link href="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.9/summernote.css" rel="stylesheet">
}
So the issue is when I post the form it's gets to the controller but the content comes over as null. I'm not sure how to post the content
Here are my thoughts, I'm thinking i'm missing a some attribute that allows html to come over the wire to my controller, but all the reserach i've found is that asp.net core doesn't require that. Or I need to handle this type of request in the middleware pipeline, but that doesn't make much sense since it's just html strings i'm sending over the wire to the controller.
It looks like the top of your view was not left out, I assume you have Editor as model.
The problem is on your text area you are using both asp-for and then setting the id and name to something that doesn't match your model property.
You should just use asp-for and let it decide the id and name instead of adding those yourself.
What is really getting posted is a string named editordata because you used that name on the textarea. remove that and it will be named Content to match the property of the model
You also don't need the [Bind] attribute shown in the controller action in your screenshot.
I have been sitting with the same issue and was able to resolve it due to Joe's answer!
Could I suggest working on the summernote class for the text area instead of using your id?
I noticed when I use the id that my textarea's display property doesn't get set to none, but it works when i use the class="summernote".
<textarea asp-for="Instructions" class="summernote"></textarea>
<script>
$(document).ready(function () {
$('.summernote').summernote();
});
</script>
Put this script in your page head:
<script src="https://cdn.ckeditor.com/4.13.0/standard/ckeditor.js"></script>
Lets say you have model called ForumModel where you save contents of editor. Property where you your content is saved is called answer:
public string Answer { get; set; }
So in your view you have following tag:
#model ForumModel
Therefore if you want to add editor:
<textarea id="editor1" asp-for="#Model.Answer" class="form-control" required=""></textarea>
<script>
CKEDITOR.replace("editor1");
</script>
And now all that is left is to call your controller on submit button. When your form is submitted you go to constructor that saves your contents.
public IActionResult Reply(ForumModel forumModel)
{
forumModel.SaveReply();
return RedirectToAction("SomeRandomPage");
}

Using HTML fragments with declarative HTML views

I am trying to decompose a large HTML view down into smaller, more manageable chunks.
Is it possible to use fragments to do this?
For example, I have a fragment file (view.configurator.Summary.fragment.html) containing the following:
<div data-sap-ui-type="sap.m.Button" data-text="Hello"></div>
In my parent file, I try to include the fragment as follows:
<div data-sap-ui-type="sap.m.VBox" class="summary-panel-content">
<div data-sap-ui-type="sap.ui.core.Fragment"
data-fragment-name="view.configurator.Summary"
data-type="HTML"></div>
</div>
However I get the following Error in the console:
Please provide a fragment name
Any ideas?
Seems like its a bug, but you can workaround by wrapping the fragment in a custom control
sap.ui.core.Control.extend("sap.mic.controls.Fragment", {
metadata: {
properties: {
"name": "string"
}
},
init: function () {
},
renderer: function (renderManager, control) {
var fragmentName = control.getProperty("name"),
fragment = sap.ui.htmlfragment(fragmentName);
renderManager.renderControl(fragment);
}
});
And used like so:
<div data-sap-ui-type="sap.m.Page" data-enable-scrolling="false">
<div data-sap-ui-type="sap.mic.controls.Fragment"
data-name="view.configurator.Summary"></div>
</div>
In XML-View
Include the view with this:
<mvc:XMLView viewName="your.namespace.ViewName" async="true" />
Whereas xmlns:mvc="sap.ui.core.mvc"
In HTML-View
You can include Views like this:
<div data-sap-ui-type="sap.ui.core.mvc.HTMLView" data-view-name="your.namespace.ViewName" data-async="true"></div>

Blue Dot Menu displaying HTML as text

After the app menu html is retrieved, it is displayed as text instead of html. Chrome complains Resource interpreted as Script but transferred with MIME type text/plain. I'm using MVC on the Force.com platform. I've tried specifying the content type of the response as "text/html" and "application/javascript", but neither worked.
[EDIT 1]
Code
<script>
intuit.ipp.anywhere.setup({
menuProxy: "https://c.na55.visual.force.com/"
+ "apex/bluedot",
grantUrl: "https://c.na55.visual.force.com/"
+ "apex/authpage"
});
</script>
<ipp:bluedot>
<div id="intuitPlatformAppMenu">
<a id="intuitPlatformAppMenuLogo" href="javascript:void(0);" title="Intuit App Center">
<span id="intuitPlatformAppMenuDot"> </span>
</a>
<div id="intuitPlatformAppMenuDropdown" style="display: none;">
<div id="intuitPlatformAppMenuDropdownTop"></div>
<div id="intuitPlatformAppMenuDropdownInner">
<<=======
</div>
</div>
</div>
</ipp:bluedot>
When dropdown is open, code is added at arrow location as string and a class 'open' is addedto #intuitPlatformAppMenuLogo.
Image
[EDIT 2]
Server side apex code
public with sharing class GetBlueDotMenu {
public String response {get; set;}
public GetBlueDotMenu() {
QbApiController api = new QbApiController ('GET', 'QB API' , null, null, 'https://appcenter.intuit.com/api/v1/Account/AppMenu');
response = api.execute();
}
}
api.execute() returns the response body and saves it to response which is then rendered on the page.
This issue arises from Visualforce's default rendering of strings as escaped. To fix it, the apex:outputText attribute escaped needs to be "false". See http://bit.ly/13CSXve
PFB link -
https://developer.intuit.com/docs/0025_quickbooksapi/0060_auth_auth/widgets/blue_dot_menu
For IE8, you should add (as mentioned in the above doc)
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ipp="">
You can clear the browser's cache and try it again.
Plz let me know how it goes.
Thanks

Need help Selecting

I have HTML similar to this :
<div class="MainForm">
<form name="FromName">
<button name="Button1"></button>
...
...
</form>
<Div class="blackBox" style="visibility:hidden;"></div>
<Div class="SubFotm" style="visibility:hidden;"></div>
</div>
Now I can properly find the trigger for my button click in my script, but I'm not able to target only the closet blackbox to turn it visible.
Currently I'm doing :
if (PButtonName=="Fermer") {
$(this).closest("div .ProfileForm").remove(); // Closing Profile Form
} else if (PButtonName=="plusAdresse") {
alert('In');
$(this).closest("div .BlackBox").css("visibility","visible");
}
I can get the alert "In" to show, but not the BlackBox
If I change the
$(this).closest("div .BlackBox").css("visibility","visible");
for :
$("div .FormBlackBox").css("visibility","visible");
It will show, but will also show all the black box in the document.
If you are using the above HTML, or something similar, I would do it using a reference to the parents.
instead of:
$(".MainForm").closest("div .BlackBox").css('visibility','visible');
use
$(this).parents('.MainForm').children('.BlackBox').css('visibility','visible');
This is assuming you have more than one MainForm div and they all have a single child with the BlackBox class.
here is an example.
Instead of what you have done just add styles display:none; to your divs and then show them whenever you want.So you can do this as below:
<div class="MainForm">
<form name="FromName">
<button name="Button1"></button>
...
...
</form>
<div class="blackBox" style="display:none;"></div>
<div class="SubFotm" style="display:none;"></div>
</div>
and then in your script
if (PButtonName=="Fermer")
{
$(".MainForm").closest("div .ProfileForm").remove(); // Closing Profile Form
}
else if (PButtonName=="plusAdresse")
{
alert('In');
$(".MainForm").closest("div .BlackBox").show();
}
And I will recommend you using Switch case instead of loops at this place.

Forms in zend framework

I'm new in Zend Framework, and I'm having a problem.
usually when verifying data in forms we use javascript like bellow:
<html>
<head>
<script>
function verify(){
if( document.form.name.value=="") { alert("Error"); return false}
}
</script>
</head>
<body>
<form onSubmit="verify()" name="form">
<input name="name" />
<input type="submit" />
</form>
</body>
</html>
I'm using zend forms and i don't have a clue how to do it.
<?php
class Application_Form_Login extends Zend_Form {
public function init() {
$login = new Zend_Form_Element_Text('login');
$password = new Zend_Form_Element_Password('password');
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel("Login");
$remember = new Zend_Form_Element_Checkbox('remember');
$this->addElements(array($login, $password,$remember ,$submit));
}
}
?>
Any help please.
thanks for any help.
You do it the same way as before, but here is how to tell Zend_Form to add the onsubmit event to your so that the HTML code generated contains the attribute in the <form> tag.
class Application_Form_Login extends Zend_Form {
public function init() {
$this->setAttrib('onsubmit', 'return verify()');
// rest of your form code to add elements
}
}
This adds an attribute onsubmit to the Zend_Form object, such that when the form is rendered your <form> tag has onsubmit="return verify()" in it.
Now you can just put the actual Javascript code to verify the form in the view script itself, or an external javascript file that you can reference in a <script> tag.